<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Querying multiple databases within one cfquery</title>
	<atom:link href="http://www.chapter31.com/2008/12/03/querying-multiple-databases-within-one-cfquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chapter31.com/2008/12/03/querying-multiple-databases-within-one-cfquery/</link>
	<description>Rich Internet Application development</description>
	<lastBuildDate>Tue, 31 Jan 2012 15:10:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: David Sirr</title>
		<link>http://www.chapter31.com/2008/12/03/querying-multiple-databases-within-one-cfquery/comment-page-1/#comment-106257</link>
		<dc:creator>David Sirr</dc:creator>
		<pubDate>Thu, 03 Sep 2009 04:43:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.chapter31.com/?p=515#comment-106257</guid>
		<description>just a couple of notes, i&#039;m using MySQL 5.1 and CF8.01 hotfix3, and you can do this quite simply with aliases as normal without needed to explicitly qualify dbs in column references. You didnt need to qualify tables in the default database for the datasource either.

e.g. if there was the default DB of users, and a seperate DB accountsDB:
SELECT u.userName, a.account
FROM userDetails u INNER JOIN accountsDB.accountDetails a ON u.userid = a.userID
WHERE u.userid = 1;

Also, this approach definitely works in MSSQL (or did work when i last used it 3 years ago) we had large telecommunications databases to report across, the only difference in approach is that you need to add a schema,

e.g. in the above scenario if the default dbo schema
SELECT u.userName, a.account
FROM userDetails u INNER JOIN accountsDB.dbo.accountDetails a ON u.userid = a.userID
WHERE u.userid = 1;

you could also omit the default schema from memory but the period marker is required, so you could do:
SELECT u.userName, a.account
FROM userDetails u INNER JOIN accountsDB..accountDetails a ON u.userid = a.userID
WHERE u.userid = 1;

additionally if you configured linked servers inside MSSQL administrator you could take it a level higher to communicate between multiple SQL Servers with an additional servername prefix to the database name:
SELECT u.userName, a.account
FROM userDetails u INNER JOIN differentServer.accountsDB.dbo.accountDetails a ON u.userid = a.userID
WHERE u.userid = 1;

