    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Let's Do C# and MySQL - Part 1 - MySQL</title>
        <link>https://members.accu.org/index.php/articles/834</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + CVu Journal Vol 17, #5 - Oct 2005</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c94/">175</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-94/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+94/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Let's Do C# and MySQL - Part 1 - MySQL</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 02 October 2005 06:00:00 +01:00 or Sun, 02 October 2005 06:00:00 +01:00</p>
<p><strong>Summary:</strong>&nbsp;<p>Before I start, this is going to be fun. Understand? Fun. Not dull, but fun. I intend writing this in a banana suit with my feet in a bucket of warm rice pudding[1]. That's how much fun it's going to be!</p></p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e22" id="d0e22"></a></h2>
</div>
<p>Before I start, this is going to be fun. Understand? Fun. Not
dull, but fun. I intend writing this in a banana suit with my feet
in a bucket of warm rice pudding<sup>[<a name="d0e26" href=
"#ftn.d0e26" id="d0e26">1</a>]</sup>. That's how much fun it's
going to be!</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e30" id="d0e30"></a>Objectives</h2>
</div>
<p>What is the point of the series of articles? I intend it to be a
learning progression to take you from the very basics of an
application through to implementation. I've chosen to write a small
MySQL front end in C# to do this. There will be a progression from
setting up the MySQL database, testing using a command line
application, moving it over to a System.Windows.Forms application
and then adding in functionality. I will also look at using db4o.
The question is though - why C#?</p>
<p>The MySQL API is very well documented and is accessible through
many different programming languages with the minimum of fuss. I've
chosen C# as I'm yet to find any really good tutorials for using
the language. Sure, MSDN contains a great deal of information, but
without the linking arguments, the information is almost context
less.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e37" id="d0e37"></a>Let's Make a
Start</h2>
</div>
<p>You will need a copy of MySQL installed on your computer to
benefit from this series of articles and some form of C# compiler.
The code works fine with both Mono and Microsoft C# - I have not
tested the C# using gnu.NET. When compiling the code, Microsoft
users should use <tt class="literal">csc</tt> and Mono users
<tt class="literal">mcs</tt>. Any additional dlls to be used will
be listed as <tt class="literal">-r:System.Drawing
-r:System.Windows.Forms</tt> (though if you are using Visual
Studio, these are normally be hidden).</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e51" id="d0e51"></a>Setting up
MySQL</h2>
</div>
<p>The first thing we'll need is a working MySQL database. I'm not
going to assume that you've set up a database before now, but there
are effectively two things you need to decide. What's going into it
and how it's laid out. Take the following list of elements:</p>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;20%&quot;&gt;
&lt;col width=&quot;20%&quot;&gt;
&lt;col width=&quot;20%&quot;&gt;
&lt;col width=&quot;20%&quot;&gt;
&lt;col width=&quot;20%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Element</th>
<th>Atomic Symbol</th>
<th>Description URL</th>
<th>Mass</th>
<th>Atomic Number</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>Copper</td>
<td>Cu</td>
<td>metals/copper</td>
<td>63.546</td>
<td>29</td>
</tr>
<tr>
<td>Chlorine</td>
<td>Cl</td>
<td>gases/chlorine</td>
<td>35.5</td>
<td>17</td>
</tr>
<tr>
<td>Neptunium</td>
<td>Np</td>
<td>actinides/neptunium</td>
<td>237</td>
<td>93</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>I could have one very large database which would contain
parameters such as the period number, CAS registry, element block,
shell filling, picture URL, if it is radioactive, man made and so
on. This would be fine, but very messy and a pain to administer
too.</p>
<p>A simpler solution is to break the database down and to do that,
we need a couple of generic categories.</p>
<p>The list above gives three types of element: metal, gas and
man-made. They are good enough and more can be added as and when I
need them (such as trans-metal, halide and trans-actinide). But
what of the actual data? For that, a second table is created which
is linked to the generic first table. In the second table, the
specifics of the element are held (such as discovery, relative
atomic weight, shell filling, etc.).</p>
<p>Graphically, the database looks like this.</p>
<div class="c3"><img src="/var/uploads/journals/resources/drawing1.png" align=
"middle"></div>
<p>For the <span class="emphasis"><em>Element Info</em></span>
column, <span class="emphasis"><em>ID</em></span> represents the
classification ID - for example, metal = 1, gas = 2. <span class=
"emphasis"><em>Name</em></span> is the generic name, <span class=
"emphasis"><em>Description</em></span> a generic description and
<span class="emphasis"><em>Image</em></span> a generic picture.
<span class="emphasis"><em>Element Info</em></span> links to
<span class="emphasis"><em>The Element</em></span> in what is known
as a 1 to many (sometimes known as 1 to infinity) relationship (1
item in the generic table can link to many items in the second
table, as long as they match the type of the generic item).
<span class="emphasis"><em>The Element</em></span> list is straight
forward to understand which again is linked to a third database
(again via a 1 to many relationship) for other information.</p>
<p>Okay, what you should now be asking is why the other information
should be in its own table?</p>
<p>When you think about it, the answer to that is simple. Say a new
element is discovered (or created). While it is entirely possible
to enter all of the details into one big table, discovery of
elements and the dates are sometimes contested (especially for the
trans-actinides where there was originally contested names for
elements 104 to 111) - after the dust settles, it may be that the
original name has to be changed, the discoverer changed and a few
other details to boot. It is far simpler to have all of the
&quot;additional&quot; information elsewhere so that the main database is
still correct.</p>
<p>When considering a MySQL database, it could also be thought of
as spreadsheet in style with columns and rows. A column will always
be of a particular type which will be associated with a row. For
example</p>
<div class="c3"><img src="/var/uploads/journals/resources/drawing2.png" align=
"middle"></div>
<p>The white blocks indicate the type associated. It's not quite
how things are done, but is a convenient way to represent the
database. (<span class="emphasis"><em>In reality, it's actually a
two column table with the ID in column 1 and the type in column 2 -
my representation is just handy - well, to me at
least!</em></span>)</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e151" id="d0e151"></a>MySQL Data
Types</h2>
</div>
<p>If you think of the MySQL server as a form of computer, you can
quickly see that objects within the database can be thought of as
variables and all variables need to be of a specific type (such as
<tt class="type">int</tt>, <tt class="type">char</tt> and
<tt class="type">float</tt>). MySQL has specific data types for the
components of a database. Effectively,there are three main types
for MySQL : <tt class="type">Date &amp; Time</tt>, <tt class=
"type">Numeric</tt> and <tt class="type">String</tt>.</p>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e174" id="d0e174"></a>Date and
Time</h3>
</div>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;33%&quot;&gt;
&lt;col width=&quot;33%&quot;&gt;
&lt;col width=&quot;34%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Field name</th>
<th>What it does</th>
<th>Range</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>DATE</td>
<td>It's a date. MySQL allows dates to be inputted as either a
string or numeric.</td>
<td>1000-01-01 to 9999-12-31. Always in yyyy-mm-dd format.</td>
</tr>
<tr>
<td>DATETIME</td>
<td>Time and date. As with date, the fields can be entered as
strings or numerics. Always displayed a yyyy-mm-dd HH:MM:SS</td>
<td>1000-01-01 00:00:00 to 9999-12-31 23:59:59</td>
</tr>
<tr>
<td>TIME</td>
<td>Time - has the format HH:MM:SS and can be set using strings or
numeric values</td>
<td>-838:59:59 to 838:59:59</td>
</tr>
<tr>
<td>TIMESTAMP</td>
<td>This allows a timestamp to be added when either update or
insert are used. TIMESTAMP is returned as a string of the format
yyyy-mm-dd HH:MM:SS. TIMESTAMP will automatically add the time and
date of the most recent operation if you don't set it.</td>
<td>1970-01-01 00:00:00 to midway through 2037.</td>
</tr>
<tr>
<td>YEAR[(2/4)]</td>
<td>Gives the year as either 2 or 4 digit values. Default 4
digit.</td>
<td>0000 and between 1901-2155 for 4 digit and 70-69 for 2 digit
(represents 1970 to 2069).</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e223" id="d0e223"></a>String
Types</h3>
</div>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;33%&quot;&gt;
&lt;col width=&quot;33%&quot;&gt;
&lt;col width=&quot;34%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Field name</th>
<th>What it does &amp; Options</th>
<th>Range</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>CHAR(M)</td>
<td>A character string of size M. It is right space padded. Options
BINARY (also written as BYTE), ASCII (assigns latin1), UNICODE
(assigns ucs2). Trailing spaces are removed when retrieved. If M
&gt; 255, it is automatically converted to SMALLTEXT (From version
4.1.0) - this applies to other large values. CHAR can be preceded
by NATIONAL. This tells the database to use the default character
set for that nation.</td>
<td>0 - 255</td>
</tr>
<tr>
<td>CHAR</td>
<td>Synonym for CHAR(1)</td>
<td> </td>
</tr>
<tr>
<td>VARCHAR(M)</td>
<td>A variable length string of maximum size M. Can be preceded by
NATIONAL. Options : BINARY (stores the string as a binary set)</td>
<td>M = 0 to 255 (MySQL &lt; 5.0.3)</td>
</tr>
<tr>
<td>BINARY(M)</td>
<td>Roughly the same as CHAR(M)</td>
<td> </td>
</tr>
<tr>
<td>VARBINARY(M)</td>
<td>Roughly the same as VARCHAR(M) except is stored as binary byte
string instead of non-binary character bytes.</td>
<td> </td>
</tr>
<tr>
<td>TINYBLOB</td>
<td>A small blob column.</td>
<td>255 bytes</td>
</tr>
<tr>
<td>TINYTEXT</td>
<td>A small text column</td>
<td>255 bytes</td>
</tr>
<tr>
<td>BLOB[(M)]</td>
<td>A blob column. The server will create the smallest possible
blob column for the size. If M &lt; 255 then a TINYBLOB is
used.</td>
<td>65535 bytes</td>
</tr>
<tr>
<td>TEXT[(M)]</td>
<td>A text column. The server will create the smallest possible
blob column for the size. If M is &lt; 255, then a TINYTEXT is
used.</td>
<td>65535 bytes</td>
</tr>
<tr>
<td>MEDIUMBLOB</td>
<td>A medium sized blob column</td>
<td>16,777,215 bytes</td>
</tr>
<tr>
<td>MEDIUMTEXT</td>
<td>A medium sized text column</td>
<td>16,777,215 bytes</td>
</tr>
<tr>
<td>LONGBLOB</td>
<td>A somewhat large blob column</td>
<td>4,294,967,295 bytes (4 Gb)</td>
</tr>
<tr>
<td>LONGTEXT</td>
<td>A large text column</td>
<td>4,294,967,295</td>
</tr>
<tr>
<td>ENUM(c1,c2,..)</td>
<td>An enumeration column. It is very similar to C enumerations
with the strings being held internally as integer values.</td>
<td>Max. 65535 enumerations</td>
</tr>
<tr>
<td>SET(c1, c2,...)</td>
<td>A string which can have more than one value (0 to n). The
strings (c1, c2 to cn) are held internally as integers.</td>
<td>Max. 64 strings.</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e339" id="d0e339"></a>Numeric
Values</h3>
</div>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;33%&quot;&gt;
&lt;col width=&quot;33%&quot;&gt;
&lt;col width=&quot;34%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Field name</th>
<th>What it is, options and aliases</th>
<th>Range</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>BIT [(M)]</td>
<td>A bit field type. If M is not specified, it is taken as 1.</td>
<td>1 - 64</td>
</tr>
<tr>
<td>TINYINT[(M)]</td>
<td>A very small integer. Can be signed (default) or UNSIGNed. Can
also be set with ZEROFILL.</td>
<td>0 - 255 (unsigned) or -127 to 128 (signed).</td>
</tr>
<tr>
<td>BOOL, BOOLEAN</td>
<td>This is a synonym for TINYINT(1).</td>
<td>0 = false, non-zero = true.</td>
</tr>
<tr>
<td>SMALLINT[(M)]</td>
<td>A small integer range. Can be signed (default) or UNSIGNed. Can
also be set with ZEROFILL.</td>
<td>-32767 - 32768 or 0 - 65535</td>
</tr>
<tr>
<td>MEDIUMINT[(M)]</td>
<td>A medium range integer. Can be signed (default) or UNSIGNed.
Can also be set with ZEROFILL.</td>
<td>-8388608 - 8388607 or 0 - 16777215</td>
</tr>
<tr>
<td>INT[(M)]</td>
<td>A normal sized integer. Can be signed (default) or UNSIGNed.
Can also be set with ZEROFILL. Can also be written as INTEGER.</td>
<td>-2147483648- 2147483647 or 0 - 4294967295</td>
</tr>
<tr>
<td>BIGINT[(M)]</td>
<td>A big integer. Can be signed (default) or UNSIGNed. Can also be
set with ZEROFILL. Use with care (see the notes after this
table).</td>
<td>-9223372036854775808 - 92233720368547758 or 0 -
18446744073709551615</td>
</tr>
<tr>
<td>FLOAT[(p)]</td>
<td>A floating point value. Can be signed (default) or UNSIGNed.
Can also be set with ZEROFILL.</td>
<td>p = 0 - 24, single precision, p = 25 - 53, double
precision</td>
</tr>
<tr>
<td>FLOAT[(M,D)]</td>
<td>A floating point figure. Can be signed (default) or UNSIGNed.
Can also be set with ZEROFILL. M is the display width, D is the
number of decimal places. If no values are set or FLOAT(p = 25 to
53) is not used (M can be blank), the value is single precision.
Can also be written as REAL.</td>
<td>-3.402823466E+38 to -1.175494351E-38, 0 and 1.175494351E-38 to
3.402823466E+38</td>
</tr>
<tr>
<td>DOUBLE[(M,D)]</td>
<td>A double precision value. Can be signed (default) or UNSIGNed.
Can also be set with ZEROFILL. M is the display width, D is the
number of decimal places. Also can be written as DOUBLE
PRECISION.</td>
<td>-1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and
2.2250738585072014E-308 to 1.7976931348623157E+308</td>
</tr>
<tr>
<td>DECIMAL[(M[,D]) (MySQL 5.03)</td>
<td>A packed exact fixed point figure of length M and with D
digits. If D is omitted, 0 is used (there can be no decimals or
fractions with this value). If M is omitted, 10 is used. Can also
be UNSIGNed and ZEROFILL. Also written as DEC[(M[,D]), FIXED[M[,D])
and NUMERIC[(M[,D]).</td>
<td>Max D = 30, Max M = 64</td>
</tr>
<tr>
<td>DECIMAL[(M[,D]) (pre MySQL 5.03)</td>
<td>An unpacked exact fixed point figure of length M and with D
digits (it acts more like a CHAR column). All parameters and
synonyms for the above apply.</td>
<td>Max D = 30, Max M = 64</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<div class="sidebar">
<p><span class="bold"><b>Notes for BLOB</b></span></p>
<p>A BLOB is a Binary Large OBject - it can be just about any piece
of binary data (picture, video or audio are examples). A BLOB can
be useful in some circumstances (saving of avatars or to replace a
directory of binary objects) but can also be a hindrance (increases
the size of the database and may take longer to serve up the
data).</p>
<p><span class="bold"><b>Notes for BIGINT</b></span></p>
<p>All arithmetic is done using signed BIGINT or DOUBLE values, so
you shouldn't use unsigned big integers larger than
9223372036854775807 (63 bits) except with bit functions! If you do
that, some of the last digits in the result may be wrong because of
rounding errors when converting a BIGINT value to a DOUBLE.</p>
<p>MySQL 4.0 can handle BIGINT in the following cases:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>When using integers to store big unsigned values in a BIGINT
column.</p>
</li>
<li>
<p>In MIN(col_name) or MAX(col_name), where col_name refers to a
BIGINT column.</p>
</li>
<li>
<p>When using operators (+, -, *, and so on) where both operands
are integers.</p>
</li>
<li>
<p>You can always store an exact integer value in a BIGINT column
by storing it using a string. In this case, MySQL performs a
string-to-number conversion that involves no intermediate
double-precision representation.</p>
</li>
<li>
<p>The -, +, and * operators use BIGINT arithmetic when both
operands are integer values. This means that if you multiply two
big integers (or results from functions that return integers), you
may get unexpected results when the result is larger than
9223372036854775807.</p>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e467" id="d0e467"></a>Setting Up
the Database for Next Time</h2>
</div>
<p>MySQL can be set up from the command line or by using something
like mysqlcc [<a href="#_1">_1</a>] or phpMyAdmin [<a href=
"#_2">_2</a>]. Being a bit of a traditionalist, I'll go with the
terminal windoUw (mainly as it also means that you don't need to
download anything else!).</p>
<p>To call up MySQL, open a terminal window and type <tt class=
"literal">mysql -u root -p</tt>. This tells MySQL that you want to
start up with the user &quot;root&quot; and with a password. The actual nuts
and bolts of setting up MySQL isn't that hard.</p>
<p>If you've never used MySQL before, then the default password is
nothing - just hit the return key. This is a hideous security hole
and one which needs to be rectified as soon as you log in.</p>
<p>Once in, you'll see something similar to the image on the
right.<span class="inlinemediaobject"><img src=
"/var/uploads/journals/resources/mysql-screen1.png" align="right"></span></p>
<p>If you've not set a password, then enter the following:</p>
<pre class="programlisting">
UPDATE user set password = PASSWORD(&quot;newpassword&quot;) 
where user = 'root'; FLUSH PRIVILEGES; exit;
</pre>
<p>(In this instance, newpassword is a password of your choice)</p>
<p>You now have a new password for the root user on your MySQL
server. FLUSH PRIVILEGES clears all privileges on the server and
exit does what it says on the tin - it exits the MySQL
terminal.</p>
<p>That done, login to the server again. This time, let's examine
what tables come by default.</p>
<pre class="screen">
mysql&gt; show databases;
</pre>
<p><span class="inlinemediaobject"><img src=
"/var/uploads/journals/resources/mysql-screen3.png" align="left"></span>This will produce
a table containing all of the databases the MySQL server is
currently serving (right). You can see there is only 1 database on
the MySQL server this series is being composed on. mysql is the
database which contains details about users, passwords and the
such.</p>
<p>When show databases; didn't show up the name of the database to
be created, that gave the green light to say the database can be
created.</p>
<p>Before creating the database (and as is common with creating
anything on a computer), the database, linking, names and types
should be written on paper first.</p>
<p>I have already specified earlier the names which I will use for
the columns, but what about the types?</p>
<p>ID (here) is an INT and is also given the special type of
PRIMARY_KEY when defining. The tables below show all of the types
for all of the names.</p>
<p>The PRIMARY_KEYs all link to each other. KEY(1) is the &quot;root&quot;
key which links to KEY(2). KEY(3) is linked from Others ID to the
Catalogue table.</p>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Category Info</th>
<th>Type</th>
<th>Size</th>
<th>Special</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>ID</td>
<td>INT</td>
<td> </td>
<td>PRIMARY_KEY (1)</td>
</tr>
<tr>
<td>NAME</td>
<td>VARCHAR</td>
<td>30</td>
<td> </td>
</tr>
<tr>
<td>DESCRIPTION</td>
<td>VARCHAR</td>
<td>30</td>
<td> </td>
</tr>
<tr>
<td>IMAGE</td>
<td>VARCHAR</td>
<td>30</td>
<td> </td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Element Info</th>
<th>Type</th>
<th>Size</th>
<th>Special</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>ID</td>
<td>LONGINT</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Element Category</td>
<td>INT</td>
<td> </td>
<td>PRIMARY_KEY (2)</td>
</tr>
<tr>
<td>Name</td>
<td>VARCHAR</td>
<td>50</td>
<td> </td>
</tr>
<tr>
<td>Symbol</td>
<td>VARCHAR</td>
<td>5</td>
<td> </td>
</tr>
<tr>
<td>Image</td>
<td>VARCHAR</td>
<td>50</td>
<td> </td>
</tr>
<tr>
<td>Atomic weight</td>
<td>FLOAT(1)</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Atomic Number</td>
<td>INT</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Classification</td>
<td>VARCHAR</td>
<td>50</td>
<td> </td>
</tr>
<tr>
<td>CAS registry</td>
<td>LONGINT</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Block</td>
<td>VARCHAR</td>
<td>5</td>
<td>NON_ZERO</td>
</tr>
<tr>
<td>Outer shell</td>
<td>VARCHAR</td>
<td>50</td>
<td> </td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;
&lt;col width=&quot;25%&quot;&gt;&lt;/colgroup&gt;
&lt;thead&gt;
<tr>
<th>Other</th>
<th>Type</th>
<th>Size</th>
<th>Special</th>
</tr>
&lt;/thead&gt;
&lt;tbody&gt;
<tr>
<td>ID</td>
<td>INT</td>
<td> </td>
<td>PRIMARY_KEY (3)</td>
</tr>
<tr>
<td>Discovered</td>
<td>INT</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Colour</td>
<td>VARCHAR</td>
<td>20</td>
<td> </td>
</tr>
<tr>
<td>Oxidation states</td>
<td>VARCHAR</td>
<td>30</td>
<td> </td>
</tr>
<tr>
<td>Allotropes</td>
<td>VARCHAR</td>
<td>200</td>
<td> </td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>At the end of the second table, there is an &quot;others&quot; id. This is
the anchor from which the ID in the Others table is attached. It
would be pointless to try and add further to these tables as they
are pretty much in their clearest format.</p>
<p>VARCHAR has been used for the images. While I could have used
BLOB, using VARCHAR allows me to say, &quot;okay, the URL for the images
is going to be fixed, this is just the filename&quot;.</p>
<p>Finally, I have &quot;Last ordered&quot; set as a DATE which is
ZEROFILLed. This means I can set the date myself which is more
useful than reliance on a TIMESTAMP (useful as it means I can say
that I had the stock before the database was set up!)</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e718" id="d0e718"></a>Creating the
Database</h2>
</div>
<p>Simple enough.</p>
<pre class="screen">
mysql&gt; create database theelements;
mysql&gt; use theelements;
mysql&gt; create table catagoryinfo (
  `id` smallint(6) NOT NULL auto_increment,
  `name` varchar(30) NOT NULL default '',
  `description` varchar(30) NOT NULL default '',
  `image` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`id`)
);

mysql&gt; create table elementinfo (
  `id` longint NOT NULL auto_increment,
  `elementcatagory` int NOT NULL,
  `name` varchar(50) NOT NULL default '',
  `symbol` varchar(5) NOT NULL default '',
  `image` varchar(50) NOT NULL default '',
  `atweight` float(1) NOT NULL,
  `atnumber` int NOT NULL,
  `classification` varchar(50) NOT NULL default '',
  `casreg` longint NOT NULL,
  `block` varchar(5) NOT NULL,
  `outershell` varchar(5) NOT NULL default '',
  PRIMARY KEY  (`id`)
);

mysql&gt; create table other(
  `id` smallint(6) NOT NULL auto_increment,
  `discovered` int NOT NULL,
  `colour` varchar(20) NOT NULL default '',
  `oxstates` varchar(50) NOT NULL default '',
  `allotropes` varchar(200) NOT NULL default '',
  PRIMARY KEY  (`id`)
);
</pre>
<p>That's the tables set. Next stage is to get the data in. As the
datasets are somewhat large for this article, I've placed them on
my website [<a href="#_3">_3</a>] - you will need to grab the file
article1.zip and de-archive it; I would suggest saving it to your
CSD<sup>[<a name="d0e730" href="#ftn.d0e730" id=
"d0e730">2</a>]</sup>. There are three files: catinfo.csv,
elemitems.csv and other.csv. These will need importing into your
database and it is very easy to do.</p>
<pre class="screen">
mysql&gt; LOAD DATA LOCAL infile 'catinfo.csv' INTO TABLE catagoryinfo 
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (id, name, description, image);
</pre>
<p>Repeat for the other files. The only difference being to change
the filename and the contents of the () to reflect the names given
to the table rows. Once imported, you should get the following
message back from the MySQL server</p>
<pre class="screen">
Query OK, 10 rows affected, 0 warnings (0.51 secs)
Records: 10 Deleted: 0 Skipped: 0 Warnings: 0
</pre>
<p>This means the data has been read in happily. A quick test to
show that the data is indeed in the table should confirm this</p>
<pre class="screen">
mysql&gt; select name,description from catagoryinfo;
</pre>
<p>This will display all of the category names and their
descriptions from the catagoryinfo table. Similar tests can be
performed for the other tables.</p>
<p>I'll leave this article at this point. Next time, I'll cover SQL
manual insertion, manual alteration and manual deletion and
introduce the C# command line interface which I will subsequently
be developing.</p>
<p>I must thank the following people for helping me out on this
project:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Paul Grenyer and Patrick De Ridder - both of whom have tested
the compiled binaries under the .NET framework to ensure they have
worked.</p>
</li>
<li>
<p>Novell - for the production and development of Mono [<a href=
"#_4">_4</a>].</p>
</li>
<li>
<p>Steve Hopley - my MySQL tutor at St. Helens College [<a href=
"#_5">_5</a>] and a good friend who helped me design the database
these articles are based on.</p>
</li>
<li>
<p>Dr. Alex Woods - my former Physical Chemistry lecturer at
Liverpool John Moores University, who inspired this due to his
slightly &quot;forgetful&quot; nature.</p>
</li>
<li>
<p>Pippa Hennessy &amp; Laurence Murphy - proof reading.</p>
</li>
</ul>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e772" id=
"d0e772"></a>Disclaimer</h2>
</div>
<p>No furry animals were hurt during the production of this
article. I did step on something while chasing some information,
but it didn't squeak, so I'm not going to count that.</p>
</div>
<div class="bibliography">
<div class="titlepage">
<h2><a name="d0e777" id=
"d0e777"></a>Webliography</h2>
</div>
<div class="bibliomixed"><a name="_1"></a>
<p class="bibliomixed">[_1] <span class="bibliomisc"><a href=
"http://www.mysql.com/products/mysqlcc/" target=
"_top">http://www.mysql.com/products/mysqlcc/</a></span></p>
</div>
<div class="bibliomixed"><a name="_2"></a>
<p class="bibliomixed">[_2] <span class="bibliomisc"><a href=
"http://www.phpmyadmin.net/home_page/" target=
"_top">http://www.phpmyadmin.net/home_page/</a></span></p>
</div>
<div class="bibliomixed"><a name="_3"></a>
<p class="bibliomixed">[_3] <span class="bibliomisc"><a href=
"http://www.all-the-johnsons.co.uk/accu/articles" target=
"_top">http://www.all-the-johnsons.co.uk/accu/articles</a></span></p>
</div>
<div class="bibliomixed"><a name="_4"></a>
<p class="bibliomixed">[_4] Novell. The Mono Project. <span class=
"bibliomisc"><a href="http://www.mono-project.com" target=
"_top">http://www.mono-project.com</a></span></p>
</div>
<div class="bibliomixed"><a name="_5"></a>
<p class="bibliomixed">[_5] St Helens College. <span class=
"bibliomisc"><a href="http://www.sthelens.ac.uk" target=
"_top">http://www.sthelens.ac.uk</a></span></p>
</div>
</div>
<div class="footnotes"><br>
<hr class="c4" width="100">
<div class="footnote">
<p><sup>[<a name="ftn.d0e26" href="#d0e26" id=
"ftn.d0e26">1</a>]</sup> Your definition of fun may vary from that
of the author. The ACCU cannot be held responsible for any
discomfort felt that you may experience in the pursuit of what you
consider fun. Rice pudding does not mix well with electricity, but
is very nice with freshly made blackcurrant and gooseberry jam.</p>
</div>
<div class="footnote">
<p><sup>[<a name="ftn.d0e730" href="#d0e730" id=
"ftn.d0e730">2</a>]</sup> On my Linux machines, that would be
/home/paul. I would suggest for those using Windows using C:\
rather than anywhere else.</p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
