mirror of
https://github.com/moodle/moodle.git
synced 2025-01-22 08:11:26 +01:00
06e3c5c030
data dictionary conversion ...
116 lines
4.5 KiB
HTML
116 lines
4.5 KiB
HTML
<H1>adodb-xmlschema</H1>
|
|
<P>Written by <a href="mailto:richtl@arscognita.com">Richard Tango-Lowy</a>.</P>
|
|
<P>For more information, contact <a href="richtl@arscognita.com">richtl@arscognita.com</a>
|
|
or visit our site at <a href="http://www.arscognita.com">www.arscognita.com</a>.</P>
|
|
<P>At the moment, you should report bugs by mailing them to me. (If I can't convince John to
|
|
make this part of ADODB :-), I'll create a project for it on SourceForge.)
|
|
|
|
<H2>Introduction</H2>
|
|
<P><B>adodb-xmlschema</B> is a class that allows the user to quickly and easily
|
|
build a database using the excellent
|
|
<a href="http://php.weblogs.com/ADODB">ADODB database library</a> and a simple
|
|
XML formatted file.</P>
|
|
<P>This library is dual-licensed under a BSD-style license and under the <B><a href="http://opensource.org/licenses/lgpl-license.php">GNU Lesser Public License</a></B>.
|
|
See the <B>LICENSE</B> file for more information.</P>
|
|
|
|
<H2>Features</H2><UL>
|
|
<LI>Darned easy to install
|
|
<LI>Quickly to create schemas that build on any platform supported by ADODB.</UL>
|
|
|
|
<H2>Installation</H2>
|
|
<P>To install adodb-xmlschema, simply copy the <tt>adodb-xmlschema.inc.php</tt> file into your
|
|
<B>ADODB</B> directory.</P>
|
|
|
|
<H2>Quick Start</H2>
|
|
<P>First, create an XML database schema. Let's call it "schema.xml:"</P><PRE>
|
|
<?xml version="1.0"?>
|
|
<schema>
|
|
<table name="mytable">
|
|
<field name="row1" type="I">
|
|
<descr>An integer row that's a primary key and autoincrements</descr>
|
|
<KEY/>
|
|
<AUTOINCREMENT/>
|
|
</field>
|
|
<field name="row2" type="C" size="16">
|
|
<descr>A 16 character varchar row that can't be null</descr>
|
|
<NOTNULL/>
|
|
</field>
|
|
</table>
|
|
<index name="myindex" table="mytable">
|
|
<col>row1</col>
|
|
<col>row2</col>
|
|
</index>
|
|
<sql>
|
|
<descr>SQL to be executed only on specific platforms</descr>
|
|
<query platform="postgres|postgres7">
|
|
insert into mytable ( row1, row2 ) values ( 12, 'stuff' )
|
|
</query>
|
|
<query platform="mysql">
|
|
insert into mytable ( row1, row2 ) values ( 12, 'different stuff' )
|
|
</query>
|
|
</sql>
|
|
</schema>
|
|
</PRE><P>Create a new database using the appropriate tool for your platform.
|
|
Executing the following PHP code will create the a <i>mytable</i> and <i>myindex</i>
|
|
in the database and insert one row into <i>mytable</i> if the platform is postgres or mysql. </P><PRE>
|
|
// To build the schema, start by creating a normal ADOdb connection:
|
|
$db->NewADOConnection( 'mysql' );
|
|
$db->Connect( ... );
|
|
|
|
// Create the schema object and build the query array.
|
|
$schema = <B>new adoSchema</B>( $db );
|
|
|
|
// Build the SQL array
|
|
$sql = $schema-><B>ParseSchema</B>( "schema.xml" );
|
|
|
|
// Execute the SQL on the database
|
|
$result = $schema-><B>ExecuteSchema</B>( $sql );
|
|
|
|
// Finally, clean up after the XML parser
|
|
// (PHP won't do this for you!)
|
|
$schema-><B>Destroy</B>();
|
|
</PRE>
|
|
|
|
<H2>XML Schema Format:</H2>
|
|
<P>(See <a href="../xmlschema.dtd">ADOdb_schema.dtd</a> for the full specification)</P>
|
|
<PRE>
|
|
<?xml version="1.0"?>
|
|
<schema>
|
|
<table name="tablename" platform="platform1|platform2|...">
|
|
<descr>Optional description</descr>
|
|
<field name="fieldname" type="datadict_type" size="size">
|
|
<KEY/>
|
|
<NOTNULL/>
|
|
<AUTOINCREMENT/>
|
|
<DEFAULT value="value"/>
|
|
</field>
|
|
... <i>more fields</i>
|
|
</table>
|
|
... <i>more tables</i>
|
|
|
|
<index name="indexname" platform="platform1|platform2|...">
|
|
<descr>Optional description</descr>
|
|
<col>fieldname</col>
|
|
... <i>more columns</i>
|
|
</index>
|
|
... <i>more indices</i>
|
|
|
|
<sql platform="platform1|platform2|...">
|
|
<descr>Optional description</descr>
|
|
<query platform="platform1|platform2|...">SQL query</query>
|
|
... <i>more queries</i>
|
|
</sql>
|
|
... <i>more SQL</i>
|
|
</schema>
|
|
</PRE>
|
|
<HR>
|
|
<H2>Thanks</H2>
|
|
<P>Thanks to John Lim for giving us ADODB, and for the hard work that keeps it on top of things.
|
|
And particulary for the datadict code that made xmlschema possible.</P>
|
|
<P>And to the kind folks at <a href="http://phpdoc.org">PHP Documentor</a>. Cool tool.</P>
|
|
<P>And to Linus. I thought the end of Amiga was the end of computing. Guess I was wrong :-)</P>
|
|
<HR>
|
|
<address>If you have any questions or comments, please email them to me at
|
|
<a href="mailto:richtl@arscognita.com">richtl@arscognita.com</a>.</address>
|
|
|
|
<P><TT>$Id$</TT></P> |