database connection error

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

database connection error

Post by jalz » Wed Feb 22, 2012 9:26 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: database connection error

Post by mwieder » Wed Feb 22, 2012 9:41 pm

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.

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: database connection error

Post by jalz » Wed Feb 22, 2012 11:23 pm

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?

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


sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: database connection error

Post by sturgis » Thu Feb 23, 2012 12:25 am

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.

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: database connection error

Post by jalz » Thu Feb 23, 2012 10:06 pm

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?

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: database connection error

Post by jalz » Thu Feb 23, 2012 11:23 pm

Ok sorted it - made a connection and I think the fun begins now :)

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: database connection error

Post by sturgis » Thu Feb 23, 2012 11:56 pm

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

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: database connection error

Post by jalz » Fri Feb 24, 2012 9:32 pm

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.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: database connection error

Post by sturgis » Fri Feb 24, 2012 9:40 pm

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

Post Reply