<?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>RBDevZone &#187; Databases</title>
	<atom:link href="http://www.rbdevzone.com/category/databases/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rbdevzone.com</link>
	<description>The REALbasic Resource</description>
	<lastBuildDate>Tue, 31 Aug 2010 19:55:19 +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>SQLite Migrator 1.3.0 Now Available</title>
		<link>http://www.rbdevzone.com/2010/02/sqlite-migrator-1-3-0-now-available/</link>
		<comments>http://www.rbdevzone.com/2010/02/sqlite-migrator-1-3-0-now-available/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 15:19:28 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/?p=366</guid>
		<description><![CDATA[Quick and easily migrate your data from any database to SQLite.
Press Release
SQLite Migrator Web Site
]]></description>
			<content:encoded><![CDATA[<p>Quick and easily migrate your data from any database to SQLite.</p>
<p><a href="http://prmac.com/release-id-10756.htm">Press Release</a></p>
<p><a href="http://www.logicalvue.com/sqlite/sqlite.html">SQLite Migrator Web Site</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2010/02/sqlite-migrator-1-3-0-now-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLite Manager on Sale</title>
		<link>http://www.rbdevzone.com/2009/09/sqlite-manager-on-sale/</link>
		<comments>http://www.rbdevzone.com/2009/09/sqlite-manager-on-sale/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 15:25:35 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[news]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/?p=278</guid>
		<description><![CDATA[For those of you that use SQLite (REALSQLDatabase) with REALbasic, you might be interested to know that SQLite Manager (from SQLabs) is on sale at MacZot today for only $24 (half price)!
]]></description>
			<content:encoded><![CDATA[<p>For those of you that use SQLite (REALSQLDatabase) with REALbasic, you might be interested to know that SQLite Manager (from <a href="http://sqlabs.net">SQLabs</a>) is on <a href="http://maczot.com/discuss/?p=1512">sale at MacZot today for only $24</a> (half price)!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2009/09/sqlite-manager-on-sale/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REALbasic Reporting Tools</title>
		<link>http://www.rbdevzone.com/2009/06/realbasic-reporting-tools/</link>
		<comments>http://www.rbdevzone.com/2009/06/realbasic-reporting-tools/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 17:43:46 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Reports]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/?p=264</guid>
		<description><![CDATA[Reporting Tools that work with REALbasic remain a hot topic, so I thought it would be worth a brief post to list the options that are currently available.
On-Target Reports: $200
The oldest and most mature of the reporting solutions.  It is a set of encrypted REALbasic classes that you drop in your project.  A [...]]]></description>
			<content:encoded><![CDATA[<p>Reporting Tools that work with REALbasic remain a hot topic, so I thought it would be worth a brief post to list the options that are currently available.</p>
<h3><a href="http://ontargetreports.com/">On-Target Reports</a>: $200</h3>
<p>The oldest and most mature of the reporting solutions.  It is a set of encrypted REALbasic classes that you drop in your project.  A report designer is also included.</p>
<h3><a href="http://www.redcort.com/rb/">Report Framework</a>: Free</h3>
<p>These open-source classes were originally developed by Keith DeLong of RedCort software.  They do a good job of abstracting out the hard stuff, but there is not a lot of functionality.  It might be useful for some simple reporting, however.</p>
<h3><a href="http://valentina-db.com/">Valentina Reports</a>: $400</h3>
<p>Introduced in early 2009, this reporting tool only works the Valentina Database.  It includes a very slick report designer.</p>
<h3><a href="http://www.rothsoft.ch/realbasic/rsreport/">RSReport</a>: $86</h3>
<p>Introduced in late 2008, this reporting tool is a set of encrypted REALbasic classes.  It doesn&#8217;t include a report designer, so you&#8217;ll be creating all your reports in REALbasic code.  It has a decent amount of features and is updated regularly, but documentation is only in German.</p>
<h3><a href="http://www.einhugur.com/EinhugurReports/">Einhugur Reports</a>: $200</h3>
<p>Included as part of the Einhugur tools suite, but pricing has not yet been finalized as it is still in early alpha stages.</p>
<h3><a href="http://www.turboreport.com/">TurboReport</a>: $Price not set</h3>
<p>Also still in development stages, but looks to have some nice features.</p>
<p><strong>Update (Jun 5, 2009):</strong></p>
<h3><a href="http://code.google.com/p/rbrw-core/">rbrw-core</a></h3>
<p>A REALbasic report writer based on OOFILE.</p>
<p>And lastly, REAL Software announced in their June newsletter that they are working on a reporting component that will be part of the IDE itself.</p>
<p><a href="http://www.realsoftware.com/emails/newsletter/0906/images/report_editor.png"><img src="http://www.rbdevzone.com/wp-content/uploads/2009/06/e534c6d7-ca8f-464d-9227-d069ad4d2d92.jpg" border="0" alt="E534C6D7-CA8F-464D-9227-D069AD4D2D92.jpg" width="350" height="266" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2009/06/realbasic-reporting-tools/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>New: SQLite Migrator 1.3.0</title>
		<link>http://www.rbdevzone.com/2009/02/sqlite-migrator/</link>
		<comments>http://www.rbdevzone.com/2009/02/sqlite-migrator/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 16:44:03 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/?p=204</guid>
		<description><![CDATA[If you use REALbasic&#8217;s built-in database engine, then you may find SQLite Migrator useful.  It allows you to migrate any database that you can connect to using ODBC to SQLite/REALSQLDatabase.
It works great with Access, FoxPro, MySQL and just about any database you might be using.
Check it out here:
SQLite Migrator
]]></description>
			<content:encoded><![CDATA[<p>If you use REALbasic&#8217;s built-in database engine, then you may find <a href="http://www.logicalvue.com/sqlite/sqlite.html">SQLite Migrator</a> useful.  It allows you to migrate any database that you can connect to using ODBC to SQLite/REALSQLDatabase.</p>
<p>It works great with Access, FoxPro, MySQL and just about any database you might be using.</p>
<p><span id="more-204"></span>Check it out here:</p>
<p><a href="http://www.logicalvue.com/sqlite/sqlite.html">SQLite Migrator</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2009/02/sqlite-migrator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting with SQLite (aka REALSQLDatabase)</title>
		<link>http://www.rbdevzone.com/2009/01/starting-with-sqlite-aka-realsqldatabase/</link>
		<comments>http://www.rbdevzone.com/2009/01/starting-with-sqlite-aka-realsqldatabase/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 02:41:38 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/?p=167</guid>
		<description><![CDATA[This article originally appeared in REALbasic Developer Magazine 4.4 (Mar/Apr 2006)
REAL SQL Database (REALSQL) is the single-user database engine included with REALbasic.  It is based on SQLite 3 (http://www.sqlite.org), a fast and powerful embedded open-source database engine.
REALSQL supports all the SQL commands that SQLite supports:



Category
SQLite Command


Tables
ALTER TABLE


 
CREATE TABLE


 
DROP TABLE


Data
INSERT


 
SELECT


 
UPDATE


 
DELETE


 
REPLACE


Indexing
CREATE INDEX


 
DROP INDEX


 
ANALYZE


 
REINDEX


Triggers
CREATE TRIGGER


 
DROP TRIGGER


Transactions
BEGIN TRANSACTION


 
COMMIT


 
ROLLBACK


Administration
ATTACH [...]]]></description>
			<content:encoded><![CDATA[<p><cite>This article originally appeared in REALbasic Developer Magazine 4.4 (Mar/Apr 2006)</cite></p>
<p>REAL SQL Database (REALSQL) is the single-user database engine included with REALbasic.  It is based on SQLite 3 (http://www.sqlite.org), a fast and powerful embedded open-source database engine.</p>
<p>REALSQL supports all the SQL commands that SQLite supports:</p>
<table border="1">
<tbody>
<tr>
<th>Category</th>
<th>SQLite Command</th>
</tr>
<tr>
<td>Tables</td>
<td>ALTER TABLE</td>
</tr>
<tr>
<td> </td>
<td>CREATE TABLE</td>
</tr>
<tr>
<td> </td>
<td>DROP TABLE</td>
</tr>
<tr>
<td>Data</td>
<td>INSERT</td>
</tr>
<tr>
<td> </td>
<td>SELECT</td>
</tr>
<tr>
<td> </td>
<td>UPDATE</td>
</tr>
<tr>
<td> </td>
<td>DELETE</td>
</tr>
<tr>
<td> </td>
<td>REPLACE</td>
</tr>
<tr>
<td>Indexing</td>
<td>CREATE INDEX</td>
</tr>
<tr>
<td> </td>
<td>DROP INDEX</td>
</tr>
<tr>
<td> </td>
<td>ANALYZE</td>
</tr>
<tr>
<td> </td>
<td>REINDEX</td>
</tr>
<tr>
<td>Triggers</td>
<td>CREATE TRIGGER</td>
</tr>
<tr>
<td> </td>
<td>DROP TRIGGER</td>
</tr>
<tr>
<td>Transactions</td>
<td>BEGIN TRANSACTION</td>
</tr>
<tr>
<td> </td>
<td>COMMIT</td>
</tr>
<tr>
<td> </td>
<td>ROLLBACK</td>
</tr>
<tr>
<td>Administration</td>
<td>ATTACH DATABASE</td>
</tr>
<tr>
<td> </td>
<td>DETACH DATABASE</td>
</tr>
<tr>
<td> </td>
<td>VACUUM</td>
</tr>
<tr>
<td>Advanced</td>
<td>ON CONFLICT</td>
</tr>
<tr>
<td> </td>
<td>PRAGMA</td>
</tr>
</tbody>
</table>
<p>In order to start working with any of these exciting SQLite commands, you need to create a REALSQL database.  This is not hard at all as we&#8217;ll see with some sample code.  All access to REALSQL databases is coincidentally done through the REALSQLDatabase class.  Once we have an instance of that class, we can assign it to a folder item and choose to create a new database.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Dim</span> testDb <span style="color: #000080;">As</span> <span style="color: #000080;">New</span> REALSQLDatabase
<span style="color: #000080;">Dim</span> testDbFile <span style="color: #000080;">As</span> <span style="color: #000080;">New</span> FolderItem(<span style="color: #800000;">&quot;TestDb.rsd&quot;</span>)
&nbsp;
testDb.DatabaseFile = testDbFile
&nbsp;
<span style="color: #000080;">If</span> testDb.CreateDatabaseFile <span style="color: #000080;">Then</span>
	// Database <span style="color: #000080;">is</span> now available <span style="color: #000080;">for</span> use
<span style="color: #000080;">Else</span>
	MessageBox(<span style="color: #800000;">&quot;Unable to create the database.&quot;</span>)
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span></pre></div></div>

<p>We can now use testDb to execute SQLite commands.  For example to create a simple table, we would use this command:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> simple <span style="color: #66cc66;">&#40;</span> firstName TEXT<span style="color: #66cc66;">,</span> lastName TEXT<span style="color: #66cc66;">,</span> age INTEGER <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This REALbasic code will send the above command to our database:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Dim</span> result <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
result = testDb.SQLExecute(<span style="color: #800000;">&quot;CREATE TABLE simple ( firstName TEXT, lastName TEXT, age INTEGER );&quot;</span>)</pre></div></div>

<p>Now we are ready to start talking about the Table commands.  The three table-related commands (ALTER TABLE, CREATE TABLE and DROP TABLE) do what their names suggest: create new tables, alter (or change) existing tables, and drop (delete) existing tables.</p>
<h2>Creating Tables</h2>
<p>As we briefly saw above, the CREATE TABLE command is the first one you would need to use after creating the database.  After all, a database without any tables is not of much use!  If you go to the official SQLite documentation page for CREATE TABLE (http://sqlite.org/lang_createtable.html), you&#8217;ll see great detail about what this command can do for you.  We&#8217;ll try to focus on a few practical examples here.</p>
<p>All tables contain a unique primary key (_rowid), but you should really create your own unique key as well.  Although these _rowid values are unique, they can change when rows are deleted.  If you rely on them as your only key, you&#8217;ll be in big trouble if you try to use them as foreign keys! These primary keys are stored in 64-bit integers, so the sun will go cold before you would run out of key values.  Use the type of INTEGER PRIMARY KEY to create your primary key.</p>
<p>Columns can be either NULL or NOT NULL.  NOT NULL columns must have a value.  Columns can also have defaults which are automatically assigned to the column when a row is created and no other value is specified.</p>
<p>Let&#8217;s create a table to store URLs for a fictional bookmark database (refer to the sidebar for information on SQLite data types):</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> bookmark <span style="color: #66cc66;">&#40;</span>ID INTEGER <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span> URL TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> Description TEXT<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>SQLite also has the ability to create temporary tables.  As the name suggests, temporary tables are not permanent and will only be available for the while you are connected to the database; once the connection is closed, the table disappears.</p>
<h2>Changing a Table</h2>
<p>SQLite provides some basic ways to change a table after you have created it.  Specifically, you are allowed to rename the table or to add new columns to the table.  SQLite does not yet provide a way to remove a column from a table.  Renaming a table is not something you will likely do often, but adding new columns is something that is quite useful.</p>
<p>Keep in mind that if you want to add a NOT NULL column to a table, then you&#8217;ll also need to provide a non-NULL default value.</p>
<p>// Rename the table</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> bookmark <span style="color: #993333; font-weight: bold;">RENAME</span> <span style="color: #993333; font-weight: bold;">TO</span> bookmarks</pre></div></div>

<p>// Add a column to track how often the URL is visted, defaulting to 0</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> bookmarks <span style="color: #993333; font-weight: bold;">ADD</span> Visits INTEGER <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #cc66cc;">0</span></pre></div></div>

<h2>Removing a Table</h2>
<p>In SQL-speak, the word DROP is used as a synonymn for remove.  The DROP TABLE command is not one you should use often or lightly.  Dropping a table throws all the data in the table away.  You will not be able to get the data back.  The syntax is quite simple:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> bookmarks</pre></div></div>

<p>Note that dropping a table does not actually reduce the size of your database file.  SQLite retains the space so that it can be used later by other tables as they grow.  Consider this a teaser for a future column: the VACUUM command can be used to reclaim unused space.</p>
<p>In our next column we&#8217;ll look at the commands for adding and manipulating data in tables.</p>
<h2>A Note About Data Types</h2>
<p>SQLite works with datatypes quite differently than you might expect.  Enough so that it is worth taking a little time to explain it.  To be brief, the datatypes in SQLite are really more like guidelines.  The SQLite documentation refers to them as &#8220;affinities&#8221;.  Regardless of the type that you specify, a column can store any type of information.  If you have a column with an INTEGER type and you try to assign it &#8216;REALbasic&#8217;, SQLite will simply store &#8216;REALbasic&#8217; in the column.</p>
<p>As far as I know, SQLite is the only database that works this way.  None of this is a huge problem, it&#8217;s just a bit odd.  This does mean you need to be careful when attempting to do math on columns that you think might contain numbers.</p>
<p>The types available to you are TEXT, NUMERIC, INTEGER, and BLOB.  For more information, visit the <a href="http://www.sqlite.org">SQLite web site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2009/01/starting-with-sqlite-aka-realsqldatabase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Stored Procedure Examples</title>
		<link>http://www.rbdevzone.com/2008/12/some-stored-procedure-examples/</link>
		<comments>http://www.rbdevzone.com/2008/12/some-stored-procedure-examples/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 02:10:38 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/?p=162</guid>
		<description><![CDATA[This article originally appeared in REALbasic Developer Magazine 4.3 (Jan/Feb 2006)
Now that we know what stored procedures are, let&#8217;s take a look at a few more examples.  The accompanying Code Listing shows a simple stored procedure for MySQL, PostgreSQL, OpenBase, FrontBase, SQL Server and Oracle.  As mentioned last time, the various syntax is [...]]]></description>
			<content:encoded><![CDATA[<p><cite>This article originally appeared in REALbasic Developer Magazine 4.3 (Jan/Feb 2006)</cite></p>
<p>Now that we know what stored procedures are, let&#8217;s take a look at a few more examples.  The accompanying Code Listing shows a simple stored procedure for MySQL, PostgreSQL, OpenBase, FrontBase, SQL Server and Oracle.  As mentioned last time, the various syntax is similar but also just different enough to be annoying.</p>
<h2>How is this related to REALbasic?</h2>
<p>REALbasic does not provide a built-in way to call stored procedures, and it provides a nice set of database classes that work with a wide variety of databases.  I guess you could say that REALbasic is encouraging you not to use stored procedures at all.  That&#8217;s not entirely true, but most languages do make it a bit easier to work with them.  For example, with VB.NET and ADO.NET you can use the ExecuteNonQuery method to call a stored procedure.  Java with JDBC also provides a way to call stored procedures.</p>
<p>In the case of REALbasic, you&#8217;ll need to use the appropriate syntax for your database server to call the stored procedure using SQL.</p>
<p>For example, with Microsoft SQL Server (on Windows, connected via ODBC) you would use this code to run a stored procedure called INSERT_TEST:</p>
<pre>mySQLServerODBCDatabase.SQLExecute("exec INSERT_TEST")</pre>
<p>For Oracle you should enclose the stored procedure call in a block:</p>
<pre>Dim spString As String
spString = "BEGIN" + EndOfLine + "INSERT_TEST" + EndOfLine + "END"
myOracleServerDatabase.SQLExecute(spString)</pre>
<p>Of course, this technique provides no way for you to easily pass parameters to the procedure and certainly no easy way to get results or parameters back.  A workaround for sending parameters would be to insert them  directly into the string, which will work for simple datatypes.  You could also insert your parameters into a special parameter table and then have the stored procedure look for them there.  For return values and results, you could also insert the information into a table and then have your app get it with a SQL SELECT.</p>
<p>Obviously this doesn&#8217;t help you a whole lot of you are trying to hook up a REALbasic application to an existing database with stored procedures, which you may not be able to modify.  One solution to this dilema is to create new wrapper procedures for the existing stored procedures.  Your REALbasic code calls the wrapper which either puts or retrieves the data in the parameter tables and then can call the original stored procedure.</p>
<h2>Using JDBC and MonkeyBread</h2>
<p>Another option that has recently become available is to use the JDBC classes that are part of the <a href="http://www.monkeybreadsoftware.de/realbasic/plugin-java.shtml">Java plugin</a> included in the <a href="http://www.monkeybreadsoftware.de/realbasic/">MonkeyBread Plugin Suite</a>.  It contains a class, JavaCallableStatementMBS, specifically for calling stored procedures.  Unfortunately the documentation and examples do not cover this feature well.  It looks like you have to set up your parameters individually and then call the procedure using executeQuery.</p>
<h2>OpenBase SQL 10</h2>
<p>I should note that <a href="http://openbase.com">OpenBase SQL 10</a> has the ability to create stored procedures using REALbasic.  This is not well documented, but apparently REALbasic console applications can be run as stored procedures on the database server.</p>
<hr />
<h2>Stored Procedure Code Samples</h2>
<h3>Oracle PL/SQL</h3>
<pre>CREATE PROCEDURE INSERT_TEST AS
BEGIN
INSERT INTO testlog (name, connectTime, status)
VALUES ('Bob Roberts', SYSDATE, 'Active');

COMMIT;

END;</pre>
<h3>SQL Server T-SQL</h3>
<pre>CREATE PROCEDURE INSERT_TEST AS
INSERT INTO TestLog (name, connectTime, status)
VALUES ('Bob Roberts', GetDate(), 'Active')

RETURN

GO</pre>
<h3>PostgreSQL PL/pgSQL</h3>
<p>:</p>
<pre>CREATE PROCEDURE INSERT_TEST AS
BEGIN
INSERT INTO testlog (name, connectTime, status)
VALUES ('Bob Roberts', now(), 'Active');

COMMIT;

END;</pre>
<h3>MySQL</h3>
<pre>CREATE PROCEDURE INSERT_TEST()
BEGIN
INSERT INTO TestLog (name, connectTime, status)
VALUES ('Bob Roberts', CURRDATE(), 'Active');
END</pre>
<h3>OpenBase OpenScript</h3>
<pre>START TRANSACTION TRY
REQUIRE EXECUTE SQL "INSERT INTO TestLog (name, connectTime, status) VALUES ('Bob Roberts', CURRDATE(), 'Active')"
REQUIRE COMMIT
CATCH
ROLLBACK
END TRY</pre>
<h3>FrontBase Stored Procedure</h3>
<pre>create procedure INSERT_TEST()
BEGIN
INSERT INTO TestLog (name, connectTime, status)
VALUES ('Bob Roberts', CURRDATE(), 'Active');
END;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2008/12/some-stored-procedure-examples/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An Overview of Stored Procedures</title>
		<link>http://www.rbdevzone.com/2008/12/an-overview-of-stored-procedures/</link>
		<comments>http://www.rbdevzone.com/2008/12/an-overview-of-stored-procedures/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 20:59:38 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/?p=150</guid>
		<description><![CDATA[This article originally appeared in REALbasic Developer Magazine 4.2 (Nov/Dec 2005)
If you find yourself working with database servers, you may be wondering about stored procedures.  Depending on who you talk to, stored procedures are either something you should definitely be using or something you should avoid like the plague.  As with most things [...]]]></description>
			<content:encoded><![CDATA[<p><cite>This article originally appeared in REALbasic Developer Magazine 4.2 (Nov/Dec 2005)</cite></p>
<p>If you find yourself working with database servers, you may be wondering about stored procedures.  Depending on who you talk to, stored procedures are either something you should definitely be using or something you should avoid like the plague.  As with most things in life, the answer is not quite so simple.</p>
<h2>What is a Stored Procedure?</h2>
<p>A stored procedure (SP) is code that runs on the database server.  Generally this code is written in a language that is proprietary to the database server you are working with.  Some database servers may support more than one store procedure language.  Figure 1 is a table of some common database servers and their corresponding stored procedure languages.</p>
<p>I&#8217;ll be focusing on the SQL-type programming languages as they are much more commonly used.</p>
<p>Code Listing 1 shows you how a very simple stored procedure looks with PostgreSQL.  This is a very simple example that justs inserts a row of data into a log table.  The syntax across the various databases is similar, but different enough to be annoying when you work with more than one.  They become much less similar when you start working with variable declarations, datatypes and control structures.</p>
<p>As their name implies, stored procedures are procedure-oriented, not object-oriented.  They&#8217;re not called stored objects, after all.  This means there is no support for things like inheritance.  Oracle has a little support for data encapsulation with its Stored Packages, but we won&#8217;t go into those now.  Also note that if you did choose to work with other stored procedure languages, you would get to use object-oriented features, but as I mention above these are not widely used.</p>
<h2>Why Should You Use Them?</h2>
<p>Stored procedures use a language you probably don&#8217;t know and are usually not object-oriented, so why would you consider using them?  Well, stored procedures can be quite fast and therefore are frequently used to improve the performance of a database application.  Since the code lives right alongside the database, you eliminate almost all network traffic and can allow the database server to work to its fullest.</p>
<p>Another benefit of stored procedures is that they can provide a nice way to encapsulate business logic near the data it is modifying.  This can be useful if you expect to have several ways to access data (perhaps both a desktop and web application) and want to ensure a consistent API.  It is easier and less error-prone to update this business logic once on the server rather than by updating multiple applications.</p>
<p>Lastly, if you&#8217;ve paid a lot of money for expensive database server software, it seems silly to not use all the features it can provide.</p>
<h2>Why Should You Avoid Them?</h2>
<p>The primary reason to not use stored procedures is that they are not portable.  Using stored procedures effectively locks you into using a single database vendor.  If you need your application to run on a different vendor&#8217;s server, then you&#8217;ll need to recreate all your stored procedures.  This can be a huge amount of work or can be completely impractical depending on the database servers you use.</p>
<h2>Wrapping Up</h2>
<p>I&#8217;ve worked on projects and products with hundreds of stored procedures, just a few stored procedures, and no stored procedures.  The rule I generally follow now is to not rely on stored procedures during initial design and development.  I design my applications so that they could work with any database backend.  As the product is nearing completion, I review areas that may need performance improvements to see if a stored procedure would make sense .  If so, I&#8217;ll add the ability to use a stored procedure while at the same time retaining the ability to work without the stored procedure.</p>
<p>Next time we&#8217;ll look at more examples of stored procedures using syntax for several different database servers.  We&#8217;ll also look at how stored procedures can be used with REALbasic.</p>
<h3>Simple PostgreSQL PL/pgSQL Stored Procedure</h3>
<pre>CREATE PROCEDURE INSERT_TEST AS
BEGIN
INSERT INTO testlog (name, connectTime, status)
VALUES ('Bob Roberts', now(), 'Active');

COMMIT;

END;</pre>
<h3>Figure 1: Databases and Stored Procedure Languages</h3>
<table border="1">
<tbody>
<tr>
<th>Database</th>
<th>Stored Procedure Language</th>
<th>Notes</th>
</tr>
<tr>
<td>MySQL</td>
<td>SQL:2003</td>
<td>Available starting with V5.0</td>
<td> </td>
</tr>
<tr>
<td>PostgreSQL</td>
<td>PL/pgSQL, PL/TCL, PL/Perl, PL/Python</td>
<td>PL/pgSQL is very similiar to Oracle PL/SQL</td>
</tr>
<tr>
<td>Oracle</td>
<td>PL/SQL, Java</td>
</tr>
<tr>
<td>SQL Server</td>
<td>Transact-SQL (T-SQL), C#, VB.NET</td>
<td>C#, VB.NET available in SQL Server 2005</td>
</tr>
<tr>
<td>OpenBase</td>
<td>OpenScript, Java, REALbasic</td>
</tr>
<tr>
<td>FrontBase</td>
<td>Stored Procedures</td>
</tr>
<tr>
<td>DB2</td>
<td>Procedural SQL, Visual Basic .NET, C, C++, C#, COBOL, Java, or REXX</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2008/12/an-overview-of-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Database Servers: FrontBase</title>
		<link>http://www.rbdevzone.com/2008/12/database-servers-frontbase/</link>
		<comments>http://www.rbdevzone.com/2008/12/database-servers-frontbase/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 03:00:06 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/?p=148</guid>
		<description><![CDATA[This article was originally published in REALbasic Developer 6.1 (Nov/Dec 2007)
FrontBase is a full-featured database server that is available for Mac OS X, Linux and Windows.  It was created by a Denmark company and was initially release just for Mac OS X.  But in 2004, it went cross-platform with releases for Windows, Linux [...]]]></description>
			<content:encoded><![CDATA[<p><cite>This article was originally published in <a href="http://www.rbdeveloper.com/browse/6.1/">REALbasic Developer 6.1 (Nov/Dec 2007)</a></cite></p>
<p><a href="http://www.frontbase.com">FrontBase</a> is a full-featured database server that is available for Mac OS X, Linux and Windows.  It was created by a Denmark company and was initially release just for Mac OS X.  But in 2004, it went cross-platform with releases for Windows, Linux (and Unix).  And as of April 15, 2006 FrontBase is available for free, with no usage restrictions.  You can purchase support services from them, however.</p>
<p>Currently at version 4.2.9, FrontBase has many features you&#8217;d associate with a professional database server, including:</p>
<ul>
<li>SQL 92 support</li>
<li>Stored procedures</li>
<li>EncryptionREALbasic native plug-in</li>
<li>Terabyte databases</li>
<li>Backups</li>
<li>Indexing</li>
<li>Migration from MySQL and FileMaker</li>
</ul>
<h2>Installation</h2>
<p>The FrontBase <a href="http://www.frontbase.com/cgi-bin/WebObjects/FrontBase.woa/wa/mainFrame?currentMenu=downloadMenu&amp;action=downloadArea&amp;currentPage=Download&amp;currentModule=Download">download</a> is quite small (only 4.5MB for Windows, 14.6MB for OS X) and installation was straightforward and fast although I did get an error about a missing web component from the Windows installer.  Even though FrontBase is free, you do have to go to the trouble of creating an account on the FrontBase web site to get a free license key.  You have to request a separate key for each platform and also need to specify either the IP address or MAC address of the computer it will be installed on.  Unless your server has a static IP address, it looks like the MAC address is the way to go.  Of course obtaining your MAC address could be tricky.  On Windows, type IPCONFIG /all and look for the line that says &#8220;Physical Address&#8221;.  On Mac OS X, it is in your Network Preference panel.  If you use Linux, I&#8217;m sure you can find it on your own.</p>
<p>Once you have this license you need to apply it to FrontBase by cutting and pasting it into a text file and putting this file in the FrontBase folder (\usr\FrontBase).  Although this was not the most complicated database installation I&#8217;ve had to do, it certainly wasn&#8217;t the easiest either.</p>
<h2>Database Administration</h2>
<p>To access FrontBase, you use either the included SQL92 command line or the Java-based FrontBase JManager, but I had trouble getting that to connect (at least on Windows).  The SQL92 command line gives you full control over the database server and the databases it is server, but you&#8217;ll obviously need to learn the commands (and there are plenty).</p>
<p>The JManager tool looks decent enough, although it suffers from its odd Java UI.  They should really create a version of this in REALbasic.</p>
<h2>Documentation</h2>
<p>No documentation is installed to your machine, but you can <a href="http://www.frontbase.com/cgi-bin/WebObjects/FrontBase.woa/wa/mainFrame?currentMenu=productsMenu&amp;action=productsPage&amp;currentPage=Documentation&amp;currentModule=Documentation">download</a> the 230 page user&#8217;s guide (in PDF format) from their web site.  Since FrontBase uses SQL 92, you can find some books about that on Amazon.  I didn&#8217;t find any FrontBase-specific books on Amazon, however.  There also was not much information about FrontBase that I could find using Google.</p>
<h2>Connecting to REALbasic</h2>
<p>I created a sample database by starting the FrontBase SQL92 command line and entering these commands, one on each line:</p>
<pre>create database firstdb;
connect to firstdb user _system;
create user test;
commit;
disconnect current;</pre>
<p>This gives us a new database, called firstdb, with a user, called test.  Now let&#8217;s see how easily we can connect to FrontBase using REALbasic.  After downloading version 1.92 of the plugin (which, I&#8217;m am pleased to see, supports Mac OS X (including Universal Binaries), Windows and Linux), I copied it to the REALbasic plugins folder and started REALbasic (Professional 2008 Release 5).  Keep in mind that in order to use databases besides REAL SQL Database, you need to have REALbasic Professional.</p>
<p>In a new blank project, add a PushButton to the default window and switch to its Action event.  Add this code:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Dim</span> firstDb <span style="color: #000080;">As</span> <span style="color: #000080;">New</span> FBDatabase
&nbsp;
firstDb.Host = <span style="color: #800000;">&quot;localhost&quot;</span>
firstDb.DatabaseName = <span style="color: #800000;">&quot;firstdb&quot;</span>
firstDb.UserName = <span style="color: #800000;">&quot;test&quot;</span>
&nbsp;
<span style="color: #000080;">If</span> firstDb.Connect <span style="color: #000080;">Then</span>
    MsgBox <span style="color: #800000;">&quot;Connected!&quot;</span>
<span style="color: #000080;">Else</span>
    MsgBox <span style="color: #800000;">&quot;Could not connect.&quot;</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span></pre></div></div>

<p>Run the app and click the button.  If everything is set up correctly, then you should get the &#8220;Connected!&#8221; message.</p>
<p>Now it works just like any other database.  You can use firstDb.SQLSelect to process SELECT statements on database tables and you can use SQLExecute to run commands on the database.</p>
<h2>Summary</h2>
<p>If you can get past the slightly annoying installation, FrontBase seems like it would be worth a look.  You&#8217;ll probably have to use the command-line, at least for some things, even if you can get the JManager tool to work.  The only other database server that is also cross-platform, works with REALbasic and is completely free is <a href="http://www.postgresql.org/">PostgreSQL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2008/12/database-servers-frontbase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free OpenBase SQL 10 for REALbasic Developers</title>
		<link>http://www.rbdevzone.com/2008/01/free-openbase-sql-10-for-realbasic-developers/</link>
		<comments>http://www.rbdevzone.com/2008/01/free-openbase-sql-10-for-realbasic-developers/#comments</comments>
		<pubDate>Sat, 05 Jan 2008 01:22:30 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/2008/01/free-openbase-sql-10-for-realbasic-developers/</guid>
		<description><![CDATA[I bet you didn&#8217;t know, but OpenBase makes their excellent database server, OpenBase SQL 10, available for free for REALbasic developers (OpenBase Unlimited for REALbasic).  This edition includes Code Builder, a free license to On-Target Reports and requires you to use the REALbasic Connectivity module (not the plugin) to connect.
Scott Keith of OpenBase was kind [...]]]></description>
			<content:encoded><![CDATA[<p>I bet you didn&#8217;t know, but <a href="http://www.openbase.com">OpenBase</a> makes their excellent database server, OpenBase SQL 10, available for free for REALbasic developers (OpenBase Unlimited for REALbasic).  This edition includes Code Builder, a free license to On-Target Reports and requires you to use the REALbasic Connectivity module (not the plugin) to connect.</p>
<p>Scott Keith of OpenBase was kind enough to pass along the license information for this edition and has given me permission to publish it here:</p>
<p>Serial Number: <span class="Apple-style-span" style="font-weight: bold">OBEMBREALBASIC-639</span><br />
Authorization Code: <span class="Apple-style-span" style="font-weight: bold">P-10-10.0-528-67E-A7C</span></p>
<p>This license works with either the Mac OS X or Windows versions, but not the Linux version.</p>
<p>Download <a href="http://www.openbase.com/downloads.html">OpenBase SQL</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2008/01/free-openbase-sql-10-for-realbasic-developers/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Databases 103: Creating Tables and Data</title>
		<link>http://www.rbdevzone.com/2007/03/databases-103-creating-tables-and-data/</link>
		<comments>http://www.rbdevzone.com/2007/03/databases-103-creating-tables-and-data/#comments</comments>
		<pubDate>Thu, 01 Mar 2007 14:28:45 +0000</pubDate>
		<dc:creator>Paul Lefebvre</dc:creator>
				<category><![CDATA[Databases]]></category>

		<guid isPermaLink="false">http://www.rbdevzone.com/2007/03/databases-103-creating-tables-and-data/</guid>
		<description><![CDATA[Let&#8217;s take the entities we created last time and turn them into tables. Once we do this we&#8217;ll create these tables in a REALbasic database using SQL.
Mapping entities to tables is fairly straightforward. Typically each entity becomes a table and each attribute becomes a column. You may have to do a few adjustments of table [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s take the entities we created last time and turn them into tables. Once we do this we&#8217;ll create these tables in a REALbasic database using SQL.</p>
<p>Mapping entities to tables is fairly straightforward. Typically each entity becomes a table and each attribute becomes a column. You may have to do a few adjustments of table and column names to meet any restrictions of the specific database you are using. Also keep in mind that not every database has the exact same datatypes so some changes may be necessary there as well.</p>
<h2>Creating the SQL</h2>
<p>Refer to the entities we created last time:</p>
<p><a rel="attachment wp-att-21" href="http://www.rbdevzone.com/?attachment_id=21" title="Databases 102: Figure 4"><img src="http://capeumc.fatcow.com/wp-content/uploads/2007/10/figure4.jpg" alt="Databases 102: Figure 4" /></a></p>
<p>There&#8217;s nothing fancy in the team entity (except that we&#8217;ll use varchar instead of string), so it&#8217;s table create statement looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> team <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">KEY</span> INTEGER <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> name TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> coach TEXT<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The key column is what is called an artificial primary key. It is used in place of the team name so that we can more easily allow for changes to the team name after it has been used in other relationships.</p>
<p>The location entity is also simple, here is its create table statement:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> location <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">KEY</span> INTEGER <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</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;">FIELD</span> TEXT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> lights TEXT<span style="color: #66cc66;">,</span> address TEXT<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The game table is a bit more complicated because of the relationships. Each of the relationships translates to a column in the game table. These columns are referred to as a foreign keys.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> game <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">KEY</span> INTEGER <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> 
hometeam INTEGER<span style="color: #66cc66;">,</span> awayteam INTEGER<span style="color: #66cc66;">,</span> location INTEGER<span style="color: #66cc66;">,</span> gamedate DATE<span style="color: #66cc66;">,</span> gametime TIME<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>I have used gamedate and gametime in place of date and time because most database systems do not like it when you use a reserved word as a column name.</p>
<h2>Creating the Database</h2>
<p>You have the option of creating the actual database and the tables using the REALbasic IDE, but we&#8217;re here to learn SQL so we&#8217;ll going to actually use the CREATE TABLE commands from above. Unfortunately, REALbasic&#8217;s built in database tool only allows for interactive SELECT statements and not CREATE TABLE or any of the other SQL commands. So for these examples we will use the free SQLite Database Browser, an open-source browser that works on Windows, Mac OS X and Linux.</p>
<p>Once you have started SQLite Database Browser, click on the leftmost icon to create a new database file and enter a name for the database. For this example we&#8217;ll use Softball.rsd. Click Cancel on the Create Table window that appears. We&#8217;ll be creating our tables using SQL.</p>
<p>Now click the Execute SQL tab. You can enter the CREATE TABLE commands from above (one at a time) and press the Execute query button. Each time you successfully create a table it will appear in the table list on the left.</p>
<p>After you have created the 3 tables, it&#8217;s time to add some sample data to them. We&#8217;ll use the SQL INSERT command to do this. These commands add data to the team table. Enter one at a time into the Execute SQL tab:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> team <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span> coach<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Ducks&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Paul&quot;</span> <span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> team <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span> coach<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Bears&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;David&quot;</span> <span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> team <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span> coach<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Lions&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Vin&quot;</span> <span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> team <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span> coach<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Tigers&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Julie&quot;</span> <span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> team <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span> coach<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Dogs&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Laura&quot;</span> <span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> team <span style="color: #66cc66;">&#40;</span>name<span style="color: #66cc66;">,</span> coach<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Cats&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Jim&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>We are not inserting any key values because we are letting SQLite handle that for us automatically. Now let&#8217;s add some data to the location table:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> location <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> lights<span style="color: #66cc66;">,</span> address<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Hadlock Field&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Yes&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Downtown&quot;</span> <span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> location <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">FIELD</span><span style="color: #66cc66;">,</span> lights<span style="color: #66cc66;">,</span> address<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Payson Park&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;No&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;Back Cove&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>And finally let&#8217;s add some games. This first command creates a game between the Ducks (Key = 1) and the Bears (Key = 2) at Hadlock Field (Key = 1):</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> game <span style="color: #66cc66;">&#40;</span>hometeam<span style="color: #66cc66;">,</span> awayteam<span style="color: #66cc66;">,</span> location<span style="color: #66cc66;">,</span> gamedate<span style="color: #66cc66;">,</span> gametime<span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;2003-06-01&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;05:00:00&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This command creates a game between the Tigers (Key = 4) and the Dogs (Key = 5) at Payson Park (Key = 2):</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> game <span style="color: #66cc66;">&#40;</span>hometeam<span style="color: #66cc66;">,</span> awayteam<span style="color: #66cc66;">,</span> location<span style="color: #66cc66;">,</span> gamedate<span style="color: #66cc66;">,</span> gametime<span style="color: #66cc66;">&#41;</span> 
<span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;2003-06-01&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">&quot;05:00:00&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>To view the data, switch to the Browse Data tab and select a table from the drop-down list.</p>
<p>To see the games we just entered in a nicer format, try this SQL:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> hteam<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'vs.'</span><span style="color: #66cc66;">,</span> ateam<span style="color: #66cc66;">.</span>name<span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'at'</span><span style="color: #66cc66;">,</span> location<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">FIELD</span> 
<span style="color: #993333; font-weight: bold;">FROM</span> team ateam<span style="color: #66cc66;">,</span> game<span style="color: #66cc66;">,</span> location<span style="color: #66cc66;">,</span> team hteam 
<span style="color: #993333; font-weight: bold;">WHERE</span> hteam<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">=</span> game<span style="color: #66cc66;">.</span>hometeam 
<span style="color: #993333; font-weight: bold;">AND</span> ateam<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">=</span> game<span style="color: #66cc66;">.</span>awayteam 
<span style="color: #993333; font-weight: bold;">AND</span> game<span style="color: #66cc66;">.</span>location <span style="color: #66cc66;">=</span> location<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">KEY</span></pre></div></div>

<p><a href="http://www.rbdevzone.com/wp-content/uploads/2007/10/softball.zip" title="Softball SQLite database">Download Softball SQLite database</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rbdevzone.com/2007/03/databases-103-creating-tables-and-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
