Opening SQLite

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
sandybassett
Posts: 35
Joined: Fri May 31, 2013 7:44 pm

Opening SQLite

Post by sandybassett » Tue Jun 18, 2013 8:07 pm

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.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Opening SQLite

Post by Klaus » Tue Jun 18, 2013 10:05 pm

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

sandybassett
Posts: 35
Joined: Fri May 31, 2013 7:44 pm

Re: Opening SQLite

Post by sandybassett » Tue Jun 18, 2013 10:32 pm

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.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Opening SQLite

Post by bangkok » Wed Jun 19, 2013 8:30 am

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).

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Opening SQLite

Post by Klaus » Wed Jun 19, 2013 10:09 am

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

Post Reply