PDA

View Full Version : SQLite Syntax problem



evosonic
06-22-2006, 01:23 PM
This is probably something something simple, but I have been staring at it and moving it around for about 3 hours now and thus far it has been kicking my butt:



allCat = SQLite.QueryToTable(db, "select * from Categories;");
catRows = allCat.Rows;
nANode = allCat.Data[catRows]["catid"];
Dialog.Message("test", nANode);
nTreeNode = allCat.Data[nANode]["Catnam"];


the dialog.message window displays the correct number everytime, however I get an error when it tries to execute the last line of code. If I hard code the number the statement above it (dialog.message) produces, I get no error.

:eek: :huh

evosonic
06-22-2006, 02:34 PM
The exact error I get is "On preload, Line 10: attempt to index field '?' (a nil value)"

TJ_Tigger
06-22-2006, 02:56 PM
What is it that you are trying to accomplish with the code, which line is line 10 from the preload event. Can you export your project and post it here for people to see? Or at least the code for that event.

Tigg

evosonic
06-22-2006, 03:06 PM
I'm trying to update a Tree View object after an item is either added or deleted from a table in SQLite. I'm having to do this because I can't find a way to update an object by executing code on a different page. ie. run code on page 2 and have it update the tree view object on page 1. Anyway, back to the code: (it has changed a bit form above because this includes the entire section with line numbers, and I was tinkering with it a bit:

The table name is 'Categories' and it has 2 columns, 'catid' and 'Catnam'.



4 if changed ~= 1 then
5 allCat = SQLite.QueryToTable(db, "select * from Categories;");
6 catRows = allCat.Rows;
7 nANode = allCat.Data[catRows]["catid"];
8 nANode = testNode;
9 Dialog.Message("test", testNode);
10 nTreeNode = allCat.Data[testNode]["Catnam"];
11 nanode = nANode + 1;
12 tblNodeData = {};
13 tblNodeData.Text = nTreeNode;
14 tblNodeData.Expanded = false;
15 tblNodeData.ImageIndex = 1;
16 Tree.InsertNode("acctTree", nanode, tblNodeData);
17 changed = 1;
18 end


My problem I think is this - on line 10 the syntax is not correct. If I manually assign an integer to the variable "testNode" such as "testNode = 11;" The code will execute without an error. It's like it needs a manually assigned integer before that line of code knows how to execute properly... If the variable is assigned on the fly, it's like it doesn't understand it, and I can't find a way to tell the programimng engine that this thing is that particular integer. It's frustrating.

evosonic
06-22-2006, 03:15 PM
Here is another block I have using the same line of code, but this time the variables are manually assigned prior to execution, and it works flawlessly:



1 function Populate ()
2 ComboBox.ResetContent("editcatCB");
3 ComboBox.ResetContent("insitemCB");
4 allCat = SQLite.QueryToTable(db, "select * from Categories;");
5 catRows = allCat.Rows
6 -- populating 'Edit Catgeories' combobox
7 for var = 1,catRows,1 do
8 catNams = allCat.Data[var]["Catnam"]
9 ComboBox.InsertItem("editcatCB", var, catNams, "");
10 end
11 -- populating 'Add Item' category combobox
12 for var = 1,catRows,1 do
13 catNams = allCat.Data[var]["Catnam"]
14 ComboBox.InsertItem("insitemCB", var, catNams, "");
15 end
16 for var = 1,catRows,1 do
17 catNams = allCat.Data[var]["Catnam"]
18 tblNodeData = {};
19 tblNodeData.Text = catNams;
20 tblNodeData.Expanded = false;
21 tblNodeData.NodeIndex = var;
22 tblNodeData.ImageIndex = 1;
23 Tree.InsertNode("acctTree", var, tblNodeData);
24 end
25 pOneLoaded = 1;
26 end


Lines 7 and 8, 12 and 13, 16 and 17 are exactly like line 10 in my last post. It just doesn't make sense.

Another solution would be if there is a way to reset a tree view object, and then re-populate it - that would accomplish my goal as well. Kind of like ComboBox.ResetContent...

TJ_Tigger
06-22-2006, 07:28 PM
To reset a Tree object use the Tree.RemoveNode and specify a NodeIndex of "0" with the quotes. That will delete all items in the tree.

Have you turned on debugging to see what happens up to the point of failure? This is under the Edit-> Preferences menu.

evosonic
06-22-2006, 08:10 PM
Awesome, Thanks TJ. :yes Resetting the Tree will work nicely, and no I haven't tried turning on debugging. I will make a note of that in the future though whenever I get stumped again.

TJ_Tigger
06-23-2006, 07:07 AM
Actions will only affect the objects on the page where the action is executed. So it looks like you are taking the correct approach in setting a variable to see if there is an update. If there is then refresh the information in the tree object. One thing I have done when I want a variable to span multiple pages is mark it as a global variable, g_changed. That way when I see that variable I know it is global to the project.

Are you rebuilding the tree completely or just adding the last item from the SQLite table to the tree? It looks like you are just adding the last item.

I would look to change your function to clear and rebuild your tree. That way you can ensure that it shows all items. also you can use the function that populated the tree in the first place. :D

This would also catch multiple entries if multiple entries were made. The previoius way would only add the last item if there had been an update.