1. Thomas J. Hall, III
  2. Valentina Studio
  3. Wednesday, July 08 2020, 08:51 PM
  4.  Subscribe via email
I began using Pro Serial this week, so I am new at the game.

I am trying to figure out how to add a Button or a Tool Button to a form and have it perform an SQL statement. I am using a local database with SQLite.

I have an 8 field table into which I have some 15-20 frequently occurring entries. I want to have a series of buttons which will pre-fill certain fields so I will not have to manually enter the data (I have this implemented in FileMaker which I am trying to replace). I have written an INSERT INTO statement in SQL Editor which puts the data into the correct fields when I click the “Execute” button on SQL Editor. However, I have not been able to hit on the correct method to attach the statement to a button and have the procedure executed. Can someone help me?
Comment
There are no comments made yet.
Thomas J. Hall, III Accepted Answer
Sergey,

Now that I have found out how to script my "pre-fill" buttons (ie. Kroger), I have a question about their placement on the form. From what I can see now they will have to go either above or below the fields. I would like to be able to place them beside the fields as in my FileMaker input screen (see attached). Does your current version allow such placement or is it in your planned upgrades?

I am using your Pro Serial now. When I get my Studio Pro for Linux will I be able to have a "runtime" version of my forms? It would be inconvenient to have to execute from and close back to the Palette everytime I use a database.
Attachments (1)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 41
Thomas J. Hall, III Accepted Answer
I did and I just double checked. It is not "enabled."
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 42
Kevin Accepted Answer
Go into Edit mode. Select the disable button. Make sure Enabled is disabled. Save.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 43
Thomas J. Hall, III Accepted Answer
I changed the underscore everyplace I could find it.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 44
Kevin Accepted Answer
Joe, if you kept the underscore in the field name for the discard button, you need to add the underscore to the above script. Your previous screen print shows you had the underscore in the script, but you might have changed it.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 45
Thomas J. Hall, III Accepted Answer
re: #76 & #77

Oops I had missed the underline.

I got the filter working thanks to Kevin's suggestion to put a space between the = and this.
My discard button is still not working.

records = this.table.getTableCursor( this.name );
records.clearFilters();
records.applyFilters();

this.tbDiscardFilter.enabled = false;
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 46
Sergey Pashkov Accepted Answer
Exactly! The button has different name than it has in the example.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 47
Kevin Accepted Answer
I got the complex filter working here. Did update leSearch. And I put in spaces between the field and operator and search term. I had one typo that was breaking things.

Joe, looking through your screen prints again ... I see you have the discard filter named tb_ ... but in the code there isn't an underscore.

Sergey, thanks for the info regarding the QMessageBox and console.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 48
Sergey Pashkov Accepted Answer
Kevin,

Right, it generates it like this, and SQLite and Valentina support such a query.

Popup can be found in the Standard Dialogs->Information template
QMessageBox.information( 'Title', condition );

Also, we can print to console (but it is necessary to open it beforehand):
console.log( condition );
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 49
Kevin Accepted Answer
Sergey,

Is there a way to display the variable values as the code works it way through? Or some code that creates a pop up with the variable value?

When I see this:


var condition = '"' + fldName + '"' + this.cbCriteria.currentText + "'" + search + "'";


I am thinking the final result will be:

"Name"LIKE'Kroger'

I don't see any spaces being built in. Or is that what is occurring upstream with all the replace code.

Kevin
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 50
Sergey Pashkov Accepted Answer
Kevin & Joe,

Yes, this.leSearch is a correct form (this was optional previously).
I'll revisit this example now.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 51
Thomas J. Hall, III Accepted Answer
Sergey
Re: #56

If you declare a field like that (without AUTO_INCREMENT):
...
TransNo INTEGER PRIMARY KEY
...
TransNo becomes an alias for ROWID, and therefore auto-incremented.
Each inserted row gets TransNo=max(TransNo)+1;
So if the new record is deleted, its TransNo will be used for the next INSERT.


