DBUPDATER
=========

version: $Id: dbupdater.txt 581 2003-01-07 12:07:54Z bschuerm $

Sorry in advance for my bad english.

This file describes how to use the database-version updater from the developer-point-of-view


Why a database updater?
=======================

In the developing process of any program, you make changes on the database. 
(e.g. add tables, add fields, alter tables, make modifications like conversion routines...)

Like in Ilias2 this Version of Ilias has such a tool, too.

In Ilias2 one has top write down a small scriptpart and putting it into a (now very large) file.

Here you have a class (class.DBUpdate.php) and a file (sql/dbupdate.php).

The class manages the update-process and outputs information about the current version, file version etc.


How to use the file sql/dbupdate.php
====================================

the file with the database patches is in a proprietary format.

Situation:
You have to make a change in the database. You want to add a table (table1) with 2 columns.
Assume your database's current version is 10.
You have to add the following lines to dbupdate.php:

<#11>
CREATE TABLE table1 (
   ...sqlcode for col 1...
   ...sqlcode for col 2...
);

that's it. If you want to add comments, do it in this way:

# comment for step 11: add some table

There can be more than sql-statement in a section:

<#12>
INSERT INTO table1 ..... ;
INSERT INTO table1 ......;
ALTER TABLE ....... ;

NOTE: you have to add a ";" at every line's end.


The most complicated things are conversions, maybe you want to select all datasets from a table and put them into another table. no problem!
For database things, there are objects $DB and $DB2 for your usage.

<#13>
CREATE TABLE table1 (
   ...sqlcode for col 1...
   ...sqlcode for col 2...
);
<?php
  $r = $DB->query("SELECT * FROM tablex");
  while ($row = $r->fetchRow())
  {
    $DB2->query("INSERT INTO table1 VALUES ($row[0], $row[1])");
  } 
?>

NOTE: you have to begin the php-code with <?php and end it with ?> in a separate line.

THATS ALL!
