database connection error
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
database connection error
Hi all,
Im trying to connect to my database, but I seem to be getting an error "Chunk: no such object - near status". Im not sure what that quite means. The code Im having problems with is below.
put "SQLite DB: " & realpath & "/data.sqlite" into field status
on the preOpenStack I have the following:
global realPath
put the effective filename of this stack into realpath
Many Thanks
Im trying to connect to my database, but I seem to be getting an error "Chunk: no such object - near status". Im not sure what that quite means. The code Im having problems with is below.
put "SQLite DB: " & realpath & "/data.sqlite" into field status
on the preOpenStack I have the following:
global realPath
put the effective filename of this stack into realpath
Many Thanks
Re: database connection error
Well, it's a bit hard to tell with code out of context, but...
You've got the global referenced locally in your preOpenStack handler. Is it also referenced where your "put" statment is? Try moving the global declaration out of any handler.
But it sounds like the error is referring to the field.
Is there a field named "status"? Try putting quotes around status.
You've got the global referenced locally in your preOpenStack handler. Is it also referenced where your "put" statment is? Try moving the global declaration out of any handler.
But it sounds like the error is referring to the field.
Is there a field named "status"? Try putting quotes around status.
Re: database connection error
Hi mweider,
Thanks for replying. Im playing around with Townsend's CRUD example database.
So far Ive changed the status code I was having trouble with to the following underneath. The only thing is, although LC isn't generating any errors, Im not sure its actually making the connection, as when I try one of the insert statements - its says no such table exists even though I know there is a table. Is there an easy what to find out if the connection made is valid?
Thanks for replying. Im playing around with Townsend's CRUD example database.
So far Ive changed the status code I was having trouble with to the following underneath. The only thing is, although LC isn't generating any errors, Im not sure its actually making the connection, as when I try one of the insert statements - its says no such table exists even though I know there is a table. Is there an easy what to find out if the connection made is valid?
Code: Select all
global conID -- connection ID
global realPath -- where executable was started
global supress
constant sq="'"
on preOpenStack
set itemDel to slash -- start to build current path for SQlite DB
put the effective filename of this stack into realpath --gets current path
delete last item of realpath --removes .livecode file name on this stack
put realpath & "/ProjectElement.sqlite" into pathNdb -- adds SQLite file name to path
end preOpenStack
on connectDB
put revopendatabases("sqlite",,,,) into dbIDs --gets a list of open databases
answer dbIDs
if not (conID is among the items of dbIDs) then -- needs new connection id
put revOpenDatabase("sqlite", pathNdb,,,,,,) into conID
put the result into temp
if the result is not a number then
answer "ERROR=" & conID
end if
end if
end connectDB
Re: database connection error
if the error message is no such table, it sounds as though the connection IS valid. (you can look at revopendatabases() to see if there is a connected database also, it will return the connection id of all currently open databases)
Is it possible there is a table name typo, or a syntax or structure error in your query?
YOu can also look at revdatabasetablenames(yourConnectionId) to see what tables are available for comparison purposes.
Is it possible there is a table name typo, or a syntax or structure error in your query?
YOu can also look at revdatabasetablenames(yourConnectionId) to see what tables are available for comparison purposes.
Re: database connection error
Hi Sturgis,
When I use the revopendatabases() - I usually get an integer back, 1, 2 or 3 - depends on how many times Ive tried connecting to the database.
The thing is when I try revDatabaseTableNames(1) or 2 or 3 I don't get anything returned. So Im assuming its not connecting to my database correctly?
When I use the revopendatabases() - I usually get an integer back, 1, 2 or 3 - depends on how many times Ive tried connecting to the database.
The thing is when I try revDatabaseTableNames(1) or 2 or 3 I don't get anything returned. So Im assuming its not connecting to my database correctly?
Re: database connection error
Ok sorted it - made a connection and I think the fun begins now 

Re: database connection error
Glad you got it sorted out. Sounds to me like there was a valid connection but no tables? Or was it something else? Just curious, if it is a quirk in the system I'd like to know about it for future reference.
jalz wrote:Ok sorted it - made a connection and I think the fun begins now
Re: database connection error
Hi Sturgis,
It was me - no bug. I hadn't got the pathname in the "put revOpenDatabase("sqlite",,,,,,,) into conID".
I was also declaring the pathname as a local variable in the preOpenStack and then trying to use that variable in another handler, and I don't think you can pass local variables on. Ive stuck everything in the preopenstack seems to be working. Will add in more code for error trapping and stuff.
It was me - no bug. I hadn't got the pathname in the "put revOpenDatabase("sqlite",,,,,,,) into conID".
I was also declaring the pathname as a local variable in the preOpenStack and then trying to use that variable in another handler, and I don't think you can pass local variables on. Ive stuck everything in the preopenstack seems to be working. Will add in more code for error trapping and stuff.
Re: database connection error
ah k. Been there too. Can be really hard to track down oopses sometimes.
To avoid a potential future issue, i'd recommend against putting the stuff into preopenstack. openstack should be ok, so should preopencard or opencard but preopenstack is early enough it can cause problems because the database external is not yet loaded. (check revopendatabase in the dictionary, look at the very last user comment by oliver) In the IDE its a non-issue, but once you start building standalones it can come back to bite you.
To avoid a potential future issue, i'd recommend against putting the stuff into preopenstack. openstack should be ok, so should preopencard or opencard but preopenstack is early enough it can cause problems because the database external is not yet loaded. (check revopendatabase in the dictionary, look at the very last user comment by oliver) In the IDE its a non-issue, but once you start building standalones it can come back to bite you.
jalz wrote:Hi Sturgis,
It was me - no bug. I hadn't got the pathname in the "put revOpenDatabase("sqlite",,,,,,,) into conID".
I was also declaring the pathname as a local variable in the preOpenStack and then trying to use that variable in another handler, and I don't think you can pass local variables on. Ive stuck everything in the preopenstack seems to be working. Will add in more code for error trapping and stuff.