on-rev queries

Bob Sneidar bobs at twft.com
Tue Feb 2 19:53:07 EST 2010


Okay, for anyone who is interested, the trick to adding and dropping tables (or executing any odd sql) when using sqlYoga is that you have to tell sqlYoga that the schema has changed. The easiest way to do that is reset the schema with dbschema_reset, then reconnect to the database. JUST reconnecting will NOT reload the schema causing you all kinds of headaches in the future. 

    dbschema_reset thePriDB
    dbconn_disconnect thePriDB
    dbconn_Connect thePriDB

I'm not sure you have to disconnect first but what the HEY! Also, any queries you use with sqlYoga will AUTOMATICALLY reconnect to the database. BUT if you are using the REV IDE to execute what I will call "foreign" queries, that is queries not run through sqlYoga, AND your connection has timed out, you will have problems, SO...

I now use dbconn_connect before executing "foreign" queries. 

    put "DROP TABLE 'myhostname'.'mytablename'" into theSQL -- foreign query
    dbconn_Connect thePriDB -- make sure we are currently connected
    put dbconn_get("connection id", theConnection, theDBObject) into theID -- get the current dbid
    revExecuteSQL theID, theSQL -- shoot the wild ass (just checking to see if you are reading the comments)

    -- now reload the schema
    dbschema_reset thePriDB -- wipes the database object clean
    dbconn_disconnect thePriDB -- may not need to do this...
    dbconn_Connect thePriDB  -- this will reload the schema
    dbobject_save thePriDB -- ALWAYS SAVE YOUR OBJECTS!

This will refresh the connection id before you execute the query and all will proceed famously. 

Problem solved. 

Bob





More information about the Use-livecode mailing list