revOpenDatabase Problem

Bob Sneidar bobs at twft.com
Tue Dec 27 12:35:32 EST 2011


After opening it, and inside a try/catch statement just use select TRUE as connected and get the query as a string. If it throws an error you know something is wrong. 

One thing I like to do in database driven apps is create handlers called dbopen, dbclose, dbIdle isConnected. In those handlers I put the database commands inside try/catch constructs, and return false when I fail. Before any query I will call isConnected, which attempts to do some arbitrary thing with the database, like select TRUE as connected, which will return 1 if it succeeds and throw an error if it doesn't. When I am done I call dbIdle which closes the connection (good practice because the server is going to disconnect you anyway after a certain amount of time). 

The Open function attempts a connection to the database with the options the user entered on a setup card. If successful, I set a global I can check in the future to make sure I successfully connected on startup. If the global is false, then I prevent any interaction with the app, sometimes quitting (if not in development). 

By doing this I don't have to recode error handling every place I need to query. isConnected, upon failing will exit to top after alerting the user that something is wrong. The close handler will close all cursors and database handlers, but this is not strictly necessary, as dbIdle. 

Since using sqlYoga, this is all rather moot anyway, as this kind of functionality is built into it. 

Bob


On Dec 26, 2011, at 1:33 PM, Pete wrote:

> Using revOpenDatabase to open an sqlite database using a file that is not
> an sqlite database return an integer as if the database was successfully
> opened.  Any subsequent db accesses fail of course but I wonder why
> revOpenDatabase doesn't return an error?
> 
> 
> -- 
> Pete
> Molly's Revenge <http://www.mollysrevenge.com>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list