Linking Database Query Host field to a variable

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Linking Database Query Host field to a variable

Post by chris9610 » Tue Aug 25, 2009 3:36 pm

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?
Developing with Windows XP & Revolution 4.5

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post subject: Linking Database Query Host field to a variabl

Post by chris9610 » Tue Aug 25, 2009 3:46 pm

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.
Developing with Windows XP & Revolution 4.5

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

Post by Janschenkel » Tue Aug 25, 2009 3:53 pm

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post by chris9610 » Tue Aug 25, 2009 4:25 pm

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.
Developing with Windows XP & Revolution 4.5

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post by chris9610 » Wed Aug 26, 2009 2:34 am

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.
Developing with Windows XP & Revolution 4.5

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post by chris9610 » Mon Aug 31, 2009 1:58 am

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
Developing with Windows XP & Revolution 4.5

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

Post by Janschenkel » Mon Aug 31, 2009 4:58 am

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.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post by chris9610 » Mon Aug 31, 2009 3:27 pm

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.
Developing with Windows XP & Revolution 4.5

Post Reply