Page 1 of 1

Linking Database Query Host field to a variable

Posted: Tue Aug 25, 2009 3:36 pm
by chris9610
Does anyone know how to link the Host field in the Database Query builder to a variable?

I am using one database from different access points and I need a way to dynamically link the Host field to different IP addresses.

Say a global variable would be nice.

Does anyone know if this can be done? Can a variable be used for the Host field in the Database Query builder?

This seems like a requirement for applications which share a server in a local area network. Once a script is compiled how would you change the IP of your server?

Post subject: Linking Database Query Host field to a variabl

Posted: Tue Aug 25, 2009 3:46 pm
by chris9610
The runrev user guide states that if no Host is supplied then the default is used.

How do I set the default?

I guess this is what I need to do.

Posted: Tue Aug 25, 2009 3:53 pm
by Janschenkel
I'm afraid you can't use a variable for that; but thanks to some inner knowledge of how the automated database queries work, I think I have a workaround for you.
The tricky part is that the revDatabase frontscript will receive the preOpenStack event before you get a chance to change any of the settings, and try and open the database connection. Which means you have to change the settings during the startup event - which your stack will only receive when compiled into a standaloine application.
So you would add something like the following to your stack script:

Code: Select all

on startup
  -- you may want to read it somewhere from a file
  put "123.123.123.123" into tIPAddress
  UpdateDBHost tIPAddress
  pass startup
end startup

on UpdateDBHost pHost
  put revQueryObjects(the longname of this stack) into tQueryObjects
  repeat for each line tQueryObject in tQueryObjects
    set the cREVDatabaseQuery["dbhost"] of tQueryObject to pHost
  end repeat
end UpdateDBHost
Caveat: I didn't test this, but it should work. At least until the RunRev team changes the innards of the implementation...

Best of luck,

Jan Schenkel.

Posted: Tue Aug 25, 2009 4:25 pm
by chris9610
Janschenkel:

Thank you so much. This is exactly what I need.

I will test it and report back.

I did not know how to retrieve the properties of the Query Object to know what values to change. There are clues in the user guide but just clues only.

This is a real learning experience.

Posted: Wed Aug 26, 2009 2:34 am
by chris9610
Janschenkel:


Many thanks
, your example worked good. It does exactly the changes I need to set the Host IP address as needed.

I am new to runrev and this adds to my learning experience.

Posted: Mon Aug 31, 2009 1:58 am
by chris9610
Janschenkel:

The query Host change is working good for me.

Now I find the need to change the database name in some select the querys.

How can I get a list of the cREVDatabaseQuery keys so I can make the dynamic changes needed at run time?

TIA

Posted: Mon Aug 31, 2009 4:58 am
by Janschenkel
The easiest way to get to the 'revDatabase' frontscript (which implements these automated queries) is:
  1. Open the Message box
  2. Switch to the Front Scriptspanel - using the sixth button
  3. Tick the checkbox Show Revolution UI Front Scripts
  4. Doubleclick on the line revDatabase
At the top of this script, you'll find the different connection parameter property names. In this case, you're looking for

Code: Select all

the cREVDatabaseQuery["dbdatabase"]
HTH,

Jan Schenkel.

Posted: Mon Aug 31, 2009 3:27 pm
by chris9610
Jan:

Thank you again

This gives me the control over the database options which I needed.

What I have done is put together a logon script to multiple companies which require different database names and different hosts ip addresses dependent on the server used and the point from which it needs to be accessed. The companies have different database names with identical tables. So the same queries are designed to work with different databases ie different companies.

Without your help here there is no way I could have figured a way to incorporate the runrev queries. So this helps me tremendously.