I did this for my TransNo field. I turned off AUTO_INCREMENT. Now if I delete a record, even if I have Updated it, the TransNo for the next Add is the last TransNo used +1. Such a simple solution. Thanks.

Joe
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 52
Thomas J. Hall, III Accepted Answer
Kevin,

I tried: var search = this.leSearch.text;
I got another error message: [clicked] TypeError: Value is undefined and could not be converted to an object

I also went back and made sure the Properties>Name of the line edit box was leSearch with an "l" (lower case L). I did the same in the script for the button.

Joe
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 53
Kevin Accepted Answer
Wish there was a way to view a post before posting or an edit. (Maybe there is and I don't see it.)

The edits:

I haven't attempted this lesson yet, but looking at the code and the error message ...

I think this:


var search = leSearch.text;


Should be this:


var search = this.leSearch.text;


The other thing it might be is I (capital i) vs l (small L) ... the field name and the code might contain different characters.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 54
Kevin Accepted Answer
Joe,

I have attempted this lesson yet, but looking at the code and the error message ...

I think this:


var search = leSearch.text;


Should be this:
var search = this.leSearch.text;




The other thing it might be is I (capital i) vs l (small L) ... the field name and the code might contain different characters.

Kevin
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 55
Thomas J. Hall, III Accepted Answer
Sergey
Re: #55 & #66

I have gone back to Tutorial 6 and implemented it as set out, but I keep getting an error message: [clicked] ReferenceError: leSearch is not defined

Here are the screen shots. I added the new Horizontal BoxLayout directly below the form.

Joe
Attachments (7)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 56
Kevin Accepted Answer
Sergey,

>"Go To" functionality

Wow. Thanks.


rn = parseInt( this.RecordNumber.text ) - 1;
import '/frm_Transactions_Main' as dlg
dlg.gotoRecord( rn );
dlg.exec();


On the TableView, I have a LineEdit not associated with a field named RecordNumber. In TableView, one sees row numbers and that is what probably one will enter into the LineEdit, thus the subtraction of 1 (Sergey had previously written: "(record numbers are 0-based)". Assign to a variable.

It works.

Again, thank you for your assistance.

Kevin
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 57
Sergey Pashkov Accepted Answer
Yes, this is because filtering changes the set of shown records.
You can clear a filter with a button.

But the only way to implement "Go To" functionality exactly as you described is in reply #55
It is just one or two lines of code
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 58
Thomas J. Hall, III Accepted Answer
Sergey & Kevin,

I opened Lesson 6 on filtering (roducts:vstudio:tutorials:forms:lesson6" target="_blank" rel="nofollow">http://valentina-db.com/docs/dokuwiki/v10/doku.php?id=valentina:products:vstudio:tutorials:forms:lesson6) and read through it. It seemed above my level of competence.

I dropped back to Lesson 5 (roducts:vstudio:tutorials:forms:lesson5" target="_blank" rel="nofollow">http://valentina-db.com/docs/dokuwiki/v10/doku.php?id=valentina:products:vstudio:tutorials:forms:lesson5) on Simple Filtering and it seemed more on my ability level, so I gave it a shot.

I left the Line Edit box in place and simply changed the name showing (I don't really understand what this type of button does, so I am using it as a de-facto label. I then went to Database>Tables>Transactions>TransNo and pulled that field onto my form. I followed the directions and changed its Data Mode to Filter and Apply. I saved and executed. It works like a charm. Any TransNo I enter will immediately show in the form. I can enter new ones one after the other and they will pop up. That is great.

BUT PROBLEM - I cannot use the other navigation buttons |< < > >|. The other buttons Update, Clear, etc. work - even the Kroger button. I have to Close the form and re-Execute to be able to use the navigation buttons again
Attachments (1)
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 59
Thomas J. Hall, III Accepted Answer
Pardon me. As I was closing I think I see what happened. Once again smart quotes snuck in. I had opened another editor and forgot to disable the smart quotes.
Comment
There are no comments made yet.
  1. more than a month ago
  2. Valentina Studio
  3. # 60


There are no replies made for this post yet.
However, you are not allowed to reply to this post.