SQLite connection

Moderators: LCNeil, heatherlaine, kevinmiller, elanorb

Post Reply
jpyck
Posts: 8
Joined: Tue Mar 11, 2014 5:12 pm

SQLite connection

Post by jpyck » Fri Mar 28, 2014 9:47 pm

Hi,
I followed the code from the example in lesson 3.
When connecting to the SQLite (contacts.sqlite) database (which is located in the "documents" folder in Win 8) I get this error message:
"revdberr,Database Error: near "tSQLQuery": syntax error"

Any ideas? Thanks.

Here is the code for the card "contacts":

local sDatabaseConnectionID


on preOpenCard
# mobGUIStart ---> Inserted by mobGUI plugin
if "MobGUILib-1394918029138" is not among the lines of the stacksInUse then start using stack "MobGUILib-1394918029138"
mobGUIPreOpenCard me
# mobGUIEnd
set the utext of group "title" to "contacts"
end preOpenCard


on databaseConnect pType
if pType is "SQLite" then
put specialFolderPath("documents") & "/contacts.sqlite" into tDatabasePath
put revOpenDatabase ("sqlite",tDatabasePath,,,) into sDatabaseConnectionID
else if pType is "Direct MySQL" then

else if pType is "Web MySQL" then

end if

end databaseConnect

on databaseSelectAllNames
if the uOptionText of group "databaseType" is "SQLite" or the uOptionText of group "databaseType" is "Direct MySQL" then
put empty into field "contacts"
put "SELECT firstname,lastname,contact_id FROM contacts" into tQSLQuery
put revDataFromQuery(comma,return,sDatabaseConnectionID,tSQLQuery) into tContacts
put tContacts into field "contacts"
end if

end databaseSelectAllNames

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: SQLite connection

Post by SparkOut » Sat Mar 29, 2014 12:47 am

The line

put "SELECT firstname,lastname,contact_id FROM contacts" into tQSLQuery

has the tSQLQuery variable name spelled wrongly. Is that just a copying typo? or ... I think that's possibly your issue. tSQLQuery will be empty so revDataFromQuery will try to run an empty query and fail.

jpyck
Posts: 8
Joined: Tue Mar 11, 2014 5:12 pm

Re: SQLite connection

Post by jpyck » Sat Mar 29, 2014 3:08 am

Thanks Sparkout, that was it. I must have stared at it too long...a second pair of eyes always works.
Jack

Post Reply

Return to “idea2app and Coding School”