Invalid connection ID

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
riccardo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 13
Joined: Sat Apr 15, 2006 10:03 am
Location: Italia

Invalid connection ID

Post by riccardo » Mon May 29, 2006 6:57 pm

Hi,
I am trying a query to MySQL database using MacOS X 10.4.6 and Rev 2.6.1.
When I am in IDE environment all works fine, but when I make a standalone application I have the following error:
-the connection is OK
the revOpenDatabase returns a connection ID
-the first query returns the error : revdberr, invalid connection ID

Have you any suggestion?
Thanks in advance

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Re: Invalid connection ID

Post by Janschenkel » Mon May 29, 2006 7:26 pm

Hi Riccardo,

Could you post the exact script here?
It should be something like:

Code: Select all

on mouseUp
  put revdb_connect("mysql","host:port","schema","user,"password") into tConnectionID
  if tConnectionID is not a number then
    answer error tConnectionID
    exit mouseUp
  end if
  put revdb_query(tConnectionID,"SELECT * FROM foobar") into tCursorID
  if tCursorID is not a number then
    answer error tCursorID
    exit mouseUp
  end if
  -- do some more stuff with the db cursor
  -- ...
  -- cleanup time
  get revdb_closecursor(tCursorID)
  get revdb_disconnect(tConnectionID)
end mouseUp
Also, if you're using the revdb_querylist function (or its synonym revDataFromQuery) then the connectionID is the third parameter, as the first and second parameter are the column and row delimiter, respectively.

Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

riccardo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 13
Joined: Sat Apr 15, 2006 10:03 am
Location: Italia

Post by riccardo » Tue May 30, 2006 6:30 am

Hi Jan,
the script is correct (it is like yours) and it works in other platformors without any problem.
It also works if I use it in IDE environment, but it doesn't work only in standalone.

Riccardo

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1236
Joined: Sat Apr 08, 2006 1:10 pm
Location: Zurich
Contact:

Post by BvG » Tue May 30, 2006 3:42 pm

Have you checked if the inclusions are there? there needs to be an mysql file next to the executable in the bundle. Sometimes Rev doesn't add them automatically, and you have to do it by hand. THere are 2 ways to do that:

In the "General" tab of the "Standalone Application Settings..." you can choose "Select inclusions for standalone application".
Then check "Database support" and make sure the "mysql" line is selected in the field below that checkbox.

If that doesn't help, you need to copy the mysql external yourself from the rev standalone to your app bundle.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Tue May 30, 2006 5:11 pm

Hi Riccardo,

If it works inside the Rev IDE, but not in your standalone, that's quite puzzling. As I don't know how your app works, I can only suggest that you add the following line just before your call to revdb_query, so you can check if you're using the wrong connection ID, or if some other piece of code has closed the connection behind your back.

Code: Select all

answer "revdb_connections:" && revdb_connections() & return & "tConnectionID:" && tConnectionID
Hope this brings you closer to the solution,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

riccardo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 13
Joined: Sat Apr 15, 2006 10:03 am
Location: Italia

Post by riccardo » Tue May 30, 2006 5:54 pm

I have checked the external files and they are OK.
As Jan suggested, I have verified the open connections before the query and I have discovered that I have no active connections.
It is very strange because the same app worked same days ago and in IDE environment it works again now.
I don't have any close database commands. Only in the shutdownrequest handler I close the database connection, but if I put an answer command, in order to debug the event handler, I can note that it is not called before.

Is there any condition for automatic database closing in standalone or have you any other suggestions?
Thank
riccardo

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Tue May 30, 2006 7:23 pm

In that case, put an answer command right after the database connection is opened, to make sure that this handler is called:

Code: Select all

put revdb_connect("mysql","host:port","schema","user,"password") into tConnectionID
answer "Opened connection:" && tConnectionID
For debugging purposes, you could also trap the revdb_disconnect function yourself before it is passed on to the external library, so you can display a message, and pass it on or not. Add the following code to your mainStack script:

Code: Select all

function revdb_disconnect pConnectionID
  put "revdb_disconnect() called: & return & \
      "--" && "the executionContexts" && "--" & return & \
      the executionContexts & return & \
      "--" && "connection ID" && "--" & return & \
      pConnectionID & return & \
      "--" && "revdb_connections()" && "--" & return & \
      revdb_connections() \
      into tPrompt
  answer tPrompt with "OK" or "Cancel"
  if it is "OK" then pass revdb_disconnect
end revdb_disconnect
Of course, this won't trap a call to the 'revCloseDatabase' command, but I'll leave that bas an exercise to the reader :wink:

Let us know how it works out for you.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

riccardo
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 13
Joined: Sat Apr 15, 2006 10:03 am
Location: Italia

Post by riccardo » Wed May 31, 2006 7:59 am

Thanks Jan,
I found the error and I hope that it can help others.

The problem is in the following code located in the openstack handler of the main stack:

Code: Select all

     put the substacks of stack "Xdent" into lista
     repeat with i=1 to the num of lines of lista
        put line i of lista into finestra
          set the decorations of stack finestra to "title,menu,minimize,maximize,close,metal"
      end repeat
If I use the code in IDE environment it works, but if I build the standalone same library stacks are added to the substack list.
In particular when the above script sets the decoration of the revMaxCursor stack the connection is closed and obviously any subsequent query command returns an invalid connection ID.

This happens only if I use this type of decoration. If I set the decorations to default it works.

In order to avoid this problem I use these modified script:

Code: Select all

     put the substacks of stack "Xdent" into lista
     repeat with i=1 to the num of lines of lista
        put line i of lista into finestra
        if char 1 to 3 of finestra<>"rev" and word 2 of finestra<>"dialog" then
          set the decorations of stack finestra to "title,menu,minimize,maximize,close,metal"
        end if
      end repeat
riccardo

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Location: Aalst, Belgium
Contact:

Post by Janschenkel » Wed May 31, 2006 10:06 am

Thanks for the update - have you submitted this problem to bugzilla?
That way the RunRev engineers can study it and provide a fix.

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Post Reply

Return to “Databases”