simultaneous multiple database access

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Steve
Posts: 30
Joined: Fri Nov 07, 2008 10:46 pm
Location: Iowa, U.S.A.
Contact:

simultaneous multiple database access

Post by Steve » Mon Jun 09, 2014 9:25 am

MySQL allows you to copy a table from one database to another with this type of format:
CREATE TABLE database1.newtable LIKE database2.oldtable
INSERT database1.newtable SELECT * FROM database2.oldtable

The syntax database.table allows one to specify a table of a particular database, so you can use two different databases in a single command.

But LiveCode uses connection numbers to access databases, and only allows one connection number in a particular command (like the revExecuteSQL command).

So, how can one perform operations across databases, like copying a table from one database to another, which must be done in a single command?

Thanks,

Steve
Steve Alessi
Associate Professor
The University of Iowa

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Location: UK
Contact:

Re: simultaneous multiple database access

Post by splash21 » Mon Jun 09, 2014 2:09 pm

Hi, Steve. If you grant the user that you connect with privileges for both databases, then you can access both DB's from 1 query.
LiveCode Development & Training : http://splash21.com

Steve
Posts: 30
Joined: Fri Nov 07, 2008 10:46 pm
Location: Iowa, U.S.A.
Contact:

Re: simultaneous multiple database access

Post by Steve » Mon Jun 09, 2014 2:42 pm

Terrific! Can you give me a brief LiveCode example?

Thanks,

Steve Alessi
Steve Alessi
Associate Professor
The University of Iowa

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Location: UK
Contact:

Re: simultaneous multiple database access

Post by splash21 » Wed Jun 11, 2014 3:39 pm

You can run something like the following providing you have the appropriate privileges;

Code: Select all

GRANT ALL ON otherDatabase.* TO 'user'@'localhost';
Check out the docs here...
http://dev.mysql.com/doc/refman/5.1/en/grant.html
LiveCode Development & Training : http://splash21.com

Steve
Posts: 30
Joined: Fri Nov 07, 2008 10:46 pm
Location: Iowa, U.S.A.
Contact:

Re: simultaneous multiple database access

Post by Steve » Wed Jun 11, 2014 6:07 pm

Hi Splash21,

Sorry ... I was not clear in my question. I know how to grant permissions. What I don't know how to do is refer to two databases in one statement.

For example, in MySQL you can do this:
CREATE TABLE database1.newtable LIKE database2.oldtable -- which refers to two different databases
INSERT database1.newtable SELECT * FROM database2.oldtable -- which also refers to two different databases

But what would the equivalent syntax be in a LiveCode revExecuteSQL command? All the documentation and examples I can find demonstrate access to a single database, because only one connection number parameter is permitted.

Thanks again,

Steve Alessi
Steve Alessi
Associate Professor
The University of Iowa

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Location: UK
Contact:

Re: simultaneous multiple database access

Post by splash21 » Fri Jun 13, 2014 11:40 am

If you are connected to a database and want some info from 'database2' included in the results, you can ....

Code: Select all

SELECT users.name, colours.favouriteColour FROM users, database2.colours AS colours WHERE users.userId = colours.userId
...just specify the database name in the table alias :)
LiveCode Development & Training : http://splash21.com

Steve
Posts: 30
Joined: Fri Nov 07, 2008 10:46 pm
Location: Iowa, U.S.A.
Contact:

Thanks very much

Post by Steve » Fri Jun 13, 2014 2:35 pm

Hi Splash21,

Thanks very much! That worked for me inside a revExecuteSQL command. I guess I should have tried it, because it is standard mySQL syntax. But because the revExecuteSQL command refers to a database connection number, I assumed you could only operate on one database at a time. Apparently, the database connection number in LiveCode is somewhat "fake". You only have to give SOME exiting connection number, and your commands can then refer to ANY databases you have permission to access in your server area.

Thanks again,

Steve Alessi
Steve Alessi
Associate Professor
The University of Iowa

Post Reply

Return to “Databases”