Page 1 of 1
Invalid connection id error
Posted: Fri Dec 14, 2012 11:36 am
by rleiman
Hi Everyone,
I'm using Mac OSX for the operating system.
I'm running a stack from lesson number 5 from the LiveCode Academy called "Simple Query Example" and it is giving the following error:
The only thing I changed was the specialFolderPath to where the database was as shown in this coding:
Code: Select all
local sDatabaseID
on preopencard
put empty into field "details"
end preopencard
on connectToDatabase
local tDatabasePath, tSQLQuery
## Connect to the database
## Save the connection id
put specialFolderPath("emailaddresses.sqlite") into tDatabasePath
put revOpenDatabase("sqlite",tDatabasePath,,,,) into sDatabaseID
end connectToDatabase
on displayDetails
## Query all details
## Put the result into the field
put "SELECT * from contact_details" into tSQLQuery
put revDataFromQuery(tab, return, sDatabaseID, tSQLQuery) into field "details"
end displayDetails
Since I'm new to the language, can you tell me what else I need to do to get it working?
I made sure the database was in the same location as the other files for this stack.
Thanks.
Re: Invalid connection id error
Posted: Fri Dec 14, 2012 11:46 am
by Klaus
Hi rleiman,
well, "specialfolderpath()" is a function with FIXED parameters, please read up this term in hte dictionary!
You connot supply your own parameter
So your line:
...
put specialFolderPath("emailaddresses.sqlite") into tDatabasePath
..
does not create a valid path and will give an error later.
Where exactly is your database "emailaddresses.sqlite" located?
You need to supply the full path to that db file in your "connection" script!
Best
Klaus
P.S
Welcome to the forum!

Re: Invalid connection id error
Posted: Fri Dec 14, 2012 4:24 pm
by rleiman
Thanks for the reply.
All files are in the same folder on my Mac.
I'm at work now so I can't tell you the exact path but it's off the main user folder in a folder called iosdevelopment.
If you can tell me how to proceed that will be appreciated.
Thanks.
Re: Invalid connection id error
Posted: Fri Dec 14, 2012 4:43 pm
by Klaus
Hi rleiman,
so the stack and the db file are in the same folder?
Be sure to read up all terms in capitals in the dictionary!
Then you could do something like this:
...
## 1. get the filename (0 path) to your stack
put the effective filename of this stack into tDatabasePath
## I use the "EFFECTIVE" keywords, since this will also work for substacks, which do not have a FILENAME of their own!
## this will result in something like this on my Mac
## -> /Applications/Revolution Enterprise/cool_stack.livecode
## 2. now set the ITEMDELIMITER to extract the "parent" folder from the name
## pathnames in Livecode always use the UNIX style SLASH as a pathdelimiter!
set itemdel to "/"
## 3. Instead of extracting the "parent" folder, we simply overwrite "cool_stack.livecode" with "emailaddresses.sqlite"
## in the last item of tDatabasePath and voila, the absolute path to your database file
put "emailaddresses.sqlite" into item last item of tDatabasePath
## -> /Applications/Revolution Enterprise/emailaddresses.sqlite
## Now tDatabasePath contains the correct path to your database file, ready to use
...
Best
Klaus
Re: Invalid connection id error
Posted: Fri Dec 14, 2012 4:48 pm
by bangkok
I think your problem is coming from :
You declared it as... a local variable.
And then you use it in several handler.
It can't work.
In your script, at the top of it, put :
Global sDatabaseID
Then the content of sDatabaseID will be available to all your handlers (but be sure to remove all the other local sDatabaseID)
Re: Invalid connection id error
Posted: Fri Dec 14, 2012 4:59 pm
by Klaus
Yes, but the main problem was: specialFolderPath("emailaddresses.sqlite")

Re: Invalid connection id error
Posted: Fri Dec 14, 2012 5:09 pm
by sturgis
Its declared as a script local, so all the handlers in that script should be fine with it that way. If other handlers are being called of course, then theres a problem, but my guess is that all the handlers are in the same script.
bangkok wrote:I think your problem is coming from :
You declared it as... a local variable.
And then you use it in several handler.
It can't work.
In your script, at the top of it, put :
Global sDatabaseID
Then the content of sDatabaseID will be available to all your handlers (but be sure to remove all the other local sDatabaseID)
Re: Invalid connection id error
Posted: Sun Dec 16, 2012 2:53 pm
by rleiman
Thanks everyone for your replies and help.
I have it working now.
I originally thought that specialFolderPath was required for a database path since that was how it was shown in the tutorial. After reading your replies, I stuck in an "answer" statement to see what the actual path specialFolderPath was giving me and it was not where the database was located.
I looked at the properties of where I moved all of the files in finder and found out what the actual path was and included it like this statement:
Code: Select all
put "/Users/emad-ud-deenleiman/Development/iosdevelopment/CBT/ExampleStacks/emailaddresses.sqlite" into tDatabasePath
Re: Invalid connection id error
Posted: Sun Dec 16, 2012 2:58 pm
by Klaus
OK, but this absolute and hard-coded pathname will only work on your machine, I'm sure you know this!

Re: Invalid connection id error
Posted: Sun Dec 16, 2012 6:30 pm
by rleiman
Hi,
Yes. I know. It's just for working with the tutorials and I will need to find out later how to do it for development on IOS.
