<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DJS Consulting Tech Blog &#187; Databases</title>
	<atom:link href="http://djs-consulting.com/linux/blog/category/databases/feed" rel="self" type="application/rss+xml" />
	<link>http://djs-consulting.com/linux/blog</link>
	<description>Technical Information You Can Use (or not - but hey, at least it&#039;s free!)</description>
	<lastBuildDate>Tue, 02 Mar 2010 19:11:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Oracle SQL Developer 2.1 Debian Package</title>
		<link>http://djs-consulting.com/linux/blog/2010/oracle-sql-developer-2-1-debian-package</link>
		<comments>http://djs-consulting.com/linux/blog/2010/oracle-sql-developer-2-1-debian-package#comments</comments>
		<pubDate>Tue, 02 Mar 2010 19:11:29 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://djs-consulting.com/linux/blog/?p=92</guid>
		<description><![CDATA[It had been a while since I had updated SQL Developer.  It turns out that version 2.1 was released March 1st of this year.  I&#8217;ve downloaded it and created a Debian package.  It can be downloaded from the DJS Consulting Linux Software Repository.
I&#8217;ve used it with Sun&#8217;s Java 6 Update 18; I [...]]]></description>
			<content:encoded><![CDATA[<p>It had been a while since I had updated SQL Developer.  It turns out that version 2.1 was released March 1st of this year.  I&#8217;ve downloaded it and created a Debian package.  It can be <a href="http://djs-consulting.com/linux/software/sqldeveloper/sqldeveloper_2.1.1.64.39-2_all.deb" title="Download SQL Developer 2.1 Debian Package">downloaded</a> from the <a href="http://djs-consulting.com/linux/software" title="DJS Consulting Linux Software Repository">DJS Consulting Linux Software Repository</a>.</p>
<p>I&#8217;ve used it with Sun&#8217;s Java 6 Update 18; I have not tested it with OpenJDK.  If you have problems getting it to work, you may want to check the <a href="http://djs-consulting.com/linux/blog/2008/oracle-sql-developer-debian-package" title="Oracle SQL Developer Debian Package &bull; DJS Consulting Tech Blog">previous post</a> on this topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2010/oracle-sql-developer-2-1-debian-package/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Oracle SQL Developer Debian Package</title>
		<link>http://djs-consulting.com/linux/blog/2008/oracle-sql-developer-debian-package</link>
		<comments>http://djs-consulting.com/linux/blog/2008/oracle-sql-developer-debian-package#comments</comments>
		<pubDate>Wed, 29 Oct 2008 13:17:13 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[deb]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[rpm]]></category>
		<category><![CDATA[sql developer]]></category>
		<category><![CDATA[toad]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/?p=72</guid>
		<description><![CDATA[Oracle SQL Developer is a Java-based tool that provides a graphical interface to a database.  While it&#8217;s main focus is Oracle (of course), it can be hooked up, via JDBC, to many other databases, such as MySQL, PostgreSQL, and SQL Server.  It&#8217;s similar to Toad, but is provided by Oracle at no cost.
Oracle [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.oracle.com/technology/products/database/sql_developer/index.html" title="Oracle SQL Developer &bull; Oracle">Oracle SQL Developer</a> is a Java-based tool that provides a graphical interface to a database.  While it&#8217;s main focus is Oracle (of course), it can be hooked up, via JDBC, to many other databases, such as MySQL, PostgreSQL, and SQL Server.  It&#8217;s similar to <a href="http://www.toadsoft.com/">Toad</a>, but is provided by Oracle at no cost.</p>
<p>Oracle provides SQL Developer in either an RPM, or a generic binary install.  I like the ability to manage packages, but I&#8217;ve never had much luck at getting RPM to run on Ubuntu.  I downloaded the RPM file, and, using <a href="http://kitenet.net/~joey/code/alien/">alien</a>, I converted the package to a .deb package (Debian package format) and installed it.  I worked like a charm!</p>
<p>I haven&#8217;t tested it with gcj, but using Sun&#8217;s Java 6 update 7 from the Ubuntu repositories, it ran just fine.  After you install the package, do a directory list on /usr/lib/jvm.  You&#8217;re looking for the Sun JDK &#8211; if it&#8217;s installed, you&#8217;ll have a symlink java-6-sun that points to java-6-sun-1.6.0.07.  Once you&#8217;ve determined the location of the JDK, run &#8220;sqldeveloper&#8221; from the command line &#8211; the program will prompt you for the path to your JDK.  Enter it (probably &#8220;/usr/lib/jvm/java-6-sun&#8221;) and you&#8217;re good to go.  (You have to install the package as root &#8211; but, for the rest of these steps, use your normal user, not root, as this puts settings in a .sqldeveloper directory off your home directory.)  The package installs an icon in the &#8220;Programming&#8221; or &#8220;Development&#8221; group.  Once you&#8217;ve told it where the JDK is, you can use this to launch it.</p>
<p><a href="http://www.djs-consulting.com/linux/software/sqldeveloper/sqldeveloper_1.5.54.40-2_all.deb" title="SQL Developer 1.5.1 Debian Package &bull; DJS Consulting Linux Software Repository">Download SQL Developer 1.5.1 Debian Package</a></p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2008/oracle-sql-developer-debian-package/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>A Handy PHP Backup Script</title>
		<link>http://djs-consulting.com/linux/blog/2008/a-handy-php-backup-script</link>
		<comments>http://djs-consulting.com/linux/blog/2008/a-handy-php-backup-script#comments</comments>
		<pubDate>Sat, 29 Mar 2008 05:06:03 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[pg_dump]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/2008/a-handy-php-backup-script</guid>
		<description><![CDATA[I found a script over on the Lunarpages Forums about using PHP to back up your site.  I have taken it, modified it a little, beefed up the documentation a lot, and am now posting it here.  You can download the source code for it, and it is also displayed below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
&#60;?php
/**
 * Generic [...]]]></description>
			<content:encoded><![CDATA[<p>I found a script over on the Lunarpages Forums about <a href="http://www.lunarforums.com/lunarpages_how_tos/site_and_mysql_backups_via_cron-t22118.0.html" title="Site and MySQL backups via cron - Lunarforums">using PHP to back up your site</a>.  I have taken it, modified it a little, beefed up the documentation a lot, and am now posting it here.  You can <a href="/linux/generic_backup.txt" title="Generic Backup Script">download the source code</a> for it, and it is also displayed below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
</pre></td><td class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #0000ff; font-style: italic;">/**
 * Generic Backup Script.
 * 
 * To configure this script for your purposes, just edit the parameters below.
 * Once you have the parameters set properly, when the script executes, it will
 * create an archive file, gzip it, and e-mail it to the address specified.  It
 * can be executed through cron with the command
 * 
 * php -q [name of script]
 * 
 * You are free to use this, modify it, copy it, etc.  However, neither DJS
 * Consulting nor Daniel J. Summers assume any responsibility for good or bad
 * things that happen when modifications of this script are run.
 * 
 * @author Daniel J. Summers &lt;daniel@djs-consulting.com&gt;
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// --- SCRIPT PARAMETERS ---</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- File Name --
	This is the name of the file that you're backing up, and should contain no
	slashes.  For example, if you're backing up a database, this might look
	something like...
$sFilename = &quot;backup-my_database_name-&quot; . date(&quot;Y-m-d&quot;) . &quot;.sql&quot;; */</span>
<span style="color: #000088;">$sFilename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;backup-[whatever-it-is]-&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y-m-d&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;.[extension]&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- E-mail Address --
	This is the e-mail address to which the message will be sent. */</span>
<span style="color: #000088;">$sEmailAddress</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[your e-mail address]&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- E-mail Subject --
	This is the subject that will be on the e-mail you receive. */</span>
<span style="color: #000088;">$sEmailSubject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[something meaningful]&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- E-mail Message --
	This is the text of the message that will be sent. */</span>
<span style="color: #000088;">$sMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Compressed database backup file $sFilename.gz attached.&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">/*  -- Backup Command --
	This is the command that does the work.
&nbsp;
	A note on the database commands - your setup likely requires a password
	for these commands, and they each allow you to pass a password on the
	command line.  However, this is very insecure, as anyone who runs &quot;ps&quot; can
	see your password!  For MySQL, you can create a ~/.my.cnf file - it is
	detailed at http://dev.mysql.com/doc/refman/4.1/en/password-security.html .
	For PostgreSQL, the file is ~/.pgpass, and it is detailed at
	http://www.postgresql.org/docs/8.0/interactive/libpq-pgpass.html .  Both of
	these files should be chmod-ded to 600, so that they can only be viewed by
	you, the creator.
&nbsp;
	That being said, some common commands are...
&nbsp;
- Backing Up a MySQL Database
$sBackupCommand = &quot;mysqldump -u [user_name] [db_name] &gt; $sFilename&quot;;
&nbsp;
- Backing Up a PostgreSQL Database
$sBackupCommand = &quot;pg_dump [db_name] -h localhost -U [user_name] -d -O &gt; $sFilename&quot;;
&nbsp;
- Backing Up a set of files (tar and gzip)
$sBackupCommand = &quot;tar cvf $sFilename [directory]/*&quot;;
&nbsp;
Whatever command you use, this script appends .gz to the filename after the command is executed.  */</span>
<span style="color: #000088;">$sBackupCommand</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;[a backup command]&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// --- END OF SCRIPT PARAMETERS ---</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">// Edit below at your own risk.  :)</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Do the backup.</span>
<span style="color: #000088;">$sResult</span> <span style="color: #339933;">=</span> <span style="color: #990000;">passthru</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sBackupCommand</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;; gzip $sFilename&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$sFilename</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;.gz&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Create the message.</span>
<span style="color: #000088;">$sMessage</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Compressed database backup file $sFilename attached.&quot;</span>;
<span style="color: #000088;">$sMimeBoundary</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;&lt;&lt;:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$sData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chunk_split</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sFilename</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000088;">$sHeaders</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: $sEmailAddress<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-type: multipart/mixed;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; boundary=<span style="color: #000099; font-weight: bold;">\&quot;</span>$sMimeBoundary<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #000088;">$sContent</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;This is a multi-part message in MIME format.<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;--$sMimeBoundary<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Type: text/plain; charset=<span style="color: #000099; font-weight: bold;">\&quot;</span>iso-8859-1<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Transfer-Encoding: 7bit<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #000088;">$sMessage</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;--$sMimeBoundary<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Disposition: attachment;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Type: Application/Octet-Stream; name=<span style="color: #000099; font-weight: bold;">\&quot;</span>$sFilename<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;Content-Transfer-Encoding: base64<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #000088;">$sData</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;--$sMimeBoundary<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Send the message.</span>
<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sEmailAddress</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sEmailSubject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sContent</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sHeaders</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Delete the file - we don't need it any more.</span>
<span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sFilename</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2008/a-handy-php-backup-script/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Algorithm for One-to-Many Child Table Updates</title>
		<link>http://djs-consulting.com/linux/blog/2008/algorithm-for-one-to-many-child-table-updates</link>
		<comments>http://djs-consulting.com/linux/blog/2008/algorithm-for-one-to-many-child-table-updates#comments</comments>
		<pubDate>Sat, 29 Mar 2008 03:13:21 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[many-to-one]]></category>
		<category><![CDATA[one-to-many]]></category>
		<category><![CDATA[pdo]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/2008/algorithm-for-one-to-many-child-table-updates</guid>
		<description><![CDATA[While working on the Not So Extreme Makeover: Community Edition site, I came up with an algorithm that simplifies anything else I&#8217;ve ever written to deal with this condition.  I&#8217;ll set the scenario, explain the algorithm, share how I implemented it in PHP, and provide a modification if the scenario is a bit more [...]]]></description>
			<content:encoded><![CDATA[<p>While working on the <a href="http://www.notsoextreme.org" title="Not So Extreme Makeover: Community Edition">Not So Extreme Makeover: Community Edition</a> site, I came up with an algorithm that simplifies anything else I&#8217;ve ever written to deal with this condition.  I&#8217;ll set the scenario, explain the algorithm, share how I implemented it in PHP, and provide a modification if the scenario is a bit more complicated.</p>
<p><strong>Scenario</strong> &#8211; You have two parent tables, and a child table with a many-to-one relationship with both parent tables, used to map entries in the two parent tables to each other.  For this example, we&#8217;ll use these three tables&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> volunteer <span style="color: #66cc66;">&#40;</span>
    vol_id  integer  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    vol_last_name  varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    <span style="color: #66cc66;">...</span>etc<span style="color: #66cc66;">...</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>vol_id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> r_volunteer_area <span style="color: #66cc66;">&#40;</span>
    rva_id  integer  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    rva_description  varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>rva_id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> volunteer_area <span style="color: #66cc66;">&#40;</span>
    va_volunteer_id  integer  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    va_area_id  integer  <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>va_volunteer_id<span style="color: #66cc66;">,</span> va_area_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>va_volunteer_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> volunteer <span style="color: #66cc66;">&#40;</span>vol_id<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  <span style="color: #993333; font-weight: bold;">FOREIGN</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span>va_area_id<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">REFERENCES</span> r_volunteer_area <span style="color: #66cc66;">&#40;</span>rva_id<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p><strong>Algorithm</strong> &#8211; The three-step algorithm is as follows&#8230;</p>
<ol>
<li>Create a comma-delimited string of IDs for the child table.</li>
<li>Delete the IDs from the child table that are not in the list.</li>
<li>Insert the IDs into the child table that are not there already.</li>
</ol>
<p><strong>Implementation</strong> &#8211; In PHP, if you have an array, it&#8217;s easy to come up with comma-delimited list.  To get an array of values back in a post, define your fields with &#8220;[]&#8221; after the name&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;area[]&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;chkArea1&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;chkArea1&quot;</span>&gt;</span>Do Something<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;area[]&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;chkArea7&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;7&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;chkArea7&quot;</span>&gt;</span>Do Something Else<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span></pre></td></tr></table></div>

<p>Here&#8217;s the PHP code, using <a href="http://us.php.net/pdo" title="PHP Data Objects (PDO)">PHP Data Objects (PDO)</a> as the database interface, behind a helper class that creates the statement, appends the parameters, and executes it.  <em>(The &#8220;quoting&#8221; escapes the statement to avoid potential SQL injection attacks &#8211; putting it in its own class would make the implementation here much cleaner.)</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #0000ff; font-style: italic;">/**
 * STEP 1
 *    Create a comma-delimited list of IDs.
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Quote will return the string as '2,3,4' - since we're using this</span>
<span style="color: #666666; font-style: italic;">// as an IN clause of integers, we'll strip the quotes off.</span>
<span style="color: #000088;">$sAreas</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;area&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$sAreas</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sAreas</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sAreas</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Quote the volunteer ID.</span>
<span style="color: #000088;">$iVol</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pdo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">quote</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;vol&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> PDO<span style="color: #339933;">::</span><span style="color: #004000;">PARAM_INT</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #0000ff; font-style: italic;">/**
 * STEP 2
 *    Delete the IDs that are no longer in the list.
 */</span>
<span style="color: #000088;">$dbService</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">executeCommand</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;DELETE FROM volunteer_area
    WHERE   va_volunteer_id = ?
        AND va_area_id NOT IN ($sAreas)&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iVol</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #0000ff; font-style: italic;">/**
 * STEP 3
 *    Insert the IDs that are not yet in the list.
 */</span>
<span style="color: #000088;">$dbService</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">executeCommand</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;INSERT INTO volunteer_area
        SELECT $iVol, rva_id
        FROM r_volunteer_area
        WHERE   rva_id IN ($sAreas)
            AND rva_id NOT IN
            (SELECT va_area_id
            FROM volunteer_area
            WHERE va_volunteer_id = ?)&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iVol</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p><strong>Modification</strong> &#8211; Suppose that now you accepted comments along with each of the checkboxes, so a simple two-integer insert/delete is no longer sufficient.  You would still only need to break step 3 into two steps.</p>
<ol>
<li>Get a list of IDs to update.</li>
<li>For each ID in the posted list
<ol>
<li>If the ID exists in the update list, update it.</li>
<li>Otherwise, insert it.</li>
</ol>
</li>
</ol>
<p>The implementation would then be able to use this list to make the decision without hitting the database every time.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Assume this returns an associative array of IDs.</span>
<span style="color: #000088;">$aUpdates</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dbService</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">performSelect</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;SELECT va_area_id
    FROM volunteer_area
    WHERE   va_volunteer_id = ?
        AND va_area_id IN ($sAreas)&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iVol</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;area&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$iArea</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iArea</span><span style="color: #339933;">,</span> <span style="color: #000088;">$aUpdates</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Update the table</span>
        <span style="color: #339933;">...</span>etc<span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Insert into the table</span>
        <span style="color: #339933;">...</span>etc<span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I think you&#8217;ll agree that this is much better than spinning through a loop, doing a count on each ID to see if it exists, then either doing an update or an insert based on the count.  And, while the implementation here is PHP, it could easily be implemented in any language that supports arrays and database access.</p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2008/algorithm-for-one-to-many-child-table-updates/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Transferring Data between Oracle and SQL Server</title>
		<link>http://djs-consulting.com/linux/blog/2007/transferring-data-between-oracle-and-sql-server</link>
		<comments>http://djs-consulting.com/linux/blog/2007/transferring-data-between-oracle-and-sql-server#comments</comments>
		<pubDate>Mon, 09 Jul 2007 21:23:06 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/2007/transferring-data-between-oracle-and-sql-server</guid>
		<description><![CDATA[There are lots of &#8220;how to&#8221; articles on sharing data between Oracle and SQL Server.  Most of these involve installing Oracle&#8217;s code base on the SQL Server machine, then using that instance to link tables within Oracle.  This technique does not require that, thanks to a product from Oracle called Oracle Instant Client.
To [...]]]></description>
			<content:encoded><![CDATA[<p>There are lots of &#8220;how to&#8221; articles on sharing data between Oracle and SQL Server.  Most of these involve installing Oracle&#8217;s code base on the SQL Server machine, then using that instance to link tables within Oracle.  This technique does not require that, thanks to a product from Oracle called <a href="http://www.oracle.com/technology/tech/oci/instantclient/index.html" title="Download Oracle Instant Client">Oracle Instant Client</a>.</p>
<p>To set up the Oracle piece, download the packages for &#8220;Basic&#8221; and &#8220;ODBC Supplement&#8221;, and follow the instructions for installation, on the machine with SQL Server.  (This is not an &#8220;install&#8221; per se &#8211; it&#8217;s basically an unzip.)  Next, you&#8217;ll need to provide a TNSNAMES.ORA file &#8211; this can be any valid file, including a simple shell with an &#8220;ifile=&#8221; statement pointing to a common TNSNAMES.ORA file.  Finally, set the environment variable TNS_ADMIN to point to the directory where this TNSNAMES.ORA file resides.</p>
<p>Now, you can easily create a DTS script through SQL Server to push or pull data however you&#8217;d like.  Oracle Instant Client will appear in the drop-down list of providers, and you&#8217;ll be able to specify your connection the way you normally do (i.e., &#8220;DB01.WORLD&#8221;).</p>
<p>Happy migrating!</p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2007/transferring-data-between-oracle-and-sql-server/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transferring CLOBs Across Linked Oracle Databases</title>
		<link>http://djs-consulting.com/linux/blog/2007/transferring-clobs-across-linked-oracle-databases</link>
		<comments>http://djs-consulting.com/linux/blog/2007/transferring-clobs-across-linked-oracle-databases#comments</comments>
		<pubDate>Fri, 15 Jun 2007 20:04:09 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[PL/SQL]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/2007/transferring-clobs-across-linked-oracle-databases</guid>
		<description><![CDATA[Linking databases in Oracle make it easy to share data, and can be useful for replication.  However, there is a limitation in Oracle that prevents Character Large Objects (CLOBs) from coming across these links.  The following technique uses stored procedures and a temporary table to pull CLOBs across a database link.
First, you&#8217;ll need [...]]]></description>
			<content:encoded><![CDATA[<p>Linking databases in Oracle make it easy to share data, and can be useful for replication.  However, there is a limitation in Oracle that prevents Character Large Objects (CLOBs) from coming across these links.  The following technique uses stored procedures and a temporary table to pull CLOBs across a database link.</p>
<p>First, you&#8217;ll need the temporary table, which will hold a sequence number, the primary key for the table where you&#8217;ll want to reconstruct the CLOB, and some text.  This table can reside in the source or destination database, but must be linked from the other one.  For our purposes, it looks like this&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="plsql plsql" style="font-family:monospace;"><span style="color: #00F;">CREATE</span> <span style="color: #00F;">TABLE</span> clob_xfer_area
<span style="color: #00F;">&#40;</span>
  cxa_pk      <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#40;</span><span style="color: #800;">12</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
  cxa_number  <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#40;</span><span style="color: #800;">12</span><span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
  cxa_text    <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">4000</span> byte<span style="color: #00F;">&#41;</span>
<span style="color: #00F;">&#41;</span>;
<span style="color: #00F;">ALTER</span> <span style="color: #00F;">TABLE</span> clob_xfer_area add
<span style="color: #00F;">&#40;</span>
  constraint pk_cxa_id
    primary key <span style="color: #00F;">&#40;</span>cxa_pk<span style="color: #00F;">,</span> cxa_number<span style="color: #00F;">&#41;</span>
<span style="color: #00F;">&#41;</span>;</pre></td></tr></table></div>

<p>Second, you&#8217;ll need the procedure in the source database that breaks the CLOB apart and populates the temporary table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="plsql plsql" style="font-family:monospace;"><span style="color: #00F;">SET</span> serveroutput <span style="color: #00F;">ON</span> size <span style="color: #800;">1000000</span>
<span style="color: #00F;">SET</span> lines <span style="color: #800;">1000</span>
<span style="color: #00F;">SET</span> pages 0
<span style="color: #00F;">SET</span> tab off
<span style="color: #00F;">SET</span> feedback <span style="color: #00F;">ON</span>
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span>
<span style="color: #00F;">PROCEDURE</span> break_clobs_apart
<span style="color: #00F;">IS</span>
&nbsp;
  v_line_number   <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#40;</span><span style="color: #800;">3</span><span style="color: #00F;">&#41;</span>;
  v_text_piece    <span style="color: #00F;">VARCHAR2</span><span style="color: #00F;">&#40;</span><span style="color: #800;">4000</span><span style="color: #00F;">&#41;</span>;
  v_total_length  <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#40;</span><span style="color: #800;">12</span><span style="color: #00F;">&#41;</span>;
&nbsp;
  <span style="color: #00F;">CURSOR</span> clob_cur <span style="color: #00F;">IS</span>
    <span style="color: #00F;">SELECT</span> twc_pk<span style="color: #00F;">,</span> twc_clob_field
    <span style="color: #00F;">FROM</span>   table_with_clob;
&nbsp;
<span style="color: #00F;">BEGIN</span> <span style="color: #080; font-style: italic;">/* { */</span>
&nbsp;
  <span style="color: #00F;">FOR</span> clob_rec <span style="color: #00F;">IN</span> clob_cur <span style="color: #00F;">LOOP</span> <span style="color: #080; font-style: italic;">/* { */</span>
&nbsp;
    v_total_length <span style="color: #00F;">:=</span> <span style="color: #800;">1</span>;
    v_line_number  <span style="color: #00F;">:=</span> 0;
&nbsp;
    <span style="color: #00F;">WHILE</span> <span style="color: #00F;">&#40;</span>v_total_length <span style="color: #00F;">&lt;=</span>
           <span style="color: #00F;">DBMS_LOB</span><span style="color: #00F;">.</span>GETLENGTH<span style="color: #00F;">&#40;</span>clob_rec<span style="color: #00F;">.</span>twc_clob_field<span style="color: #00F;">&#41;</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">LOOP</span> <span style="color: #080; font-style: italic;">/* { */</span>
&nbsp;
      v_line_number <span style="color: #00F;">:=</span> v_line_number <span style="color: #00F;">+</span> <span style="color: #800;">1</span>;
      v_text_piece <span style="color: #00F;">:=</span> <span style="color: #00F;">DBMS_LOB</span><span style="color: #00F;">.</span><span style="color: #000;">SUBSTR</span><span style="color: #00F;">&#40;</span>clob_rec<span style="color: #00F;">.</span>twc_clob_field<span style="color: #00F;">,</span>
        <span style="color: #800;">3999</span><span style="color: #00F;">,</span> v_total_length<span style="color: #00F;">&#41;</span>;
      v_total_length <span style="color: #00F;">:=</span> v_total_length <span style="color: #00F;">+</span> <span style="color: #800;">3999</span>;
&nbsp;
      <span style="color: #00F;">INSERT</span> <span style="color: #00F;">INTO</span> clob_xfer_area <span style="color: #00F;">&#40;</span>
        cxa_pk<span style="color: #00F;">,</span>
        cxa_number<span style="color: #00F;">,</span>
        cxa_text
      <span style="color: #00F;">&#41;</span>
        <span style="color: #00F;">VALUES</span> <span style="color: #00F;">&#40;</span>
          clob_rec<span style="color: #00F;">.</span>twc_pk<span style="color: #00F;">,</span> <span style="color: #080; font-style: italic;">-- cxa_pk</span>
          v_line_number<span style="color: #00F;">,</span>   <span style="color: #080; font-style: italic;">-- cxa_number</span>
          v_text_piece     <span style="color: #080; font-style: italic;">-- cxa_text</span>
        <span style="color: #00F;">&#41;</span>;
&nbsp;
    <span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span>; <span style="color: #080; font-style: italic;">/* } of while */</span>
&nbsp;
  <span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span>; <span style="color: #080; font-style: italic;">/* } of clob_cur */</span>
&nbsp;
<span style="color: #00F;">END</span>; <span style="color: #080; font-style: italic;">/* } of procedure break_clobs_apart */</span></pre></td></tr></table></div>

<p>Third, you&#8217;ll need a procedure in the destination database that puts the CLOB back together, and deletes the data from the temporary table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="plsql plsql" style="font-family:monospace;"><span style="color: #00F;">SET</span> serveroutput <span style="color: #00F;">ON</span> size <span style="color: #800;">1000000</span>
<span style="color: #00F;">SET</span> lines <span style="color: #800;">1000</span>
<span style="color: #00F;">SET</span> pages 0
<span style="color: #00F;">SET</span> feedback <span style="color: #00F;">ON</span>
<span style="color: #00F;">SET</span> tab off
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span>
<span style="color: #00F;">PROCEDURE</span> put_clobs_together
<span style="color: #00F;">IS</span>
  v_new_clob   clob;
&nbsp;
  <span style="color: #00F;">CURSOR</span> pk_cur <span style="color: #00F;">IS</span>
    <span style="color: #00F;">SELECT</span> <span style="color: #00F;">DISTINCT</span> cxa_pk
    <span style="color: #00F;">FROM</span>   clob_xfer_area;
&nbsp;
  <span style="color: #00F;">CURSOR</span> piece_cur<span style="color: #00F;">&#40;</span>p_cxa_pk <span style="color: #00F;">NUMBER</span><span style="color: #00F;">&#41;</span> <span style="color: #00F;">IS</span>
    <span style="color: #00F;">SELECT</span> cxa_text
    <span style="color: #00F;">FROM</span>   clob_xfer_area
    <span style="color: #00F;">WHERE</span>  cxa_pk <span style="color: #00F;">=</span> p_cxa_pk
    <span style="color: #00F;">ORDER</span> <span style="color: #00F;">BY</span> cxa_number;
&nbsp;
<span style="color: #00F;">BEGIN</span> <span style="color: #080; font-style: italic;">/* { */</span>
&nbsp;
  <span style="color: #00F;">FOR</span> pk_rec <span style="color: #00F;">IN</span> pk_cur <span style="color: #00F;">LOOP</span> <span style="color: #080; font-style: italic;">/* { */</span>
&nbsp;
    <span style="color: #00F;">DBMS_LOB</span><span style="color: #00F;">.</span>CREATETEMPORARY<span style="color: #00F;">&#40;</span>v_new_clob<span style="color: #00F;">,</span> <span style="color: #00F;">TRUE</span><span style="color: #00F;">&#41;</span>;
    <span style="color: #00F;">DBMS_LOB</span><span style="color: #00F;">.</span><span style="color: #00F;">OPEN</span><span style="color: #00F;">&#40;</span>v_new_clob<span style="color: #00F;">,</span> <span style="color: #00F;">DBMS_LOB</span><span style="color: #00F;">.</span>LOB_READWRITE<span style="color: #00F;">&#41;</span>;
&nbsp;
    <span style="color: #00F;">FOR</span> piece_rec <span style="color: #00F;">IN</span> piece_cur<span style="color: #00F;">&#40;</span>pk_rec<span style="color: #00F;">.</span>cxa_pk<span style="color: #00F;">&#41;</span> <span style="color: #00F;">LOOP</span> <span style="color: #080; font-style: italic;">/* { */</span>
&nbsp;
      <span style="color: #00F;">DBMS_LOB</span><span style="color: #00F;">.</span>WRITEAPPEND<span style="color: #00F;">&#40;</span>v_new_clob<span style="color: #00F;">,</span> <span style="color: #000;">LENGTH</span><span style="color: #00F;">&#40;</span>piece_rec<span style="color: #00F;">.</span>cxa_text<span style="color: #00F;">&#41;</span><span style="color: #00F;">,</span>
        piece_rec<span style="color: #00F;">.</span>cxa_text<span style="color: #00F;">&#41;</span>;
&nbsp;
    <span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span>;  <span style="color: #080; font-style: italic;">/* } of piece_cur */</span>
&nbsp;
    <span style="color: #00F;">DBMS_LOB</span><span style="color: #00F;">.</span><span style="color: #00F;">CLOSE</span><span style="color: #00F;">&#40;</span>v_new_clob<span style="color: #00F;">&#41;</span>;
&nbsp;
    <span style="color: #00F;">UPDATE</span> dest_table_with_clob
      <span style="color: #00F;">SET</span>  migrated_clob <span style="color: #00F;">=</span> v_new_clob
      <span style="color: #00F;">WHERE</span> dtwc_pk <span style="color: #00F;">=</span> pk_rec<span style="color: #00F;">.</span>cxa_pk;
&nbsp;
  <span style="color: #00F;">END</span> <span style="color: #00F;">LOOP</span>; <span style="color: #080; font-style: italic;">/* } of pk_cur */</span>
&nbsp;
  <span style="color: #00F;">DELETE</span> <span style="color: #00F;">FROM</span> clob_xfer_area;
&nbsp;
<span style="color: #00F;">END</span>; <span style="color: #080; font-style: italic;">/* } of procedure put_clobs_together */</span></pre></td></tr></table></div>

<p>Finally, you&#8217;ll need a procedure that controls the whole thing.  We&#8217;ll assume that this procedure is loaded in the destination database, and the source database is linked with the name &#8220;source&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="plsql plsql" style="font-family:monospace;"><span style="color: #00F;">SET</span> lines <span style="color: #800;">1000</span>
<span style="color: #00F;">SET</span> pages 0
<span style="color: #00F;">SET</span> feedback <span style="color: #00F;">ON</span>
<span style="color: #00F;">SET</span> tab off
&nbsp;
<span style="color: #00F;">CREATE</span> <span style="color: #00F;">OR</span> <span style="color: #000;">REPLACE</span>
<span style="color: #00F;">PROCEDURE</span> xfer_clobs
<span style="color: #00F;">IS</span>
&nbsp;
<span style="color: #00F;">BEGIN</span> <span style="color: #080; font-style: italic;">/* { */</span>
&nbsp;
  break_clobs_apart<span style="color: #00F;">@</span>source;
  put_clobs_together;
&nbsp;
<span style="color: #00F;">END</span>; <span style="color: #080; font-style: italic;">/* } */</span></pre></td></tr></table></div>

<p>(This does not include a commit &#8211; the changes will not be persistent unless they are committed.)</p>
<p>Of course, these processes could (and, to be useful, likely would) be integrated into other procedures and scripts.  But, this framework will successfully transfer CLOBs across linked databases in Oracle.</p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2007/transferring-clobs-across-linked-oracle-databases/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache and MySQL Are Back</title>
		<link>http://djs-consulting.com/linux/blog/2004/apache-and-mysql-are-back</link>
		<comments>http://djs-consulting.com/linux/blog/2004/apache-and-mysql-are-back#comments</comments>
		<pubDate>Wed, 08 Sep 2004 06:00:55 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Internet Apps]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/2004/apache-and-mysql-are-back</guid>
		<description><![CDATA[I was finally able to resolve my problems with Apache and MySQL.  When I decided to mount my FAT32 drive under /home/summersd, I inadvertently caused myself some problems.  From talking to a Linux guy at work, I found that no processes that weren&#8217;t running under my user ID could access those files.  [...]]]></description>
			<content:encoded><![CDATA[<p>I was finally able to resolve my problems with Apache and MySQL.  When I decided to mount my FAT32 drive under /home/summersd, I inadvertently caused myself some problems.  From talking to a Linux guy at work, I found that no processes that weren&#8217;t running under my user ID could access those files.  The reason is that Linux looks up the entire diretory tree, back to /, to determine if you can access the file.  So, although I had &#8220;-rwxrwxrwx summersd summersd&#8221; on every file, /home/summersd was &#8220;drwx&#8212;&#8212; summersd summersd&#8221;, and /home was &#8220;drwxr-xr-x&#8221;.  The permissions on /home/summersd was keeping Apache from seeing /home/summersd/drive_d/wwwroot, and MySQL from seeing or writing to /home/summersd/drive_d/mysql/data.  I moved the drive to /mnt/drive_d, with the mount point being owned by &#8220;root&#8221;, still mounting the drive with my user name, and everything worked.</p>
<p>In the process of reconfiguring Thunderbird, I believe I may have found out how to share the address book across operating systems.  The file ~/.thunderbird/default.[something]/prefs.js has a listing of all the preferences and settings.  I modified this file to change the location of my mail files, and there is a setting there for an address book (which isn&#8217;t shown in the configuration dialog &#8211; after all, it is 0.7.3&#8230;)  I&#8217;ll play with that later &#8211; right now I&#8217;m just elated to have Apache and MySQL working again.</p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2004/apache-and-mysql-are-back/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Success with Wine &amp; Diagnostics</title>
		<link>http://djs-consulting.com/linux/blog/2004/success-with-wine-diagnostics</link>
		<comments>http://djs-consulting.com/linux/blog/2004/success-with-wine-diagnostics#comments</comments>
		<pubDate>Sun, 05 Sep 2004 06:00:57 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Wine]]></category>
		<category><![CDATA[Wireless Support]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/2004/success-with-wine-diagnostics</guid>
		<description><![CDATA[At work, we use an editor called Visual SlickEdit (VSlick).  It&#8217;s got a lot of features, and supports color-coding for many different languages.  I decided that I&#8217;d give wine another shot, as we only have the Windows version of this program.  I installed wine and winesetuptk, used winesetuptk to configure the installation, [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we use an editor called <a href="http://www.slickedit.com/">Visual SlickEdit</a> (VSlick).  It&#8217;s got a lot of features, and supports color-coding for many different languages.  I decided that I&#8217;d give wine another shot, as we only have the Windows version of this program.  I installed wine and winesetuptk, used winesetuptk to configure the installation, then ran the installation program.  Everything installed, and the program ran up to a point, when it started complaining about a missing DLL.  I booted to WXP, found the DLL, copied it to the FAT32 drive, rebooted to Linux, and copied the DLL into the &#8220;fake windows&#8221; system directory.  Soon, it was working great!  I can&#8217;t believe it &#8211; success with wine!</p>
<p>I also have made little headway towards getting Apache and MySQL to working.  I changed the process that Apache uses to run as &#8220;summersd&#8221;, and I was able to see pages (although any pages that relied on a database didn&#8217;t work).  I still haven&#8217;t figured this one out yet&#8230;</p>
<p>I&#8217;m still getting kernel panics from time to time, and it seems to be whenever I access networking.  A suggestion from one of the folks on the WBEL users list was to download the <a href="http://www.ultimatebootcd.com/">Ultimate Boot CD</a>, filled with diagnostic programs.  I downloaded it, burned it, and ran some memory checks.  Those checked out, so I&#8217;m going to run a &#8220;CPU Burn-In&#8221; program to see if it can detect errors from the CPU.  It runs for up to 7 days, but I think I&#8217;ll just run it overnight &#8211;            folding@home didn&#8217;t take nearly that long to crash it before.</p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2004/success-with-wine-diagnostics/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back to WBEL</title>
		<link>http://djs-consulting.com/linux/blog/2004/back-to-wbel</link>
		<comments>http://djs-consulting.com/linux/blog/2004/back-to-wbel#comments</comments>
		<pubDate>Sat, 04 Sep 2004 06:00:24 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Internet Apps]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Office Productivity]]></category>
		<category><![CDATA[White Box]]></category>
		<category><![CDATA[Wireless Support]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/2004/back-to-wbel</guid>
		<description><![CDATA[Today, I reinstalled WBEL 3.0.  I was able to compile ndiswrapper (as I kept that on my FAT32             drive), and get the network card working smoothly very quickly.  (In fact, it seems to be more reliable under       [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I reinstalled WBEL 3.0.  I was able to compile ndiswrapper (as I kept that on my FAT32             drive), and get the network card working smoothly very quickly.  (In fact, it seems to be more reliable under             Linux than WXP!)  With the network up, it was easy to download Firefox, Thunderbird, and OpenOffice, and installing             them was a breeze.  (I decided to put them under /opt this time, trying to stick with the FHS.)  I decided             to mount my FAT32 drive under my home directory, as /home/summersd/drive_d.  E-mail works fine, but Apache gives             me a 403 (Permission Denied) error.  MySQL doesn&#8217;t seem to be working either &#8211; I&#8217;ll have to play with that             later.</p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2004/back-to-wbel/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Month in Summary</title>
		<link>http://djs-consulting.com/linux/blog/2004/a-month-in-summary</link>
		<comments>http://djs-consulting.com/linux/blog/2004/a-month-in-summary#comments</comments>
		<pubDate>Tue, 31 Aug 2004 06:00:44 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Audio / Video]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[Internet Apps]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Red Hat / Fedora]]></category>
		<category><![CDATA[White Box]]></category>
		<category><![CDATA[Wireless Support]]></category>

		<guid isPermaLink="false">http://www.djs-consulting.com/linux/blog/2004/a-month-in-summary</guid>
		<description><![CDATA[Well, the last month has been interesting.  I was able to get my Windows and Linux installations synchronized by creating a mount point for my second drive under /mnt/drive_d .  Under that, I created a directory called /thunderbird for my e-mail, and moved my e-mail and newsgroup folders over there.  (The first [...]]]></description>
			<content:encoded><![CDATA[<p>Well, the last month has been interesting.  I was able to get my Windows and Linux installations synchronized by creating a mount point for my second drive under /mnt/drive_d .  Under that, I created a directory called /thunderbird for my e-mail, and moved my e-mail and newsgroup folders over there.  (The first time, I missed the &#8220;newsrc&#8221; file, which is important &#8211; it tells what newsgroups you&#8217;ve subscribed to and which messages you&#8217;ve read.)  Under Windows, I pointed it to &#8220;D:\thunderbird\pop3.knology.net&#8221;, and under Linux, it was configured to &#8220;/mnt/drive_d/thunderbird/pop3.knology.net&#8221;.  I then moved the &#8220;wwwroot&#8221; directory from &#8220;C:\Inetpub&#8221; to drive D:, and pointed IIS to the new location.  Under Linux, I did something a little different.  As &#8220;root&#8221;, I deleted the directory /var/www/html, and instead created /var/www/html as a symbolic link to /mnt/drive_d/wwwroot (the actual command is &#8220;ln -s /mnt/drive_d/wwwroot /var/www/html&#8221;).  That worked great as well.</p>
<p>MySQL was more complicated, but I was eventually able to get it working as well.  I created the directory             &#8220;D:\mysql\data&#8221; for the data, then configured /etc/my.cnf under Linux to look at &#8220;/mnt/drive_d/mysql/data&#8221;.  I kept             getting &#8220;Could not connect to server using socket /var/lib/mysql/mysql.sock&#8221;.  After some digging, it appeared to be a permissions problem.  All the documentation said that the default socket was /tmp/mysql.sock, so I changed my.cnf to point there instead, restarted mysqld, and it worked!  So, I have no idea what a Unix socket it, but I know that now I have one!  <img src='http://djs-consulting.com/linux/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I was also able to get DVDs playing using xine, compiling it myself, and using <a href="http://developers.videolan.org/libdvdcss/">libdvdcss</a>, I can even watch commercial DVDs.  I&#8217;m really impressed with xine &#8211; it handles all kinds of media out of the box, including DivX and up to version 8 of WMV files.  You can add codecs to it as well, to support almost anything you want to do from an audio or video perspective.  Compiling the player took around 20 minutes, and compiling the front end took another 5.  And, it was simple &#8211; download the .tar.gz file, do &#8220;tar xvfz [name].tar.gz&#8221;, &#8220;cd [name]&#8220;, &#8220;./configure&#8221;, &#8220;make install&#8221;.  The &#8220;./configure&#8221; script is the key in the whole process &#8211; it looks at what you have installed, and creates make files that will work with your compiler.</p>
<p>Everything started going south, though, when I started having freezes.  Eventually, I got to where I could not boot without a kernel panic, and then boot errors (which I detailed in <a href="http://beau.org/pipermail/whitebox-users/2004-August/003197.html">this e-mail to the WBEL user&#8217;s list</a>.  Encouraged by my success over the past month, I decided to return to WBEL &#8211; it&#8217;s supposed to be more stable than FC2, and I bet that I can get ndiswrapper, the dual-booting web server, the common e-mail, and maybe even some other stuff working again.</p>
]]></content:encoded>
			<wfw:commentRss>http://djs-consulting.com/linux/blog/2004/a-month-in-summary/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