so the absolute reference to the table was of the format: server.database.schema.table</description>
		<content:encoded><![CDATA[<p>just a couple of notes, i&#8217;m using MySQL 5.1 and CF8.01 hotfix3, and you can do this quite simply with aliases as normal without needed to explicitly qualify dbs in column references. You didnt need to qualify tables in the default database for the datasource either.</p>
<p>e.g. if there was the default DB of users, and a seperate DB accountsDB:<br />
SELECT u.userName, a.account<br />
FROM userDetails u INNER JOIN accountsDB.accountDetails a ON u.userid = a.userID<br />
WHERE u.userid = 1;</p>
<p>Also, this approach definitely works in MSSQL (or did work when i last used it 3 years ago) we had large telecommunications databases to report across, the only difference in approach is that you need to add a schema,</p>
<p>e.g. in the above scenario if the default dbo schema<br />
SELECT u.userName, a.account<br />
FROM userDetails u INNER JOIN accountsDB.dbo.accountDetails a ON u.userid = a.userID<br />
WHERE u.userid = 1;</p>
<p>you could also omit the default schema from memory but the period marker is required, so you could do:<br />
SELECT u.userName, a.account<br />
FROM userDetails u INNER JOIN accountsDB..accountDetails a ON u.userid = a.userID<br />
WHERE u.userid = 1;</p>
<p>additionally if you configured linked servers inside MSSQL administrator you could take it a level higher to communicate between multiple SQL Servers with an additional servername prefix to the database name:<br />
SELECT u.userName, a.account<br />
FROM userDetails u INNER JOIN differentServer.accountsDB.dbo.accountDetails a ON u.userid = a.userID<br />
WHERE u.userid = 1;</p>
<p>so the absolute reference to the table was of the format: server.database.schema.table</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Lynch</title>
		<link>http://www.chapter31.com/2008/12/03/querying-multiple-databases-within-one-cfquery/comment-page-1/#comment-83890</link>
		<dc:creator>Mark Lynch</dc:creator>
		<pubDate>Fri, 05 Dec 2008 04:49:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.chapter31.com/?p=515#comment-83890</guid>
		<description>@John
Pretty sure this doesn&#039;t work in MSSQL, I did try many years ago and failed.

In terms of a datasource connecting to a different database, when you specify the database to it doesn&#039;t stop the database being changed with a USE statement.
http://dev.mysql.com/doc/refman/5.0/en/use.html

This is a MySQL feature that is relatively unknown as CF makes it so easy to connect to db&#039;s.  It is also another reason to be careful about SQL Injection attacks, as it&#039;s not just the current database that can be accessed. 

If the following SQL was injected into your application it could give away a lot of information:

USE information_schema;
SELECT * FROM tables;

I think it&#039;s a great feature that MySQL enables, but you just need to be aware of it so that you can secure against it being misused.</description>
		<content:encoded><![CDATA[<p>@John<br />
Pretty sure this doesn&#8217;t work in MSSQL, I did try many years ago and failed.</p>
<p>In terms of a datasource connecting to a different database, when you specify the database to it doesn&#8217;t stop the database being changed with a USE statement.<br />
<a href="http://dev.mysql.com/doc/refman/5.0/en/use.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/use.html</a></p>
<p>This is a MySQL feature that is relatively unknown as CF makes it so easy to connect to db&#8217;s.  It is also another reason to be careful about SQL Injection attacks, as it&#8217;s not just the current database that can be accessed. </p>
<p>If the following SQL was injected into your application it could give away a lot of information:</p>
<p>USE information_schema;<br />
SELECT * FROM tables;</p>
<p>I think it&#8217;s a great feature that MySQL enables, but you just need to be aware of it so that you can secure against it being misused.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Sharman</title>
		<link>http://www.chapter31.com/2008/12/03/querying-multiple-databases-within-one-cfquery/comment-page-1/#comment-83853</link>
		<dc:creator>Michael Sharman</dc:creator>
		<pubDate>Thu, 04 Dec 2008 20:23:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.chapter31.com/?p=515#comment-83853</guid>
		<description>@John

&gt;First… you entered the code twice, you should remove the duplicate.
Hmm, the 2nd code block is slightly different as it qualifies the table name in the SELECT statement.

&gt;Do you have performance ratings?
Nothing at this stage but I would be curious to run some tests to get a general idea as to how good or bad this may be in heavy usage. For us this was really a proof of concept so I haven&#039;t investigated much further than actually getting it to work. Of course referential integrity is out the window, but for most users of MySQL this won&#039;t be a problem as the MyISAM engine doesn&#039;t allow for that anyway.

&gt;Can you insert and update like this? (rather limiting otherwise)
Whilst I didn&#039;t specifically test for this I can&#039;t see it working, just like you can&#039;t INSERT or UPDATE columns across multiple tables.

&gt;Has this been tested on MSSQL or Oracle or Derby?
Not yet, as I said we&#039;re at POC stage.

&gt;*** How did you set up a single data source to connect to two databases???
Ok, when in CF Admin create your datasource which of course just talks to a single database which you specify. The important thing here is the database user you in the &quot;username&quot; and &quot;password&quot; fields of the datasource. Let&#039;s say you used the following:

u: mydbusername
p: mydbpassword

This will allow ColdFusion to open a connection to the database using those credentials. Now you of course need to make sure that those user details are in place on the database server for the database specified in the ColdFusion datasource, but you also attach another database to that user (in the database user manager).

This means your single db user has access to multiple databases, so when ColdFusion sends the SQL to the database server for execution server it is successfully run because the user in your initial datasource has access to both databases.

Make sense?</description>
		<content:encoded><![CDATA[<p>@John</p>
<p>>First… you entered the code twice, you should remove the duplicate.<br />
Hmm, the 2nd code block is slightly different as it qualifies the table name in the SELECT statement.</p>
<p>>Do you have performance ratings?<br />
Nothing at this stage but I would be curious to run some tests to get a general idea as to how good or bad this may be in heavy usage. For us this was really a proof of concept so I haven&#8217;t investigated much further than actually getting it to work. Of course referential integrity is out the window, but for most users of MySQL this won&#8217;t be a problem as the MyISAM engine doesn&#8217;t allow for that anyway.</p>
<p>>Can you insert and update like this? (rather limiting otherwise)<br />
Whilst I didn&#8217;t specifically test for this I can&#8217;t see it working, just like you can&#8217;t INSERT or UPDATE columns across multiple tables.</p>
<p>>Has this been tested on MSSQL or Oracle or Derby?<br />
Not yet, as I said we&#8217;re at POC stage.</p>
<p>>*** How did you set up a single data source to connect to two databases???<br />
Ok, when in CF Admin create your datasource which of course just talks to a single database which you specify. The important thing here is the database user you in the &#8220;username&#8221; and &#8220;password&#8221; fields of the datasource. Let&#8217;s say you used the following:</p>
<p>u: mydbusername<br />
p: mydbpassword</p>
<p>This will allow ColdFusion to open a connection to the database using those credentials. Now you of course need to make sure that those user details are in place on the database server for the database specified in the ColdFusion datasource, but you also attach another database to that user (in the database user manager).</p>
<p>This means your single db user has access to multiple databases, so when ColdFusion sends the SQL to the database server for execution server it is successfully run because the user in your initial datasource has access to both databases.</p>
<p>Make sense?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Hoffman</title>
		<link>http://www.chapter31.com/2008/12/03/querying-multiple-databases-within-one-cfquery/comment-page-1/#comment-83846</link>
		<dc:creator>Eric Hoffman</dc:creator>
		<pubDate>Thu, 04 Dec 2008 18:50:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.chapter31.com/?p=515#comment-83846</guid>
		<description>We had done this as well as a proof of concept having been addressed a situation similarly.

Never went past the point of MySQL to see if it would work on other platforms.</description>
		<content:encoded><![CDATA[<p>We had done this as well as a proof of concept having been addressed a situation similarly.</p>
<p>Never went past the point of MySQL to see if it would work on other platforms.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Farrar</title>
		<link>http://www.chapter31.com/2008/12/03/querying-multiple-databases-within-one-cfquery/comment-page-1/#comment-83824</link>
		<dc:creator>John Farrar</dc:creator>
		<pubDate>Thu, 04 Dec 2008 15:05:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.chapter31.com/?p=515#comment-83824</guid>
		<description>First... you entered the code twice, you should remove the duplicate.

Second is the questions...
Do you have performance ratings?
Can you insert and update like this? (rather limiting otherwise)
Has this been tested on MSSQL or Oracle or Derby?
*** How did you set up a single data source to connect to two databases???</description>
		<content:encoded><![CDATA[<p>First&#8230; you entered the code twice, you should remove the duplicate.</p>
<p>Second is the questions&#8230;<br />
Do you have performance ratings?<br />
Can you insert and update like this? (rather limiting otherwise)<br />
Has this been tested on MSSQL or Oracle or Derby?<br />
*** How did you set up a single data source to connect to two databases???</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: chapter31.nfshost.com @ 2012-02-10 13:17:42 -->
