Page 1 of 1

Opening SQLite

Posted: Tue Jun 18, 2013 8:07 pm
by sandybassett
I've finally got the correct syntax for opening a SQLite database, creating a table, entering data and displaying data. Works great, so easy after you know it. Now I want to start making it user-friendly for users. Now (as in the lessons) you click a button to open the database before proceeding. How can I make it so it opens automatically when the program starts? without user action. I tried on open, on preopen, etc and that always produces error messages at the databaseconnect line. Surely there is some way. Thanks for any help.

Re: Opening SQLite

Posted: Tue Jun 18, 2013 10:05 pm
by Klaus
Hi Sandy,

## I tried on open, on preopen...
open and preopen what?
Where is your databqse located?

Please post your script(s), guessing is ineffective ;-)


Best

Klaus

Re: Opening SQLite

Posted: Tue Jun 18, 2013 10:32 pm
by sandybassett
Here's my code:
global gDatabasePath,gDatabaseID

on databaseConnect ##put into preopen
put specialFolderPath("desktop") & "/apartments.sqlite" into gDatabasePath
put revOpenDatabase("sqlite", gDatabasePath, , , , ) into myDatabaseID
if myDatabaseID is an integer then
put myDatabaseID into gDatabaseID
answer "Good Connection"
else
beep
answer error "An error occurred:" && item 2 of myDatabaseID
end if
end databaseConnect

The "on databaseConnect" routine works fine from a user button mouse up call, but what I want is a way to make it operate automagically when the stack is turned on, with no operator action required. Thanks for your help.

Re: Opening SQLite

Posted: Wed Jun 19, 2013 8:30 am
by bangkok
sandybassett wrote: The "on databaseConnect" routine works fine from a user button mouse up call, but what I want is a way to make it operate automagically when the stack is turned on, with no operator action required. Thanks for your help.
In the stack script :

Code: Select all

on openstack
databaseConnect
end openstack
And put the databaseConnect script in the stack script as well.

That will do. Watchout if you use datagrids and you edit template, or substack (because in this case, openstack will be fired again).

Re: Opening SQLite

Posted: Wed Jun 19, 2013 10:09 am
by Klaus
Hi Sandy,

as bangkok says :-)

Hint: There is no "open" or preopen" message!
You probably mean "preopenSTACK" or "preopenCARD" or "openCARD" or "preopencard", right? ;-)


Best

Klaus