Database connection ids incrementing
Posted: Fri Sep 20, 2013 10:29 am
Hi. I'm new to LiveCode but not to databases. (using Livecode 5.5.5 on a PC 64 bit, Intel I5, Win8, ODBC with MS Access 2013 and SQLite 3) In my experience, one attempts to reuse database ids to the extent possible, but the revOpenDatabase function seems to increment the id, both in my code and the user samples I've downloaded, including the sqlite sample that came with the development environment. There also seems to be a difference of opinion as to where to declare global variables, either outside or inside a command, or in a card or stack. I have a reasonable nube understanding of your messaging hierarchy, but I figure if I go by your sqlite sample, I should be on safe ground. The query part works fine but the adding and editing parts are looking for the global id, evidently, yielding a runreverr.
I've evolved several methods for closing the db connection, using the examples I could find, but they seem to be using a number other than the current db id, even though I think I should be catching it after the increment, since I'm passing the db id to the global variable after the RevOpenDatabase function (which is the one causing the increment).
As a user of VB and FoxPro, I've always declared globals once outside of a procedure and I don't understand the logic of declaring a global in a command, since to me that would remove the value you were presumably attempting to retain through your use of the "global".
What I'm asking is either for a failsafe db close routine (which I thought I had) or for a parameter on an open routine that would use previous db connection ids by default, or for something really obvious that I missed simply because I'm a nube. Thanks in advance for any enlightenment you might provide.
Examples from present code:
This line alone increments, as I assume it was designed to do by default (it does find and display the data source):
put revOpenDatabase("ODBC","cat", "CatData","","" ) into tDatabaseID
I've used infinite varieties of this, in and out of commands:
global sDatabaseID
put sDatabaseID into tDatabaseID (the local variable receiving the connection ID)
And I'm closing with various iterations of this:
command databaseClose
revCloseDatabase tDatabaseID
put empty into tDatabaseID
put empty into tDatabaseID
answer tDatabaseID
answer tDatabaseID
end databaseClose
I've evolved several methods for closing the db connection, using the examples I could find, but they seem to be using a number other than the current db id, even though I think I should be catching it after the increment, since I'm passing the db id to the global variable after the RevOpenDatabase function (which is the one causing the increment).
As a user of VB and FoxPro, I've always declared globals once outside of a procedure and I don't understand the logic of declaring a global in a command, since to me that would remove the value you were presumably attempting to retain through your use of the "global".
What I'm asking is either for a failsafe db close routine (which I thought I had) or for a parameter on an open routine that would use previous db connection ids by default, or for something really obvious that I missed simply because I'm a nube. Thanks in advance for any enlightenment you might provide.
Examples from present code:
This line alone increments, as I assume it was designed to do by default (it does find and display the data source):
put revOpenDatabase("ODBC","cat", "CatData","","" ) into tDatabaseID
I've used infinite varieties of this, in and out of commands:
global sDatabaseID
put sDatabaseID into tDatabaseID (the local variable receiving the connection ID)
And I'm closing with various iterations of this:
command databaseClose
revCloseDatabase tDatabaseID
put empty into tDatabaseID
put empty into tDatabaseID
answer tDatabaseID
answer tDatabaseID
end databaseClose