Initial revision
authorKasper Skårhøj <kasper@typo3.org>
Sun, 28 Mar 2004 12:07:55 +0000 (12:07 +0000)
committerKasper Skårhøj <kasper@typo3.org>
Sun, 28 Mar 2004 12:07:55 +0000 (12:07 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@346 735d13b6-9817-0410-8766-e36946ffe9aa

211 files changed:
typo3/sysext/dbal/DB-1.6.0RC6/DB.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/common.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/dbase.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/fbsql.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/ibase.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/ifx.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/msql.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/mssql.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/mysql.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/mysql4.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/oci8.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/odbc.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/pgsql.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/sqlite.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/storage.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/DB/sybase.php [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/doc/IDEAS [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/doc/MAINTAINERS [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/doc/STATUS [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/doc/TESTERS [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/db_error.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/db_error2.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/db_factory.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/db_ismanip.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/db_parsedsn.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/01connect.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/02fetch.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/03simplequery.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/04numcols.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/05sequences.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/06prepexec.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/08affectedrows.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/09numrows.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/10errormap.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/13limit.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/14fetchmode_object.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/15quote.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/16tableinfo.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/17query.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/18get.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/bug22328.phpt [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/connect.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/mktable.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/setup.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/driver/skipif.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/errors.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/fetchmode_object.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/fetchmodes.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/include.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/limit.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/numcols.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/numrows.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/prepexe.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/sequences.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/simplequery.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/tableinfo.inc [new file with mode: 0755]
typo3/sysext/dbal/DB-1.6.0RC6/tests/transactions.inc [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-csvlib.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-datadict.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-error.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-errorhandler.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-errorpear.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-exceptions.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-iterator.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-lib.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-pager.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-pear.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-perf.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-php4.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-time.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-xmlschema.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb-xmlschema.zip [new file with mode: 0755]
typo3/sysext/dbal/adodb/adodb.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/cute_icons_for_site/adodb.gif [new file with mode: 0755]
typo3/sysext/dbal/adodb/cute_icons_for_site/adodb.png [new file with mode: 0755]
typo3/sysext/dbal/adodb/cute_icons_for_site/adodb2.gif [new file with mode: 0755]
typo3/sysext/dbal/adodb/cute_icons_for_site/adodb2.png [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-access.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-db2.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-generic.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-ibase.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-informix.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-mssql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-mysql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-oci8.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-postgres.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/datadict/datadict-sybase.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/docs-adodb.htm [new file with mode: 0755]
typo3/sysext/dbal/adodb/docs-datadict.htm [new file with mode: 0755]
typo3/sysext/dbal/adodb/docs-perf.htm [new file with mode: 0755]
typo3/sysext/dbal/adodb/docs-session.htm [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-access.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-ado.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-ado_access.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-ado_mssql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-borland_ibase.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-csv.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-db2.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-fbsql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-firebird.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-ibase.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-informix.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-informix72.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-mssql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-mssqlpo.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-mysql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-mysqli.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-mysqlt.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-oci8.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-oci805.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-oci8po.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-odbc.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-odbc_mssql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-odbc_oracle.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-oracle.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-postgres.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-postgres64.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-postgres7.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-proxy.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-sapdb.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-sqlanywhere.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-sqlite.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-sybase.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/drivers/adodb-vfp.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-cn.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-cz.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-de.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-en.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-es.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-fr.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-it.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-pt-br.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-ru1251.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/lang/adodb-sv.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/license.txt [new file with mode: 0755]
typo3/sysext/dbal/adodb/old-changelog.htm [new file with mode: 0755]
typo3/sysext/dbal/adodb/perf/perf-db2.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/perf/perf-informix.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/perf/perf-mssql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/perf/perf-mysql.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/perf/perf-oci8.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/perf/perf-postgres.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/pivottable.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/readme.htm [new file with mode: 0755]
typo3/sysext/dbal/adodb/readme.txt [new file with mode: 0755]
typo3/sysext/dbal/adodb/rsfilter.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/server.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-compress-bzip2.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-compress-gzip.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-cryptsession.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-encrypt-mcrypt.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-encrypt-md5.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-encrypt-secret.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-sess.txt [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-session-clob.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-session.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-sessions.mysql.sql [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-sessions.oracle.clob.sql [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/adodb-sessions.oracle.sql [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/crypt.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/old/adodb-cryptsession.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/old/adodb-session-clob.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/old/adodb-session.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/session/old/crypt.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/benchmark.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/client.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test-datadict.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test-perf.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test-pgblob.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test-php5.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test-xmlschema.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test2.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test3.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test4.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test5.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/test_rs_array.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testcache.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testdatabases.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testgenid.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testmssql.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testoci8.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testoci8cursor.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testpaging.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testpear.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/testsessions.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/time.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/tmssql.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tests/xmlschema.xml [new file with mode: 0755]
typo3/sysext/dbal/adodb/tips_portable_sql.htm [new file with mode: 0755]
typo3/sysext/dbal/adodb/toexport.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tohtml.inc.php [new file with mode: 0755]
typo3/sysext/dbal/adodb/tute.htm [new file with mode: 0755]
typo3/sysext/dbal/class.ux_t3lib_db.php [new file with mode: 0755]
typo3/sysext/dbal/doc/TODO.txt [new file with mode: 0755]
typo3/sysext/dbal/doc/manual.sxw [new file with mode: 0755]
typo3/sysext/dbal/ext_emconf.php [new file with mode: 0755]
typo3/sysext/dbal/ext_icon.gif [new file with mode: 0755]
typo3/sysext/dbal/ext_localconf.php [new file with mode: 0755]
typo3/sysext/dbal/ext_php_api.dat [new file with mode: 0755]
typo3/sysext/dbal/ext_tables.php [new file with mode: 0755]
typo3/sysext/dbal/ext_tables.sql [new file with mode: 0755]
typo3/sysext/dbal/handlers/class.tx_dbal_handler_openoffice.php [new file with mode: 0755]
typo3/sysext/dbal/handlers/class.tx_dbal_handler_rawmysql.php [new file with mode: 0755]
typo3/sysext/dbal/handlers/class.tx_dbal_handler_xmldb.php [new file with mode: 0755]
typo3/sysext/dbal/mod1/clear.gif [new file with mode: 0755]
typo3/sysext/dbal/mod1/conf.php [new file with mode: 0755]
typo3/sysext/dbal/mod1/index.php [new file with mode: 0755]
typo3/sysext/dbal/mod1/locallang.php [new file with mode: 0755]
typo3/sysext/dbal/mod1/locallang_mod.php [new file with mode: 0755]
typo3/sysext/dbal/mod1/moduleicon.gif [new file with mode: 0755]

diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB.php
new file mode 100755 (executable)
index 0000000..9a80cb7
--- /dev/null
@@ -0,0 +1,1105 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Authors: Stig Bakken <ssb@php.net>                                   |
+// |          Tomas V.V.Cox <cox@idecnet.com>                             |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+//
+// Database independent query interface.
+
+
+require_once 'PEAR.php';
+
+// {{{ constants
+// {{{ error codes
+
+/*
+ * The method mapErrorCode in each DB_dbtype implementation maps
+ * native error codes to one of these.
+ *
+ * If you add an error code here, make sure you also add a textual
+ * version of it in DB::errorMessage().
+ */
+define('DB_OK',                         1);
+define('DB_ERROR',                     -1);
+define('DB_ERROR_SYNTAX',              -2);
+define('DB_ERROR_CONSTRAINT',          -3);
+define('DB_ERROR_NOT_FOUND',           -4);
+define('DB_ERROR_ALREADY_EXISTS',      -5);
+define('DB_ERROR_UNSUPPORTED',         -6);
+define('DB_ERROR_MISMATCH',            -7);
+define('DB_ERROR_INVALID',             -8);
+define('DB_ERROR_NOT_CAPABLE',         -9);
+define('DB_ERROR_TRUNCATED',          -10);
+define('DB_ERROR_INVALID_NUMBER',     -11);
+define('DB_ERROR_INVALID_DATE',       -12);
+define('DB_ERROR_DIVZERO',            -13);
+define('DB_ERROR_NODBSELECTED',       -14);
+define('DB_ERROR_CANNOT_CREATE',      -15);
+define('DB_ERROR_CANNOT_DELETE',      -16);
+define('DB_ERROR_CANNOT_DROP',        -17);
+define('DB_ERROR_NOSUCHTABLE',        -18);
+define('DB_ERROR_NOSUCHFIELD',        -19);
+define('DB_ERROR_NEED_MORE_DATA',     -20);
+define('DB_ERROR_NOT_LOCKED',         -21);
+define('DB_ERROR_VALUE_COUNT_ON_ROW', -22);
+define('DB_ERROR_INVALID_DSN',        -23);
+define('DB_ERROR_CONNECT_FAILED',     -24);
+define('DB_ERROR_EXTENSION_NOT_FOUND',-25);
+define('DB_ERROR_ACCESS_VIOLATION',   -26);
+define('DB_ERROR_NOSUCHDB',           -27);
+
+
+// }}}
+// {{{ prepared statement-related
+
+
+/*
+ * These constants are used when storing information about prepared
+ * statements (using the "prepare" method in DB_dbtype).
+ *
+ * The prepare/execute model in DB is mostly borrowed from the ODBC
+ * extension, in a query the "?" character means a scalar parameter.
+ * There are two extensions though, a "&" character means an opaque
+ * parameter.  An opaque parameter is simply a file name, the real
+ * data are in that file (useful for putting uploaded files into your
+ * database and such). The "!" char means a parameter that must be
+ * left as it is.
+ * They modify the quote behavoir:
+ * DB_PARAM_SCALAR (?) => 'original string quoted'
+ * DB_PARAM_OPAQUE (&) => 'string from file quoted'
+ * DB_PARAM_MISC   (!) => original string
+ */
+define('DB_PARAM_SCALAR', 1);
+define('DB_PARAM_OPAQUE', 2);
+define('DB_PARAM_MISC',   3);
+
+
+// }}}
+// {{{ binary data-related
+
+
+/*
+ * These constants define different ways of returning binary data
+ * from queries.  Again, this model has been borrowed from the ODBC
+ * extension.
+ *
+ * DB_BINMODE_PASSTHRU sends the data directly through to the browser
+ * when data is fetched from the database.
+ * DB_BINMODE_RETURN lets you return data as usual.
+ * DB_BINMODE_CONVERT returns data as well, only it is converted to
+ * hex format, for example the string "123" would become "313233".
+ */
+define('DB_BINMODE_PASSTHRU', 1);
+define('DB_BINMODE_RETURN',   2);
+define('DB_BINMODE_CONVERT',  3);
+
+
+// }}}
+// {{{ fetch modes
+
+
+/**
+ * This is a special constant that tells DB the user hasn't specified
+ * any particular get mode, so the default should be used.
+ */
+define('DB_FETCHMODE_DEFAULT', 0);
+
+/**
+ * Column data indexed by numbers, ordered from 0 and up
+ */
+define('DB_FETCHMODE_ORDERED', 1);
+
+/**
+ * Column data indexed by column names
+ */
+define('DB_FETCHMODE_ASSOC', 2);
+
+/**
+ * Column data as object properties
+ */
+define('DB_FETCHMODE_OBJECT', 3);
+
+/**
+ * For multi-dimensional results: normally the first level of arrays
+ * is the row number, and the second level indexed by column number or name.
+ * DB_FETCHMODE_FLIPPED switches this order, so the first level of arrays
+ * is the column name, and the second level the row number.
+ */
+define('DB_FETCHMODE_FLIPPED', 4);
+
+/* for compatibility */
+define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
+define('DB_GETMODE_ASSOC',   DB_FETCHMODE_ASSOC);
+define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
+
+
+// }}}
+// {{{ tableInfo() && autoPrepare()-related
+
+
+/**
+ * these are constants for the tableInfo-function
+ * they are bitwised or'ed. so if there are more constants to be defined
+ * in the future, adjust DB_TABLEINFO_FULL accordingly
+ */
+define('DB_TABLEINFO_ORDER', 1);
+define('DB_TABLEINFO_ORDERTABLE', 2);
+define('DB_TABLEINFO_FULL', 3);
+
+/*
+ * Used by autoPrepare()
+ */
+define('DB_AUTOQUERY_INSERT', 1);
+define('DB_AUTOQUERY_UPDATE', 2);
+
+
+// }}}
+// {{{ portability modes
+
+
+/**
+ * Portability: turn off all portability features.
+ * @see DB_common::setOption()
+ */
+define('DB_PORTABILITY_NONE', 0);
+
+/**
+ * Portability: convert names of tables and fields to lower case
+ * when using the get*(), fetch*() and tableInfo() methods.
+ * @see DB_common::setOption()
+ */
+define('DB_PORTABILITY_LOWERCASE', 1);
+
+/**
+ * Portability: right trim the data output by get*() and fetch*().
+ * @see DB_common::setOption()
+ */
+define('DB_PORTABILITY_RTRIM', 2);
+
+/**
+ * Portability: force reporting the number of rows deleted.
+ * @see DB_common::setOption()
+ */
+define('DB_PORTABILITY_DELETE_COUNT', 4);
+
+/**
+ * Portability: enable hack that makes numRows() work in Oracle.
+ * @see DB_common::setOption()
+ */
+define('DB_PORTABILITY_NUMROWS', 8);
+
+/**
+ * Portability: makes certain error messages in certain drivers compatible
+ * with those from other DBMS's.
+ *
+ * + mysql, mysql4:  change unique/primary key constraints
+ *   DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
+ *
+ * + odbc(access):  MS's ODBC driver reports 'no such field' as code
+ *   07001, which means 'too few parameters.'  When this option is on
+ *   that code gets mapped to DB_ERROR_NOSUCHFIELD.
+ *
+ * @see DB_common::setOption()
+ */
+define('DB_PORTABILITY_ERRORS', 16);
+
+/**
+ * Portability: turn on all portability features.
+ * @see DB_common::setOption()
+ */
+define('DB_PORTABILITY_ALL', 31);
+
+// }}}
+
+
+// }}}
+// {{{ class DB
+
+/**
+ * The main "DB" class is simply a container class with some static
+ * methods for creating DB objects as well as some utility functions
+ * common to all parts of DB.
+ *
+ * The object model of DB is as follows (indentation means inheritance):
+ *
+ * DB           The main DB class.  This is simply a utility class
+ *              with some "static" methods for creating DB objects as
+ *              well as common utility functions for other DB classes.
+ *
+ * DB_common    The base for each DB implementation.  Provides default
+ * |            implementations (in OO lingo virtual methods) for
+ * |            the actual DB implementations as well as a bunch of
+ * |            query utility functions.
+ * |
+ * +-DB_mysql   The DB implementation for MySQL.  Inherits DB_common.
+ *              When calling DB::factory or DB::connect for MySQL
+ *              connections, the object returned is an instance of this
+ *              class.
+ *
+ * @package  DB
+ * @author   Stig Bakken <ssb@php.net>
+ * @author   Tomas V.V.Cox <cox@idecnet.com>
+ * @since    PHP 4.0
+ * @version  $Id$
+ * @category Database
+ */
+class DB
+{
+    // {{{ &factory()
+
+    /**
+     * Create a new DB object for the specified database type.
+     *
+     * Allows creation of a DB_<driver> object from which the object's
+     * methods can be utilized without actually connecting to a database.
+     *
+     * @param string $type    database type, for example "mysql"
+     * @param array  $options associative array of option names and values
+     *
+     * @return object  a new DB object.  On error, an error object.
+     *
+     * @see DB_common::setOption()
+     * @access public
+     */
+    function &factory($type, $options = false)
+    {
+        if (!is_array($options)) {
+            $options = array('persistent' => $options);
+        }
+
+        if (isset($options['debug']) && $options['debug'] >= 2) {
+            // expose php errors with sufficient debug level
+            include_once "DB/{$type}.php";
+        } else {
+            @include_once "DB/{$type}.php";
+        }
+
+        $classname = "DB_${type}";
+
+        if (!class_exists($classname)) {
+            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
+                                    "Unable to include the DB/{$type}.php file",
+                                    'DB_Error', true);
+            return $tmp;
+        }
+
+        @$obj =& new $classname;
+
+        foreach ($options as $option => $value) {
+            $test = $obj->setOption($option, $value);
+            if (DB::isError($test)) {
+                return $test;
+            }
+        }
+
+        return $obj;
+    }
+
+    // }}}
+    // {{{ &connect()
+
+    /**
+     * Create a new DB object and connect to the specified database.
+     *
+     * Example 1.
+     * <code> <?php
+     * require_once 'DB.php';
+     *
+     * $dsn = 'mysql://user:password@host/database'
+     * $options = array(
+     *     'debug'       => 2,
+     *     'portability' => DB_PORTABILITY_ALL,
+     * );
+     *
+     * $dbh =& DB::connect($dsn, $options);
+     * if (DB::isError($dbh)) {
+     *     die($dbh->getMessage());
+     * }
+     * ?></code>
+     *
+     * @param mixed $dsn      string "data source name" or an array in the
+     *                        format returned by DB::parseDSN()
+     *
+     * @param array $options  an associative array of option names and
+     *                        their values
+     *
+     * @return object  a newly created DB connection object, or a DB
+     *                 error object on error
+     *
+     * @see DB::parseDSN(), DB_common::setOption(), DB::isError()
+     * @access public
+     */
+    function &connect($dsn, $options = array())
+    {
+        $dsninfo = DB::parseDSN($dsn);
+        $type = $dsninfo['phptype'];
+
+        if (!is_array($options)) {
+            /*
+             * For backwards compatibility.  $options used to be boolean,
+             * indicating whether the connection should be persistent.
+             */
+            $options = array('persistent' => $options);
+        }
+
+        if (isset($options['debug']) && $options['debug'] >= 2) {
+            // expose php errors with sufficient debug level
+            include_once "DB/${type}.php";
+        } else {
+            @include_once "DB/${type}.php";
+        }
+
+        $classname = "DB_${type}";
+        if (!class_exists($classname)) {
+            $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null,
+                                    "Unable to include the DB/{$type}.php file for `$dsn'",
+                                    'DB_Error', true);
+            return $tmp;
+        }
+
+        @$obj =& new $classname;
+
+        foreach ($options as $option => $value) {
+            $test = $obj->setOption($option, $value);
+            if (DB::isError($test)) {
+                return $test;
+            }
+        }
+
+        $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
+        if (DB::isError($err)) {
+            $err->addUserInfo($dsn);
+            return $err;
+        }
+
+        return $obj;
+    }
+
+    // }}}
+    // {{{ apiVersion()
+
+    /**
+     * Return the DB API version
+     *
+     * @return int the DB API version number
+     *
+     * @access public
+     */
+    function apiVersion()
+    {
+        return 2;
+    }
+
+    // }}}
+    // {{{ isError()
+
+    /**
+     * Tell whether a result code from a DB method is an error
+     *
+     * @param int $value result code
+     *
+     * @return bool whether $value is an error
+     *
+     * @access public
+     */
+    function isError($value)
+    {
+        return is_a($value, 'DB_Error');
+    }
+
+    // }}}
+    // {{{ isConnection()
+
+    /**
+     * Tell whether a value is a DB connection
+     *
+     * @param mixed $value value to test
+     *
+     * @return bool whether $value is a DB connection
+     *
+     * @access public
+     */
+    function isConnection($value)
+    {
+        return (is_object($value) &&
+                is_subclass_of($value, 'db_common') &&
+                method_exists($value, 'simpleQuery'));
+    }
+
+    // }}}
+    // {{{ isManip()
+
+    /**
+     * Tell whether a query is a data manipulation query (insert,
+     * update or delete) or a data definition query (create, drop,
+     * alter, grant, revoke).
+     *
+     * @access public
+     *
+     * @param string $query the query
+     *
+     * @return boolean whether $query is a data manipulation query
+     */
+    function isManip($query)
+    {
+        $manips = 'INSERT|UPDATE|DELETE|'.'REPLACE|CREATE|DROP|'.
+                  'ALTER|GRANT|REVOKE|'.'LOCK|UNLOCK';
+        if (preg_match('/^\s*"?('.$manips.')\s+/i', $query)) {
+            return true;
+        }
+        return false;
+    }
+
+    // }}}
+    // {{{ errorMessage()
+
+    /**
+     * Return a textual error message for a DB error code
+     *
+     * @param integer $value error code
+     *
+     * @return string error message, or false if the error code was
+     * not recognized
+     */
+    function errorMessage($value)
+    {
+        static $errorMessages;
+        if (!isset($errorMessages)) {
+            $errorMessages = array(
+                DB_ERROR                    => 'unknown error',
+                DB_ERROR_ALREADY_EXISTS     => 'already exists',
+                DB_ERROR_CANNOT_CREATE      => 'can not create',
+                DB_ERROR_CANNOT_DELETE      => 'can not delete',
+                DB_ERROR_CANNOT_DROP        => 'can not drop',
+                DB_ERROR_CONSTRAINT         => 'constraint violation',
+                DB_ERROR_DIVZERO            => 'division by zero',
+                DB_ERROR_INVALID            => 'invalid',
+                DB_ERROR_INVALID_DATE       => 'invalid date or time',
+                DB_ERROR_INVALID_NUMBER     => 'invalid number',
+                DB_ERROR_MISMATCH           => 'mismatch',
+                DB_ERROR_NODBSELECTED       => 'no database selected',
+                DB_ERROR_NOSUCHFIELD        => 'no such field',
+                DB_ERROR_NOSUCHTABLE        => 'no such table',
+                DB_ERROR_NOT_CAPABLE        => 'DB backend not capable',
+                DB_ERROR_NOT_FOUND          => 'not found',
+                DB_ERROR_NOT_LOCKED         => 'not locked',
+                DB_ERROR_SYNTAX             => 'syntax error',
+                DB_ERROR_UNSUPPORTED        => 'not supported',
+                DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
+                DB_ERROR_INVALID_DSN        => 'invalid DSN',
+                DB_ERROR_CONNECT_FAILED     => 'connect failed',
+                DB_OK                       => 'no error',
+                DB_ERROR_NEED_MORE_DATA     => 'insufficient data supplied',
+                DB_ERROR_EXTENSION_NOT_FOUND=> 'extension not found',
+                DB_ERROR_NOSUCHDB           => 'no such database',
+                DB_ERROR_ACCESS_VIOLATION   => 'insufficient permissions',
+                DB_ERROR_TRUNCATED          => 'truncated'
+            );
+        }
+
+        if (DB::isError($value)) {
+            $value = $value->getCode();
+        }
+
+        return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[DB_ERROR];
+    }
+
+    // }}}
+    // {{{ parseDSN()
+
+    /**
+     * Parse a data source name.
+     *
+     * Additional keys can be added by appending a URI query string to the
+     * end of the DSN.
+     *
+     * The format of the supplied DSN is in its fullest form:
+     * <code>
+     *  phptype(dbsyntax)://username:password@protocol+hostspec/database?option=8&another=true
+     * </code>
+     *
+     * Most variations are allowed:
+     * <code>
+     *  phptype://username:password@protocol+hostspec:110//usr/db_file.db?mode=0644
+     *  phptype://username:password@hostspec/database_name
+     *  phptype://username:password@hostspec
+     *  phptype://username@hostspec
+     *  phptype://hostspec/database
+     *  phptype://hostspec
+     *  phptype(dbsyntax)
+     *  phptype
+     * </code>
+     *
+     * @param string $dsn Data Source Name to be parsed
+     *
+     * @return array an associative array with the following keys:
+     *  + phptype:  Database backend used in PHP (mysql, odbc etc.)
+     *  + dbsyntax: Database used with regards to SQL syntax etc.
+     *  + protocol: Communication protocol to use (tcp, unix etc.)
+     *  + hostspec: Host specification (hostname[:port])
+     *  + database: Database to use on the DBMS server
+     *  + username: User name for login
+     *  + password: Password for login
+     *
+     * @author Tomas V.V.Cox <cox@idecnet.com>
+     */
+    function parseDSN($dsn)
+    {
+        $parsed = array(
+            'phptype'  => false,
+            'dbsyntax' => false,
+            'username' => false,
+            'password' => false,
+            'protocol' => false,
+            'hostspec' => false,
+            'port'     => false,
+            'socket'   => false,
+            'database' => false,
+        );
+
+        if (is_array($dsn)) {
+            $dsn = array_merge($parsed, $dsn);
+            if (!$dsn['dbsyntax']) {
+                $dsn['dbsyntax'] = $dsn['phptype'];
+            }
+            return $dsn;
+        }
+
+        // Find phptype and dbsyntax
+        if (($pos = strpos($dsn, '://')) !== false) {
+            $str = substr($dsn, 0, $pos);
+            $dsn = substr($dsn, $pos + 3);
+        } else {
+            $str = $dsn;
+            $dsn = NULL;
+        }
+
+        // Get phptype and dbsyntax
+        // $str => phptype(dbsyntax)
+        if (preg_match('|^(.+?)\((.*?)\)$|', $str, $arr)) {
+            $parsed['phptype']  = $arr[1];
+            $parsed['dbsyntax'] = !$arr[2] ? $arr[1] : $arr[2];
+        } else {
+            $parsed['phptype']  = $str;
+            $parsed['dbsyntax'] = $str;
+        }
+
+        if (!count($dsn)) {
+            return $parsed;
+        }
+
+        // Get (if found): username and password
+        // $dsn => username:password@protocol+hostspec/database
+        if (($at = strrpos($dsn,'@')) !== false) {
+            $str = substr($dsn, 0, $at);
+            $dsn = substr($dsn, $at + 1);
+            if (($pos = strpos($str, ':')) !== false) {
+                $parsed['username'] = rawurldecode(substr($str, 0, $pos));
+                $parsed['password'] = rawurldecode(substr($str, $pos + 1));
+            } else {
+                $parsed['username'] = rawurldecode($str);
+            }
+        }
+
+        // Find protocol and hostspec
+
+        // $dsn => proto(proto_opts)/database
+        if (preg_match('|^([^(]+)\((.*?)\)/?(.*?)$|', $dsn, $match)) {
+            $proto       = $match[1];
+            $proto_opts  = $match[2] ? $match[2] : false;
+            $dsn         = $match[3];
+
+        // $dsn => protocol+hostspec/database (old format)
+        } else {
+            if (strpos($dsn, '+') !== false) {
+                list($proto, $dsn) = explode('+', $dsn, 2);
+            }
+            if (strpos($dsn, '/') !== false) {
+                list($proto_opts, $dsn) = explode('/', $dsn, 2);
+            } else {
+                $proto_opts = $dsn;
+                $dsn = null;
+            }
+        }
+
+        // process the different protocol options
+        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp';
+        $proto_opts = rawurldecode($proto_opts);
+        if ($parsed['protocol'] == 'tcp') {
+            if (strpos($proto_opts, ':') !== false) {
+                list($parsed['hostspec'], $parsed['port']) = explode(':', $proto_opts);
+            } else {
+                $parsed['hostspec'] = $proto_opts;
+            }
+        } elseif ($parsed['protocol'] == 'unix') {
+            $parsed['socket'] = $proto_opts;
+        }
+
+        // Get dabase if any
+        // $dsn => database
+        if ($dsn) {
+            // /database
+            if (($pos = strpos($dsn, '?')) === false) {
+                $parsed['database'] = $dsn;
+            // /database?param1=value1&param2=value2
+            } else {
+                $parsed['database'] = substr($dsn, 0, $pos);
+                $dsn = substr($dsn, $pos + 1);
+                if (strpos($dsn, '&') !== false) {
+                    $opts = explode('&', $dsn);
+                } else { // database?param1=value1
+                    $opts = array($dsn);
+                }
+                foreach ($opts as $opt) {
+                    list($key, $value) = explode('=', $opt);
+                    if (!isset($parsed[$key])) {
+                        // don't allow params overwrite
+                        $parsed[$key] = rawurldecode($value);
+                    }
+                }
+            }
+        }
+
+        return $parsed;
+    }
+
+    // }}}
+    // {{{ assertExtension()
+
+    /**
+     * Load a PHP database extension if it is not loaded already.
+     *
+     * @access public
+     *
+     * @param string $name the base name of the extension (without the .so or
+     *                     .dll suffix)
+     *
+     * @return boolean true if the extension was already or successfully
+     *                 loaded, false if it could not be loaded
+     */
+    function assertExtension($name)
+    {
+        if (!extension_loaded($name)) {
+            $dlext = OS_WINDOWS ? '.dll' : '.so';
+            $dlprefix = OS_WINDOWS ? 'php_' : '';
+            @dl($dlprefix . $name . $dlext);
+            return extension_loaded($name);
+        }
+        return true;
+    }
+    // }}}
+}
+
+// }}}
+// {{{ class DB_Error
+
+/**
+ * DB_Error implements a class for reporting portable database error
+ * messages.
+ *
+ * @package  DB
+ * @author Stig Bakken <ssb@php.net>
+ */
+class DB_Error extends PEAR_Error
+{
+    // {{{ constructor
+
+    /**
+     * DB_Error constructor.
+     *
+     * @param mixed   $code   DB error code, or string with error message.
+     * @param integer $mode   what "error mode" to operate in
+     * @param integer $level  what error level to use for $mode & PEAR_ERROR_TRIGGER
+     * @param mixed   $debuginfo  additional debug info, such as the last query
+     *
+     * @access public
+     *
+     * @see PEAR_Error
+     */
+    function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
+              $level = E_USER_NOTICE, $debuginfo = null)
+    {
+        if (is_int($code)) {
+            $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
+        } else {
+            $this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo);
+        }
+    }
+    // }}}
+}
+
+// }}}
+// {{{ class DB_result
+
+/**
+ * This class implements a wrapper for a DB result set.
+ * A new instance of this class will be returned by the DB implementation
+ * after processing a query that returns data.
+ *
+ * @package  DB
+ * @author Stig Bakken <ssb@php.net>
+ */
+class DB_result
+{
+    // {{{ properties
+
+    var $dbh;
+    var $result;
+    var $row_counter = null;
+
+    /**
+     * for limit queries, the row to start fetching
+     * @var integer
+     */
+    var $limit_from  = null;
+
+    /**
+     * for limit queries, the number of rows to fetch
+     * @var integer
+     */
+    var $limit_count = null;
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * DB_result constructor.
+     * @param resource &$dbh   DB object reference
+     * @param resource $result  result resource id
+     * @param array    $options assoc array with optional result options
+     */
+    function DB_result(&$dbh, $result, $options = array())
+    {
+        $this->dbh = &$dbh;
+        $this->result = $result;
+        foreach ($options as $key => $value) {
+            $this->setOption($key, $value);
+        }
+        $this->limit_type  = $dbh->features['limit'];
+        $this->autofree    = $dbh->options['autofree'];
+        $this->fetchmode   = $dbh->fetchmode;
+        $this->fetchmode_object_class = $dbh->fetchmode_object_class;
+    }
+
+    function setOption($key, $value = null)
+    {
+        switch ($key) {
+            case 'limit_from':
+                $this->limit_from = $value; break;
+            case 'limit_count':
+                $this->limit_count = $value; break;
+        }
+    }
+
+    // }}}
+    // {{{ fetchRow()
+
+    /**
+     * Fetch a row of data and return it by reference into an array.
+     *
+     * The type of array returned can be controlled either by setting this
+     * method's <var>$fetchmode</var> parameter or by changing the default
+     * fetch mode setFetchMode() before calling this method.
+     *
+     * There are two options for standardizing the information returned
+     * from databases, ensuring their values are consistent when changing
+     * DBMS's.  These portability options can be turned on when creating a
+     * new DB object or by using setOption().
+     *
+     *   + <samp>DB_PORTABILITY_LOWERCASE</samp>
+     *     convert names of fields to lower case
+     *
+     *   + <samp>DB_PORTABILITY_RTRIM</samp>
+     *     right trim the data
+     *
+     * @param int $fetchmode  how the resulting array should be indexed
+     * @param int $rownum     the row number to fetch
+     *
+     * @return array  a row of data, NULL on no more rows or PEAR_Error
+     *                object on error
+     *
+     * @see DB_common::setOption(), DB_common::setFetchMode()
+     * @access public
+     */
+    function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
+    {
+        if ($fetchmode === DB_FETCHMODE_DEFAULT) {
+            $fetchmode = $this->fetchmode;
+        }
+        if ($fetchmode === DB_FETCHMODE_OBJECT) {
+            $fetchmode = DB_FETCHMODE_ASSOC;
+            $object_class = $this->fetchmode_object_class;
+        }
+        if ($this->limit_from !== null) {
+            if ($this->row_counter === null) {
+                $this->row_counter = $this->limit_from;
+                // Skip rows
+                if ($this->limit_type == false) {
+                    $i = 0;
+                    while ($i++ < $this->limit_from) {
+                        $this->dbh->fetchInto($this->result, $arr, $fetchmode);
+                    }
+                }
+            }
+            if ($this->row_counter >= (
+                    $this->limit_from + $this->limit_count))
+            {
+                if ($this->autofree) {
+                    $this->free();
+                }
+                $tmp = null;
+                return $tmp;
+            }
+            if ($this->limit_type == 'emulate') {
+                $rownum = $this->row_counter;
+            }
+            $this->row_counter++;
+        }
+        $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
+        if ($res === DB_OK) {
+            if (isset($object_class)) {
+                // default mode specified in DB_common::fetchmode_object_class property
+                if ($object_class == 'stdClass') {
+                    $arr = (object) $arr;
+                } else {
+                    $arr = &new $object_class($arr);
+                }
+            }
+            return $arr;
+        }
+        if ($res == null && $this->autofree) {
+            $this->free();
+        }
+        return $res;
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row of data into an array which is passed by reference.
+     *
+     * The type of array returned can be controlled either by setting this
+     * method's <var>$fetchmode</var> parameter or by changing the default
+     * fetch mode setFetchMode() before calling this method.
+     *
+     * There are two options for standardizing the information returned
+     * from databases, ensuring their values are consistent when changing
+     * DBMS's.  These portability options can be turned on when creating a
+     * new DB object or by using setOption().
+     *
+     *   + <samp>DB_PORTABILITY_LOWERCASE</samp>
+     *     convert names of fields to lower case
+     *
+     *   + <samp>DB_PORTABILITY_RTRIM</samp>
+     *     right trim the data
+     *
+     * @param array &$arr       (reference) array where data from the row
+     *                          should be placed
+     * @param int   $fetchmode  how the resulting array should be indexed
+     * @param int   $rownum     the row number to fetch
+     *
+     * @return mixed  DB_OK on success, NULL on no more rows or
+     *                a DB_Error object on error
+     *
+     * @see DB_common::setOption(), DB_common::setFetchMode()
+     * @access public
+     */
+    function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
+    {
+        if ($fetchmode === DB_FETCHMODE_DEFAULT) {
+            $fetchmode = $this->fetchmode;
+        }
+        if ($fetchmode === DB_FETCHMODE_OBJECT) {
+            $fetchmode = DB_FETCHMODE_ASSOC;
+            $object_class = $this->fetchmode_object_class;
+        }
+        if ($this->limit_from !== null) {
+            if ($this->row_counter === null) {
+                $this->row_counter = $this->limit_from;
+                // Skip rows
+                if ($this->limit_type == false) {
+                    $i = 0;
+                    while ($i++ < $this->limit_from) {
+                        $this->dbh->fetchInto($this->result, $arr, $fetchmode);
+                    }
+                }
+            }
+            if ($this->row_counter >= (
+                    $this->limit_from + $this->limit_count))
+            {
+                if ($this->autofree) {
+                    $this->free();
+                }
+                return null;
+            }
+            if ($this->limit_type == 'emulate') {
+                $rownum = $this->row_counter;
+            }
+
+            $this->row_counter++;
+        }
+        $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
+        if ($res === DB_OK) {
+            if (isset($object_class)) {
+                // default mode specified in DB_common::fetchmode_object_class property
+                if ($object_class == 'stdClass') {
+                    $arr = (object) $arr;
+                } else {
+                    $arr = new $object_class($arr);
+                }
+            }
+            return DB_OK;
+        }
+        if ($res == null && $this->autofree) {
+            $this->free();
+        }
+        return $res;
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    /**
+     * Get the the number of columns in a result set.
+     *
+     * @return int the number of columns, or a DB error
+     *
+     * @access public
+     */
+    function numCols()
+    {
+        return $this->dbh->numCols($this->result);
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    /**
+     * Get the number of rows in a result set.
+     *
+     * @return int the number of rows, or a DB error
+     *
+     * @access public
+     */
+    function numRows()
+    {
+        return $this->dbh->numRows($this->result);
+    }
+
+    // }}}
+    // {{{ nextResult()
+
+    /**
+     * Get the next result if a batch of queries was executed.
+     *
+     * @return bool true if a new result is available or false if not.
+     *
+     * @access public
+     */
+    function nextResult()
+    {
+        return $this->dbh->nextResult($this->result);
+    }
+
+    // }}}
+    // {{{ free()
+
+    /**
+     * Frees the resources allocated for this result set.
+     * @return  int error code
+     *
+     * @access public
+     */
+    function free()
+    {
+        $err = $this->dbh->freeResult($this->result);
+        if(DB::isError($err)) {
+            return $err;
+        }
+        $this->result = false;
+        return true;
+    }
+
+    // }}}
+    // {{{ tableInfo()
+
+    /**
+     * @deprecated
+     * @internal
+     * @see DB_common::tableInfo()
+     */
+    function tableInfo($mode = null)
+    {
+        if (is_string($mode)) {
+            return $this->dbh->raiseError(DB_ERROR_NEED_MORE_DATA);
+        }
+        return $this->dbh->tableInfo($this, $mode);
+    }
+
+    // }}}
+    // {{{ getRowCounter()
+
+    /**
+     * returns the actual row number
+     * @return integer
+     */
+    function getRowCounter()
+    {
+        return $this->row_counter;
+    }
+    // }}}
+}
+
+// }}}
+// {{{ class DB_Row
+
+/**
+ * Pear DB Row Object
+ * @see DB_common::setFetchMode()
+ */
+class DB_row
+{
+    // {{{ constructor
+
+    /**
+     * constructor
+     *
+     * @param resource row data as array
+     */
+    function DB_row(&$arr)
+    {
+        foreach ($arr as $key => $value) {
+            $this->$key = &$arr[$key];
+        }
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/common.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/common.php
new file mode 100755 (executable)
index 0000000..c917133
--- /dev/null
@@ -0,0 +1,1998 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Stig Bakken <ssb@php.net>                                    |
+// |         Tomas V.V.Cox <cox@idecnet.com>                              |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+require_once 'PEAR.php';
+
+/**
+ * DB_common is a base class for DB implementations, and must be
+ * inherited by all such
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Stig Bakken <ssb@php.net>
+ * @author   Tomas V.V.Cox <cox@idecnet.com>
+ */
+class DB_common extends PEAR
+{
+    // {{{ properties
+
+    /**
+     * assoc of capabilities for this DB implementation
+     * $features['limit'] =>  'emulate' => emulate with fetch row by number
+     *                        'alter'   => alter the query
+     *                        false     => skip rows
+     * @var array
+     */
+    var $features = array();
+
+    /**
+     * assoc mapping native error codes to DB ones
+     * @var array
+     */
+    var $errorcode_map = array();
+
+    /**
+     * DB type (mysql, oci8, odbc etc.)
+     * @var string
+     */
+    var $phptype;
+
+    /**
+     * @var string
+     */
+    var $prepare_tokens;
+
+    /**
+     * @var string
+     */
+    var $prepare_types;
+
+    /**
+     * @var string
+     */
+    var $prepared_queries;
+
+    /**
+     * @var integer
+     */
+    var $prepare_maxstmt = 0;
+
+    /**
+     * @var string
+     */
+    var $last_query = '';
+
+    /**
+     * @var integer
+     */
+    var $fetchmode = DB_FETCHMODE_ORDERED;
+
+    /**
+     * @var string
+     */
+    var $fetchmode_object_class = 'stdClass';
+
+    /**
+     * Run-time configuration options.
+     *
+     * The 'optimize' option has been deprecated.  Use the 'portability'
+     * option instead.
+     *
+     * @see DB_common::setOption()
+     * @var array
+     */
+    var $options = array(
+        'persistent' => false,
+        'ssl' => false,
+        'debug' => 0,
+        'seqname_format' => '%s_seq',
+        'autofree' => false,
+        'portability' => DB_PORTABILITY_NONE,
+        'optimize' => 'performance',  // Deprecated.  Use 'portability'.
+    );
+
+    /**
+     * DB handle
+     * @var resource
+     */
+    var $dbh;
+
+    // }}}
+    // {{{ toString()
+
+    /**
+     * String conversation
+     *
+     * @return string
+     * @access private
+     */
+    function toString()
+    {
+        $info = strtolower(get_class($this));
+        $info .=  ': (phptype=' . $this->phptype .
+                  ', dbsyntax=' . $this->dbsyntax .
+                  ')';
+
+        if ($this->connection) {
+            $info .= ' [connected]';
+        }
+
+        return $info;
+    }
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * Constructor
+     */
+    function DB_common()
+    {
+        $this->PEAR('DB_Error');
+    }
+
+    // }}}
+    // {{{ quoteString()
+
+    /**
+     * DEPRECATED: Quotes a string so it can be safely used within string
+     * delimiters in a query
+     *
+     * @return string quoted string
+     *
+     * @see DB_common::quoteSmart(), DB_common::escapeSimple()
+     * @deprecated  Deprecated in release 1.2 or lower
+     * @internal
+     */
+    function quoteString($string)
+    {
+        $string = $this->quote($string);
+        if ($string{0} == "'") {
+            return substr($string, 1, -1);
+        }
+        return $string;
+    }
+
+    // }}}
+    // {{{ quote()
+
+    /**
+     * DEPRECATED: Quotes a string so it can be safely used in a query
+     *
+     * @param string $string the input string to quote
+     *
+     * @return string The NULL string or the string quotes
+     *                in magic_quote_sybase style
+     *
+     * @see DB_common::quoteSmart(), DB_common::escapeSimple()
+     * @deprecated  Deprecated in release 1.6.0
+     * @internal
+     */
+    function quote($string = null)
+    {
+        return ($string === null) ? 'NULL' : "'".str_replace("'", "''", $string)."'";
+    }
+
+    // }}}
+    // {{{ quoteIdentifier()
+
+    /**
+     * Quote a string so it can be safely used as a table or column name
+     *
+     * Delimiting style depends on which database driver is being used.
+     *
+     * NOTE: just because you CAN use delimited identifiers doesn't mean
+     * you SHOULD use them.  In general, they end up causing way more
+     * problems than they solve.
+     *
+     * Portability is broken by using the following characters inside
+     * delimited identifiers:
+     *   + backtick (<kbd>`</kbd>) -- due to MySQL
+     *   + double quote (<kbd>"</kbd>) -- due to Oracle
+     *   + brackets (<kbd>[</kbd> or <kbd>]</kbd>) -- due to Access
+     *
+     * Delimited identifiers are known to generally work correctly under
+     * the following drivers:
+     *   + mssql
+     *   + mysql
+     *   + mysql4
+     *   + oci8
+     *   + odbc(access)
+     *   + odbc(db2)
+     *   + pgsql
+     *   + sqlite
+     *   + sybase
+     *
+     * InterBase doesn't seem to be able to use delimited identifiers
+     * via PHP 4.  They work fine under PHP 5.
+     *
+     * @param string $str  identifier name to be quoted
+     *
+     * @return string  quoted identifier string
+     *
+     * @since 1.6.0
+     * @access public
+     */
+    function quoteIdentifier($str)
+    {
+        return '"' . str_replace('"', '""', $str) . '"';
+    }
+
+    // }}}
+    // {{{ quoteSmart()
+
+    /**
+     * Format input so it can be safely used in a query
+     *
+     * The output depends on the PHP data type of input and the database
+     * type being used.
+     *
+     * @param mixed $in  data to be quoted
+     *
+     * @return mixed  the format of the results depends on the input's
+     *                PHP type:
+     *
+     * <ul>
+     *  <li>
+     *    <kbd>input</kbd> -> <samp>returns</samp>
+     *  </li>
+     *  <li>
+     *    <kbd>null</kbd> -> the string <samp>NULL</samp>
+     *  </li>
+     *  <li>
+     *    <kbd>integer</kbd> or <kbd>double</kbd> -> the unquoted number
+     *  </li>
+     *  <li>
+     *    &type.bool; -> output depends on the driver in use
+     *    Most drivers return integers: <samp>1</samp> if
+     *    <kbd>true</kbd> or <samp>0</samp> if 
+     *    <kbd>false</kbd>.
+     *    Some return strings: <samp>TRUE</samp> if
+     *    <kbd>true</kbd> or <samp>FALSE</samp> if 
+     *    <kbd>false</kbd>.
+     *    Finally one returns strings: <samp>T</samp> if
+     *    <kbd>true</kbd> or <samp>F</samp> if 
+     *    <kbd>false</kbd>. Here is a list of each DBMS,
+     *    the values returned and the suggested column type:
+     *    <ul>
+     *      <li>
+     *        <kbd>dbase</kbd> -> <samp>T/F</samp>
+     *        (<kbd>Logical</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>fbase</kbd> -> <samp>TRUE/FALSE</samp>
+     *        (<kbd>BOOLEAN</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>ibase</kbd> -> <samp>1/0</samp>
+     *        (<kbd>SMALLINT</kbd>) [1]
+     *      </li>
+     *      <li>
+     *        <kbd>ifx</kbd> -> <samp>1/0</samp>
+     *        (<kbd>SMALLINT</kbd>) [1]
+     *      </li>
+     *      <li>
+     *        <kbd>msql</kbd> -> <samp>1/0</samp>
+     *        (<kbd>INTEGER</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>mssql</kbd> -> <samp>1/0</samp>
+     *        (<kbd>BIT</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>mysql</kbd> -> <samp>1/0</samp>
+     *        (<kbd>TINYINT(1)</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>mysql4</kbd> -> <samp>1/0</samp>
+     *        (<kbd>TINYINT(1)</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>oci8</kbd> -> <samp>1/0</samp>
+     *        (<kbd>NUMBER(1)</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>odbc</kbd> -> <samp>1/0</samp>
+     *        (<kbd>SMALLINT</kbd>) [1]
+     *      </li>
+     *      <li>
+     *        <kbd>pgsql</kbd> -> <samp>TRUE/FALSE</samp>
+     *        (<kbd>BOOLEAN</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>sqlite</kbd> -> <samp>1/0</samp>
+     *        (<kbd>INTEGER</kbd>)
+     *      </li>
+     *      <li>
+     *        <kbd>sybase</kbd> -> <samp>1/0</samp>
+     *        (<kbd>TINYINT(1)</kbd>)
+     *      </li>
+     *    </ul>
+     *    [1] Accommodate the lowest common denominator because not all
+     *    versions of have <kbd>BOOLEAN</kbd>.
+     *  </li>
+     *  <li>
+     *    other (including strings and numeric strings) ->
+     *    the data with single quotes escaped by preceeding
+     *    single quotes, backslashes are escaped by preceeding
+     *    backslashes, then the whole string is encapsulated
+     *    between single quotes
+     *  </li>
+     * </ul>
+     *      
+     * @since 1.6.0
+     * @see DB_common::escapeSimple()
+     * @access public
+     */
+    function quoteSmart($in)
+    {
+        if (is_int($in) || is_double($in)) {
+            return $in;
+        } elseif (is_bool($in)) {
+            return $in ? 1 : 0;
+        } elseif (is_null($in)) {
+            return 'NULL';
+        } else {
+            return "'" . $this->escapeSimple($in) . "'";
+        }
+    }
+
+    // }}}
+    // {{{ escapeSimple()
+
+    /**
+     * Escape a string according to the current DBMS's standards
+     *
+     * @param string $str  the string to be escaped
+     *
+     * @return string  the escaped string
+     *
+     * @since 1.6.0
+     * @see DB_common::quoteSmart()
+     * @access public
+     */
+    function escapeSimple($str) {
+        return str_replace("'", "''", $str);
+    }
+
+    // }}}
+    // {{{ provides()
+
+    /**
+     * Tell whether a DB implementation or its backend extension
+     * supports a given feature
+     *
+     * @param array $feature name of the feature (see the DB class doc)
+     * @return bool whether this DB implementation supports $feature
+     * @access public
+     */
+    function provides($feature)
+    {
+        return $this->features[$feature];
+    }
+
+    // }}}
+    // {{{ errorCode()
+
+    /**
+     * Map native error codes to DB's portable ones
+     *
+     * Requires that the DB implementation's constructor fills
+     * in the <var>$errorcode_map</var> property.
+     *
+     * @param mixed  $nativecode  the native error code, as returned by the
+     * backend database extension (string or integer)
+     *
+     * @return int a portable DB error code, or DB_ERROR if this DB
+     * implementation has no mapping for the given error code.
+     *
+     * @access public
+     */
+    function errorCode($nativecode)
+    {
+        if (isset($this->errorcode_map[$nativecode])) {
+            return $this->errorcode_map[$nativecode];
+        }
+        // Fall back to DB_ERROR if there was no mapping.
+        return DB_ERROR;
+    }
+
+    // }}}
+    // {{{ errorMessage()
+
+    /**
+     * Map a DB error code to a textual message.  This is actually
+     * just a wrapper for DB::errorMessage()
+     *
+     * @param integer $dbcode the DB error code
+     *
+     * @return string the corresponding error message, of FALSE
+     * if the error code was unknown
+     *
+     * @access public
+     */
+    function errorMessage($dbcode)
+    {
+        return DB::errorMessage($this->errorcode_map[$dbcode]);
+    }
+
+    // }}}
+    // {{{ raiseError()
+
+    /**
+     * Communicate an error and invoke error callbacks, etc
+     *
+     * Basically a wrapper for PEAR::raiseError without the message string.
+     *
+     * @param mixed    integer error code, or a PEAR error object (all
+     *                 other parameters are ignored if this parameter is
+     *                 an object
+     *
+     * @param int      error mode, see PEAR_Error docs
+     *
+     * @param mixed    If error mode is PEAR_ERROR_TRIGGER, this is the
+     *                 error level (E_USER_NOTICE etc).  If error mode is
+     *                 PEAR_ERROR_CALLBACK, this is the callback function,
+     *                 either as a function name, or as an array of an
+     *                 object and method name.  For other error modes this
+     *                 parameter is ignored.
+     *
+     * @param string   Extra debug information.  Defaults to the last
+     *                 query and native error code.
+     *
+     * @param mixed    Native error code, integer or string depending the
+     *                 backend.
+     *
+     * @return object  a PEAR error object
+     *
+     * @access public
+     * @see PEAR_Error
+     */
+    function &raiseError($code = DB_ERROR, $mode = null, $options = null,
+                         $userinfo = null, $nativecode = null)
+    {
+        // The error is yet a DB error object
+        if (is_object($code)) {
+            // because we the static PEAR::raiseError, our global
+            // handler should be used if it is set
+            if ($mode === null && !empty($this->_default_error_mode)) {
+                $mode    = $this->_default_error_mode;
+                $options = $this->_default_error_options;
+            }
+            $tmp = PEAR::raiseError($code, null, $mode, $options, null, null, true);
+            return $tmp;
+        }
+
+        if ($userinfo === null) {
+            $userinfo = $this->last_query;
+        }
+
+        if ($nativecode) {
+            $userinfo .= ' [nativecode=' . trim($nativecode) . ']';
+        }
+
+        $tmp = PEAR::raiseError(null, $code, $mode, $options, $userinfo,
+                                'DB_Error', true);
+        return $tmp;
+    }
+
+    // }}}
+    // {{{ setFetchMode()
+
+    /**
+     * Sets which fetch mode should be used by default on queries
+     * on this connection
+     *
+     * @param integer $fetchmode DB_FETCHMODE_ORDERED or
+     *        DB_FETCHMODE_ASSOC, possibly bit-wise OR'ed with
+     *        DB_FETCHMODE_FLIPPED.
+     *
+     * @param string $object_class The class of the object
+     *                      to be returned by the fetch methods when
+     *                      the DB_FETCHMODE_OBJECT mode is selected.
+     *                      If no class is specified by default a cast
+     *                      to object from the assoc array row will be done.
+     *                      There is also the posibility to use and extend the
+     *                      'DB_Row' class.
+     *
+     * @see DB_FETCHMODE_ORDERED
+     * @see DB_FETCHMODE_ASSOC
+     * @see DB_FETCHMODE_FLIPPED
+     * @see DB_FETCHMODE_OBJECT
+     * @see DB_Row::DB_Row()
+     * @access public
+     */
+    function setFetchMode($fetchmode, $object_class = null)
+    {
+        switch ($fetchmode) {
+            case DB_FETCHMODE_OBJECT:
+                if ($object_class) {
+                    $this->fetchmode_object_class = $object_class;
+                }
+            case DB_FETCHMODE_ORDERED:
+            case DB_FETCHMODE_ASSOC:
+                $this->fetchmode = $fetchmode;
+                break;
+            default:
+                return $this->raiseError('invalid fetchmode mode');
+        }
+    }
+
+    // }}}
+    // {{{ setOption()
+
+    /**
+     * Set run-time configuration options for PEAR DB
+     *
+     * Options, their data types, default values and description:
+     * <ul>
+     * <li>
+     * <var>autofree</var> <kbd>boolean</kbd> = <samp>false</samp>
+     *      <br />should results be freed automatically when there are no
+     *            more rows?
+     * </li><li>
+     * <var>debug</var> <kbd>integer</kbd> = <samp>0</samp>
+     *      <br />debug level
+     * </li><li>
+     * <var>persistent</var> <kbd>boolean</kbd> = <samp>false</samp>
+     *      <br />should the connection be persistent?
+     * </li><li>
+     * <var>portability</var> <kbd>integer</kbd> = <samp>DB_PORTABILITY_NONE</samp>
+     *      <br />portability mode constant (see below)
+     * </li><li>
+     * <var>seqname_format</var> <kbd>string</kbd> = <samp>%s_seq</samp>
+     *      <br />the sprintf() format string used on sequence names.  This
+     *            format is applied to sequence names passed to
+     *            createSequence(), nextID() and dropSequence().
+     * </li><li>
+     * <var>ssl</var> <kbd>boolean</kbd> = <samp>false</samp>
+     *      <br />use ssl to connect?
+     * </li>
+     * </ul>
+     *
+     * -----------------------------------------
+     *
+     * PORTABILITY MODES
+     *
+     * These modes are bitwised, so they can be combined using <kbd>|</kbd>
+     * and removed using <kbd>^</kbd>.  See the examples section below on how
+     * to do this.
+     *
+     * <samp>DB_PORTABILITY_NONE</samp>
+     * turn off all portability features
+     *
+     * This mode gets automatically turned on if the deprecated
+     * <var>optimize</var> option gets set to <samp>performance</samp>.
+     *
+     *
+     * <samp>DB_PORTABILITY_LOWERCASE</samp>
+     * convert names of tables and fields to lower case when using
+     * <kbd>get*()</kbd>, <kbd>fetch*()</kbd> and <kbd>tableInfo()</kbd>
+     *
+     * This mode gets automatically turned on in the following databases
+     * if the deprecated option <var>optimize</var> gets set to
+     * <samp>portability</samp>:
+     * + oci8
+     *
+     *
+     * <samp>DB_PORTABILITY_RTRIM</samp>
+     * right trim the data output by <kbd>get*()</kbd> <kbd>fetch*()</kbd>
+     *
+     *
+     * <samp>DB_PORTABILITY_DELETE_COUNT</samp>
+     * force reporting the number of rows deleted
+     *
+     * Some DBMS's don't count the number of rows deleted when performing
+     * simple <kbd>DELETE FROM tablename</kbd> queries.  This portability
+     * mode tricks such DBMS's into telling the count by adding
+     * <samp>WHERE 1=1</samp> to the end of <kbd>DELETE</kbd> queries.
+     *
+     * This mode gets automatically turned on in the following databases
+     * if the deprecated option <var>optimize</var> gets set to
+     * <samp>portability</samp>:
+     * + fbsql
+     * + mysql
+     * + mysql4
+     * + sqlite
+     *
+     *
+     * <samp>DB_PORTABILITY_NUMROWS</samp>
+     * enable hack that makes <kbd>numRows()</kbd> work in Oracle
+     *
+     * This mode gets automatically turned on in the following databases
+     * if the deprecated option <var>optimize</var> gets set to
+     * <samp>portability</samp>:
+     * + oci8
+     *
+     *
+     * <samp>DB_PORTABILITY_ERRORS</samp>
+     * makes certain error messages in certain drivers compatible
+     * with those from other DBMS's
+     *
+     * + mysql, mysql4:  change unique/primary key constraints
+     *   DB_ERROR_ALREADY_EXISTS -> DB_ERROR_CONSTRAINT
+     *
+     * + odbc(access):  MS's ODBC driver reports 'no such field' as code
+     *   07001, which means 'too few parameters.'  When this option is on
+     *   that code gets mapped to DB_ERROR_NOSUCHFIELD.
+     *   DB_ERROR_MISMATCH -> DB_ERROR_NOSUCHFIELD
+     *
+     *
+     * <samp>DB_PORTABILITY_ALL</samp>
+     * turn on all portability features
+     *
+     * -----------------------------------------
+     *
+     * Example 1. Simple setOption() example
+     * <code> <?php
+     * $dbh->setOption('autofree', true);
+     * ?></code>
+     *
+     * Example 2. Portability for lowercasing and trimming
+     * <code> <?php
+     * $dbh->setOption('portability',
+     *                  DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM);
+     * ?></code>
+     *
+     * Example 3. All portability options except trimming
+     * <code> <?php
+     * $dbh->setOption('portability',
+     *                  DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM);
+     * ?></code>
+     *
+     * @param string $option option name
+     * @param mixed  $value value for the option
+     *
+     * @return int  DB_OK on success.  DB_Error object on failure.
+     *
+     * @see DB_common::$options
+     */
+    function setOption($option, $value)
+    {
+        if (isset($this->options[$option])) {
+            $this->options[$option] = $value;
+
+            /*
+             * Backwards compatibility check for the deprecated 'optimize'
+             * option.  Done here in case settings change after connecting.
+             */
+            if ($option == 'optimize') {
+                if ($value == 'portability') {
+                    switch ($this->phptype) {
+                        case 'oci8':
+                            $this->options['portability'] =
+                                    DB_PORTABILITY_LOWERCASE |
+                                    DB_PORTABILITY_NUMROWS;
+                            break;
+                        case 'fbsql':
+                        case 'mysql':
+                        case 'mysql4':
+                        case 'sqlite':
+                            $this->options['portability'] =
+                                    DB_PORTABILITY_DELETE_COUNT;
+                            break;
+                    }
+                } else {
+                    $this->options['portability'] = DB_PORTABILITY_NONE;
+                }
+            }
+
+            return DB_OK;
+        }
+        return $this->raiseError("unknown option $option");
+    }
+
+    // }}}
+    // {{{ getOption()
+
+    /**
+     * Returns the value of an option
+     *
+     * @param string $option option name
+     *
+     * @return mixed the option value
+     */
+    function getOption($option)
+    {
+        if (isset($this->options[$option])) {
+            return $this->options[$option];
+        }
+        return $this->raiseError("unknown option $option");
+    }
+
+    // }}}
+    // {{{ prepare()
+
+    /**
+     * Prepares a query for multiple execution with execute()
+     *
+     * Creates a query that can be run multiple times.  Each time it is run,
+     * the placeholders, if any, will be replaced by the contents of
+     * execute()'s $data argument.
+     *
+     * Three types of placeholders can be used:
+     *   + <kbd>?</kbd>  scalar value (i.e. strings, integers).  The system
+     *                   will automatically quote and escape the data.
+     *   + <kbd>!</kbd>  value is inserted 'as is'
+     *   + <kbd>&</kbd>  requires a file name.  The file's contents get
+     *                   inserted into the query (i.e. saving binary
+     *                   data in a db)
+     *
+     * Example 1.
+     * <code> <?php
+     * $sth = $dbh->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)');
+     * $data = array(
+     *     "John's text",
+     *     "'it''s good'",
+     *     'filename.txt'
+     * );
+     * $res = $dbh->execute($sth, $data);
+     * ?></code>
+     *
+     * Use backslashes to escape placeholder characters if you don't want
+     * them to be interpreted as placeholders:
+     * <pre>
+     *    "UPDATE foo SET col=? WHERE col='over \& under'"
+     * </pre>
+     *
+     * With some database backends, this is emulated.
+     *
+     * {@internal ibase and oci8 have their own prepare() methods.}}
+     *
+     * @param string $query query to be prepared
+     *
+     * @return mixed DB statement resource on success. DB_Error on failure.
+     *
+     * @see DB_common::execute()
+     * @access public
+     */
+    function prepare($query)
+    {
+        $tokens   = preg_split('/((?<!\\\)[&?!])/', $query, -1,
+                               PREG_SPLIT_DELIM_CAPTURE);
+        $token     = 0;
+        $types     = array();
+        $newtokens = array();
+
+        foreach ($tokens as $val) {
+            switch ($val) {
+                case '?':
+                    $types[$token++] = DB_PARAM_SCALAR;
+                    break;
+                case '&':
+                    $types[$token++] = DB_PARAM_OPAQUE;
+                    break;
+                case '!':
+                    $types[$token++] = DB_PARAM_MISC;
+                    break;
+                default:
+                    $newtokens[] = preg_replace('/\\\([&?!])/', "\\1", $val);
+            }
+        }
+
+        $this->prepare_tokens[] = &$newtokens;
+        end($this->prepare_tokens);
+
+        $k = key($this->prepare_tokens);
+        $this->prepare_types[$k] = $types;
+        $this->prepared_queries[$k] = implode(' ', $newtokens);
+
+        return $k;
+    }
+
+    // }}}
+    // {{{ autoPrepare()
+
+    /**
+     * Automaticaly generate an insert or update query and pass it to prepare()
+     *
+     * @param string $table name of the table
+     * @param array $table_fields ordered array containing the fields names
+     * @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
+     * @param string $where in case of update queries, this string will be put after the sql WHERE statement
+     * @return resource handle for the query
+     * @see DB_common::prepare(), DB_common::buildManipSQL()
+     * @access public
+     */
+    function autoPrepare($table, $table_fields, $mode = DB_AUTOQUERY_INSERT, $where = false)
+    {
+        $query = $this->buildManipSQL($table, $table_fields, $mode, $where);
+        return $this->prepare($query);
+    }
+
+    // }}}
+    // {{{ autoExecute()
+
+    /**
+     * Automaticaly generate an insert or update query and call prepare()
+     * and execute() with it
+     *
+     * @param string $table name of the table
+     * @param array $fields_values assoc ($key=>$value) where $key is a field name and $value its value
+     * @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
+     * @param string $where in case of update queries, this string will be put after the sql WHERE statement
+     * @return mixed  a new DB_Result or a DB_Error when fail
+     * @see DB_common::autoPrepare(), DB_common::buildManipSQL()
+     * @access public
+     */
+    function autoExecute($table, $fields_values, $mode = DB_AUTOQUERY_INSERT, $where = false)
+    {
+        $sth = $this->autoPrepare($table, array_keys($fields_values), $mode, $where);
+        $ret =& $this->execute($sth, array_values($fields_values));
+        $this->freePrepared($sth);
+        return $ret;
+
+    }
+
+    // }}}
+    // {{{ buildManipSQL()
+
+    /**
+     * Make automaticaly an sql query for prepare()
+     *
+     * Example : buildManipSQL('table_sql', array('field1', 'field2', 'field3'), DB_AUTOQUERY_INSERT)
+     *           will return the string : INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?)
+     * NB : - This belongs more to a SQL Builder class, but this is a simple facility
+     *      - Be carefull ! If you don't give a $where param with an UPDATE query, all
+     *        the records of the table will be updated !
+     *
+     * @param string $table name of the table
+     * @param array $table_fields ordered array containing the fields names
+     * @param int $mode type of query to make (DB_AUTOQUERY_INSERT or DB_AUTOQUERY_UPDATE)
+     * @param string $where in case of update queries, this string will be put after the sql WHERE statement
+     * @return string sql query for prepare()
+     * @access public
+     */
+    function buildManipSQL($table, $table_fields, $mode, $where = false)
+    {
+        if (count($table_fields) == 0) {
+            $this->raiseError(DB_ERROR_NEED_MORE_DATA);
+        }
+        $first = true;
+        switch ($mode) {
+            case DB_AUTOQUERY_INSERT:
+                $values = '';
+                $names = '';
+                foreach ($table_fields as $value) {
+                    if ($first) {
+                        $first = false;
+                    } else {
+                        $names .= ',';
+                        $values .= ',';
+                    }
+                    $names .= $value;
+                    $values .= '?';
+                }
+                return "INSERT INTO $table ($names) VALUES ($values)";
+            case DB_AUTOQUERY_UPDATE:
+                $set = '';
+                foreach ($table_fields as $value) {
+                    if ($first) {
+                        $first = false;
+                    } else {
+                        $set .= ',';
+                    }
+                    $set .= "$value = ?";
+                }
+                $sql = "UPDATE $table SET $set";
+                if ($where) {
+                    $sql .= " WHERE $where";
+                }
+                return $sql;
+            default:
+                $this->raiseError(DB_ERROR_SYNTAX);
+        }
+    }
+
+    // }}}
+    // {{{ execute()
+
+    /**
+     * Executes a DB statement prepared with prepare()
+     *
+     * Example 1.
+     * <code> <?php
+     * $sth = $dbh->prepare('INSERT INTO tbl (a, b, c) VALUES (?, !, &)');
+     * $data = array(
+     *     "John's text",
+     *     "'it''s good'",
+     *     'filename.txt'
+     * );
+     * $res = $dbh->execute($sth, $data);
+     * ?></code>
+     *
+     * @param resource  $stmt  a DB statement resource returned from prepare()
+     * @param mixed  $data  array, string or numeric data to be used in
+     *                      execution of the statement.  Quantity of items
+     *                      passed must match quantity of placeholders in
+     *                      query:  meaning 1 placeholder for non-array
+     *                      parameters or 1 placeholder per array element.
+     *
+     * @return mixed  a new DB_Result or a DB_Error when fail
+     *
+     * {@internal ibase and oci8 have their own execute() methods.}}
+     *
+     * @see DB_common::prepare()
+     * @access public
+     */
+    function &execute($stmt, $data = array())
+    {
+        $realquery = $this->executeEmulateQuery($stmt, $data);
+        if (DB::isError($realquery)) {
+            return $realquery;
+        }
+        $result = $this->simpleQuery($realquery);
+
+        if (DB::isError($result) || $result === DB_OK) {
+            return $result;
+        } else {
+            $tmp =& new DB_result($this, $result);
+            return $tmp;
+        }
+    }
+
+    // }}}
+    // {{{ executeEmulateQuery()
+
+    /**
+     * Emulates the execute statement, when not supported
+     *
+     * @param resource  $stmt  a DB statement resource returned from execute()
+     * @param mixed  $data  array, string or numeric data to be used in
+     *                      execution of the statement.  Quantity of items
+     *                      passed must match quantity of placeholders in
+     *                      query:  meaning 1 placeholder for non-array
+     *                      parameters or 1 placeholder per array element.
+     *
+     * @return mixed a string containing the real query run when emulating
+     *               prepare/execute.  A DB error code is returned on failure.
+     *
+     * @see DB_common::execute()
+     * @access private
+     */
+    function executeEmulateQuery($stmt, $data = array())
+    {
+        if (!is_array($data)) {
+            $data = array($data);
+        }
+
+        if (count($this->prepare_types[$stmt]) != count($data)) {
+            $this->last_query = $this->prepared_queries[$stmt];
+            return $this->raiseError(DB_ERROR_MISMATCH);
+        }
+
+        $realquery = $this->prepare_tokens[$stmt][0];
+
+        $i = 0;
+        foreach ($data as $value) {
+            if ($this->prepare_types[$stmt][$i] == DB_PARAM_SCALAR) {
+                $realquery .= $this->quoteSmart($value);
+            } elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) {
+                $fp = @fopen($value, 'rb');
+                if (!$fp) {
+                    return $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
+                }
+                $realquery .= $this->quoteSmart(fread($fp, filesize($value)));
+                fclose($fp);
+            } else {
+                $realquery .= $value;
+            }
+
+            $realquery .= $this->prepare_tokens[$stmt][++$i];
+        }
+
+        return $realquery;
+    }
+
+    // }}}
+    // {{{ executeMultiple()
+
+    /**
+     * This function does several execute() calls on the same
+     * statement handle
+     *
+     * $data must be an array indexed numerically
+     * from 0, one execute call is done for every "row" in the array.
+     *
+     * If an error occurs during execute(), executeMultiple() does not
+     * execute the unfinished rows, but rather returns that error.
+     *
+     * @param resource $stmt query handle from prepare()
+     * @param array    $data numeric array containing the
+     *                       data to insert into the query
+     *
+     * @return mixed DB_OK or DB_Error
+     *
+     * @see DB_common::prepare(), DB_common::execute()
+     * @access public
+     */
+    function executeMultiple($stmt, $data)
+    {
+        foreach ($data as $value) {
+            $res =& $this->execute($stmt, $value);
+            if (DB::isError($res)) {
+                return $res;
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ freePrepared()
+
+    /**
+     * Free the resource used in a prepared query
+     *
+     * @param $stmt The resurce returned by the prepare() function
+     * @see DB_common::prepare()
+     */
+    function freePrepared($stmt)
+    {
+        // Free the internal prepared vars
+        if (isset($this->prepare_tokens[$stmt])) {
+            unset($this->prepare_tokens[$stmt]);
+            unset($this->prepare_types[$stmt]);
+            unset($this->prepared_queries[$stmt]);
+            return true;
+        }
+        return false;
+    }
+
+    // }}}
+    // {{{ modifyQuery()
+
+    /**
+     * This method is used by backends to alter queries for various
+     * reasons
+     *
+     * It is defined here to assure that all implementations
+     * have this method defined.
+     *
+     * @param string $query  query to modify
+     *
+     * @return the new (modified) query
+     *
+     * @access private
+     */
+    function modifyQuery($query) {
+        return $query;
+    }
+
+    // }}}
+    // {{{ modifyLimitQuery()
+
+    /**
+     * This method is used by backends to alter limited queries
+     *
+     * @param string  $query query to modify
+     * @param integer $from  the row to start to fetching
+     * @param integer $count the numbers of rows to fetch
+     *
+     * @return the new (modified) query
+     *
+     * @access private
+     */
+    function modifyLimitQuery($query, $from, $count)
+    {
+        return $query;
+    }
+
+    // }}}
+    // {{{ query()
+
+    /**
+     * Send a query to the database and return any results with a
+     * DB_result object
+     *
+     * The query string can be either a normal statement to be sent directly
+     * to the server OR if <var>$params</var> are passed the query can have
+     * placeholders and it will be passed through prepare() and execute().
+     *
+     * @param string $query  the SQL query or the statement to prepare
+     * @param mixed  $params array, string or numeric data to be used in
+     *                       execution of the statement.  Quantity of items
+     *                       passed must match quantity of placeholders in
+     *                       query:  meaning 1 placeholder for non-array
+     *                       parameters or 1 placeholder per array element.
+     *
+     * @return mixed  a DB_result object or DB_OK on success, a DB
+     *                error on failure
+     *
+     * @see DB_result, DB_common::prepare(), DB_common::execute()
+     * @access public
+     */
+    function &query($query, $params = array())
+    {
+        if (sizeof($params) > 0) {
+            $sth = $this->prepare($query);
+            if (DB::isError($sth)) {
+                return $sth;
+            }
+            $ret =& $this->execute($sth, $params);
+            $this->freePrepared($sth);
+            return $ret;
+        } else {
+            $result = $this->simpleQuery($query);
+            if (DB::isError($result) || $result === DB_OK) {
+                return $result;
+            } else {
+                $tmp =& new DB_result($this, $result);
+                return $tmp;
+            }
+        }
+    }
+
+    // }}}
+    // {{{ limitQuery()
+
+    /**
+     * Generates a limited query
+     *
+     * @param string  $query query
+     * @param integer $from  the row to start to fetching
+     * @param integer $count the numbers of rows to fetch
+     * @param array   $params required for a statement
+     *
+     * @return mixed a DB_Result object, DB_OK or a DB_Error
+     *
+     * @access public
+     */
+    function &limitQuery($query, $from, $count, $params = array())
+    {
+        $query = $this->modifyLimitQuery($query, $from, $count);
+        if (DB::isError($query)){
+            return $query;
+        }
+        $result =& $this->query($query, $params);
+        if (is_a($result, 'DB_result')) {
+            $result->setOption('limit_from', $from);
+            $result->setOption('limit_count', $count);
+        }
+        return $result;
+    }
+
+    // }}}
+    // {{{ getOne()
+
+    /**
+     * Fetch the first column of the first row of data returned from
+     * a query
+     *
+     * Takes care of doing the query and freeing the results when finished.
+     *
+     * @param string $query  the SQL query
+     * @param mixed  $params array, string or numeric data to be used in
+     *                       execution of the statement.  Quantity of items
+     *                       passed must match quantity of placeholders in
+     *                       query:  meaning 1 placeholder for non-array
+     *                       parameters or 1 placeholder per array element.
+     *
+     * @return mixed  the returned value of the query.  DB_Error on failure.
+     *
+     * @access public
+     */
+    function &getOne($query, $params = array())
+    {
+        settype($params, 'array');
+        if (sizeof($params) > 0) {
+            $sth = $this->prepare($query);
+            if (DB::isError($sth)) {
+                return $sth;
+            }
+            $res =& $this->execute($sth, $params);
+            $this->freePrepared($sth);
+        } else {
+            $res =& $this->query($query);
+        }
+
+        if (DB::isError($res)) {
+            return $res;
+        }
+
+        $err = $res->fetchInto($row, DB_FETCHMODE_ORDERED);
+        $res->free();
+
+        if ($err !== DB_OK) {
+            return $err;
+        }
+
+        return $row[0];
+    }
+
+    // }}}
+    // {{{ getRow()
+
+    /**
+     * Fetch the first row of data returned from a query
+     *
+     * Takes care of doing the query and freeing the results when finished.
+     *
+     * @param string $query  the SQL query
+     * @param array  $params array to be used in execution of the statement.
+     *                       Quantity of array elements must match quantity
+     *                       of placeholders in query.  This function does
+     *                       NOT support scalars.
+     * @param int    $fetchmode  the fetch mode to use
+     *
+     * @return array the first row of results as an array indexed from
+     *               0, or a DB error code.
+     *
+     * @access public
+     */
+    function &getRow($query,
+                     $params = array(),
+                     $fetchmode = DB_FETCHMODE_DEFAULT)
+    {
+        // compat check, the params and fetchmode parameters used to
+        // have the opposite order
+        if (!is_array($params)) {
+            if (is_array($fetchmode)) {
+                if ($params === null) {
+                    $tmp = DB_FETCHMODE_DEFAULT;
+                } else {
+                    $tmp = $params;
+                }
+                $params = $fetchmode;
+                $fetchmode = $tmp;
+            } elseif ($params !== null) {
+                $fetchmode = $params;
+                $params = array();
+            }
+        }
+
+        if (sizeof($params) > 0) {
+            $sth = $this->prepare($query);
+            if (DB::isError($sth)) {
+                return $sth;
+            }
+            $res =& $this->execute($sth, $params);
+            $this->freePrepared($sth);
+        } else {
+            $res =& $this->query($query);
+        }
+
+        if (DB::isError($res)) {
+            return $res;
+        }
+
+        $err = $res->fetchInto($row, $fetchmode);
+
+        $res->free();
+
+        if ($err !== DB_OK) {
+            return $err;
+        }
+
+        return $row;
+    }
+
+    // }}}
+    // {{{ getCol()
+
+    /**
+     * Fetch a single column from a result set and return it as an
+     * indexed array
+     *
+     * @param string $query  the SQL query
+     * @param mixed  $col    which column to return (integer [column number,
+     *                       starting at 0] or string [column name])
+     * @param mixed  $params array, string or numeric data to be used in
+     *                       execution of the statement.  Quantity of items
+     *                       passed must match quantity of placeholders in
+     *                       query:  meaning 1 placeholder for non-array
+     *                       parameters or 1 placeholder per array element.
+     *
+     * @return array  an indexed array with the data from the first
+     *                row at index 0, or a DB error code
+     *
+     * @see DB_common::query()
+     * @access public
+     */
+    function &getCol($query, $col = 0, $params = array())
+    {
+        settype($params, 'array');
+        if (sizeof($params) > 0) {
+            $sth = $this->prepare($query);
+
+            if (DB::isError($sth)) {
+                return $sth;
+            }
+
+            $res =& $this->execute($sth, $params);
+            $this->freePrepared($sth);
+        } else {
+            $res =& $this->query($query);
+        }
+
+        if (DB::isError($res)) {
+            return $res;
+        }
+
+        $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC;
+        $ret = array();
+
+        while (is_array($row = $res->fetchRow($fetchmode))) {
+            $ret[] = $row[$col];
+        }
+
+        $res->free();
+
+        if (DB::isError($row)) {
+            $ret = $row;
+        }
+
+        return $ret;
+    }
+
+    // }}}
+    // {{{ getAssoc()
+
+    /**
+     * Fetch the entire result set of a query and return it as an
+     * associative array using the first column as the key
+     *
+     * If the result set contains more than two columns, the value
+     * will be an array of the values from column 2-n.  If the result
+     * set contains only two columns, the returned value will be a
+     * scalar with the value of the second column (unless forced to an
+     * array with the $force_array parameter).  A DB error code is
+     * returned on errors.  If the result set contains fewer than two
+     * columns, a DB_ERROR_TRUNCATED error is returned.
+     *
+     * For example, if the table "mytable" contains:
+     *
+     * <pre>
+     *  ID      TEXT       DATE
+     * --------------------------------
+     *  1       'one'      944679408
+     *  2       'two'      944679408
+     *  3       'three'    944679408
+     * </pre>
+     *
+     * Then the call getAssoc('SELECT id,text FROM mytable') returns:
+     * <pre>
+     *   array(
+     *     '1' => 'one',
+     *     '2' => 'two',
+     *     '3' => 'three',
+     *   )
+     * </pre>
+     *
+     * ...while the call getAssoc('SELECT id,text,date FROM mytable') returns:
+     * <pre>
+     *   array(
+     *     '1' => array('one', '944679408'),
+     *     '2' => array('two', '944679408'),
+     *     '3' => array('three', '944679408')
+     *   )
+     * </pre>
+     *
+     * If the more than one row occurs with the same value in the
+     * first column, the last row overwrites all previous ones by
+     * default.  Use the $group parameter if you don't want to
+     * overwrite like this.  Example:
+     *
+     * <pre>
+     * getAssoc('SELECT category,id,name FROM mytable', false, null,
+     *          DB_FETCHMODE_ASSOC, true) returns:
+     *
+     *   array(
+     *     '1' => array(array('id' => '4', 'name' => 'number four'),
+     *                  array('id' => '6', 'name' => 'number six')
+     *            ),
+     *     '9' => array(array('id' => '4', 'name' => 'number four'),
+     *                  array('id' => '6', 'name' => 'number six')
+     *            )
+     *   )
+     * </pre>
+     *
+     * Keep in mind that database functions in PHP usually return string
+     * values for results regardless of the database's internal type.
+     *
+     * @param string  $query  the SQL query
+     * @param boolean $force_array  used only when the query returns
+     *                              exactly two columns.  If true, the values
+     *                              of the returned array will be one-element
+     *                              arrays instead of scalars.
+     * @param mixed   $params array, string or numeric data to be used in
+     *                        execution of the statement.  Quantity of items
+     *                        passed must match quantity of placeholders in
+     *                        query:  meaning 1 placeholder for non-array
+     *                        parameters or 1 placeholder per array element.
+     * @param boolean $group  if true, the values of the returned array
+     *                        is wrapped in another array.  If the same
+     *                        key value (in the first column) repeats
+     *                        itself, the values will be appended to
+     *                        this array instead of overwriting the
+     *                        existing values.
+     *
+     * @return array  associative array with results from the query.
+     *                DB Error on failure.
+     *
+     * @access public
+     */
+    function &getAssoc($query, $force_array = false, $params = array(),
+                       $fetchmode = DB_FETCHMODE_DEFAULT, $group = false)
+    {
+        settype($params, 'array');
+        if (sizeof($params) > 0) {
+            $sth = $this->prepare($query);
+
+            if (DB::isError($sth)) {
+                return $sth;
+            }
+
+            $res =& $this->execute($sth, $params);
+            $this->freePrepared($sth);
+        } else {
+            $res =& $this->query($query);
+        }
+
+        if (DB::isError($res)) {
+            return $res;
+        }
+        if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+            $fetchmode = $this->fetchmode;
+        }
+        $cols = $res->numCols();
+
+        if ($cols < 2) {
+            $tmp =& $this->raiseError(DB_ERROR_TRUNCATED);
+            return $tmp;
+        }
+
+        $results = array();
+
+        if ($cols > 2 || $force_array) {
+            // return array values
+            // XXX this part can be optimized
+            if ($fetchmode == DB_FETCHMODE_ASSOC) {
+                while (is_array($row = $res->fetchRow(DB_FETCHMODE_ASSOC))) {
+                    reset($row);
+                    $key = current($row);
+                    unset($row[key($row)]);
+                    if ($group) {
+                        $results[$key][] = $row;
+                    } else {
+                        $results[$key] = $row;
+                    }
+                }
+            } elseif ($fetchmode == DB_FETCHMODE_OBJECT) {
+                while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
+                    $arr = get_object_vars($row);
+                    $key = current($arr);
+                    if ($group) {
+                        $results[$key][] = $row;
+                    } else {
+                        $results[$key] = $row;
+                    }
+                }
+            } else {
+                while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
+                    // we shift away the first element to get
+                    // indices running from 0 again
+                    $key = array_shift($row);
+                    if ($group) {
+                        $results[$key][] = $row;
+                    } else {
+                        $results[$key] = $row;
+                    }
+                }
+            }
+            if (DB::isError($row)) {
+                $results = $row;
+            }
+        } else {
+            // return scalar values
+            while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) {
+                if ($group) {
+                    $results[$row[0]][] = $row[1];
+                } else {
+                    $results[$row[0]] = $row[1];
+                }
+            }
+            if (DB::isError($row)) {
+                $results = $row;
+            }
+        }
+
+        $res->free();
+
+        return $results;
+    }
+
+    // }}}
+    // {{{ getAll()
+
+    /**
+     * Fetch all the rows returned from a query
+     *
+     * @param string $query  the SQL query
+     * @param array  $params array to be used in execution of the statement.
+     *                       Quantity of array elements must match quantity
+     *                       of placeholders in query.  This function does
+     *                       NOT support scalars.
+     * @param int    $fetchmode  the fetch mode to use
+     *
+     * @return array  an nested array.  DB error on failure.
+     *
+     * @access public
+     */
+    function &getAll($query,
+                     $params = array(),
+                     $fetchmode = DB_FETCHMODE_DEFAULT)
+    {
+        // compat check, the params and fetchmode parameters used to
+        // have the opposite order
+        if (!is_array($params)) {
+            if (is_array($fetchmode)) {
+                if ($params === null) {
+                    $tmp = DB_FETCHMODE_DEFAULT;
+                } else {
+                    $tmp = $params;
+                }
+                $params = $fetchmode;
+                $fetchmode = $tmp;
+            } elseif ($params !== null) {
+                $fetchmode = $params;
+                $params = array();
+            }
+        }
+
+        if (sizeof($params) > 0) {
+            $sth = $this->prepare($query);
+
+            if (DB::isError($sth)) {
+                return $sth;
+            }
+
+            $res =& $this->execute($sth, $params);
+            $this->freePrepared($sth);
+        } else {
+            $res =& $this->query($query);
+        }
+
+        if (DB::isError($res) || $res == DB_OK) {
+            return $res;
+        }
+
+        $results = array();
+        while (DB_OK === $res->fetchInto($row, $fetchmode)) {
+            if ($fetchmode & DB_FETCHMODE_FLIPPED) {
+                foreach ($row as $key => $val) {
+                    $results[$key][] = $val;
+                }
+            } else {
+                $results[] = $row;
+            }
+        }
+
+        $res->free();
+
+        if (DB::isError($row)) {
+            $tmp =& $this->raiseError($row);
+            return $tmp;
+        }
+        return $results;
+    }
+
+    // }}}
+    // {{{ autoCommit()
+
+    /**
+     * enable automatic Commit
+     *
+     * @param boolean $onoff
+     * @return mixed DB_Error
+     *
+     * @access public
+     */
+    function autoCommit($onoff=false)
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ commit()
+
+    /**
+     * starts a Commit
+     *
+     * @return mixed DB_Error
+     *
+     * @access public
+     */
+    function commit()
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ rollback()
+
+    /**
+     * starts a rollback
+     *
+     * @return mixed DB_Error
+     *
+     * @access public
+     */
+    function rollback()
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    /**
+     * Returns the number of rows in a result object
+     *
+     * @param object DB_Result the result object to check
+     *
+     * @return mixed DB_Error or the number of rows
+     *
+     * @access public
+     */
+    function numRows($result)
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ affectedRows()
+
+    /**
+     * Returns the affected rows of a query
+     *
+     * @return mixed DB_Error or number of rows
+     *
+     * @access public
+     */
+    function affectedRows()
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ errorNative()
+
+    /**
+     * Returns an errormessage, provides by the database
+     *
+     * @return mixed DB_Error or message
+     *
+     * @access public
+     */
+    function errorNative()
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ getSequenceName()
+
+    /**
+     * Generate the name used inside the database for a sequence
+     *
+     * The createSequence() docblock contains notes about storing sequence
+     * names.
+     *
+     * @param string $sqn  the sequence's public name
+     *
+     * @return string  the sequence's name in the backend
+     *
+     * @see DB_common::createSequence(), DB_common::dropSequence(),
+     *      DB_common::nextID(), DB_common::setOption()
+     * @access private
+     */
+    function getSequenceName($sqn)
+    {
+        return sprintf($this->getOption('seqname_format'),
+                       preg_replace('/[^a-z0-9_.]/i', '_', $sqn));
+    }
+
+    // }}}
+    // {{{ nextId()
+
+    /**
+     * Returns the next free id in a sequence
+     *
+     * @param string  $seq_name  name of the sequence
+     * @param boolean $ondemand  when true, the seqence is automatically
+     *                           created if it does not exist
+     *
+     * @return int  the next id number in the sequence.  DB_Error if problem.
+     *
+     * @see DB_common::createSequence(), DB_common::dropSequence(),
+     *      DB_common::getSequenceName()
+     * @access public
+     */
+    function nextId($seq_name, $ondemand = true)
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ createSequence()
+
+    /**
+     * Creates a new sequence
+     *
+     * The name of a given sequence is determined by passing the string
+     * provided in the <var>$seq_name</var> argument through PHP's sprintf()
+     * function using the value from the <var>seqname_format</var> option as
+     * the sprintf()'s format argument.
+     *
+     * <var>seqname_format</var> is set via setOption().
+     *
+     * @param string $seq_name  name of the new sequence
+     *
+     * @return int  DB_OK on success.  A DB_Error object is returned if
+     *              problems arise.
+     *
+     * @see DB_common::dropSequence(), DB_common::getSequenceName(),
+     *      DB_common::nextID()
+     * @access public
+     */
+    function createSequence($seq_name)
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ dropSequence()
+
+    /**
+     * Deletes a sequence
+     *
+     * @param string $seq_name  name of the sequence to be deleted
+     *
+     * @return int  DB_OK on success.  DB_Error if problems.
+     *
+     * @see DB_common::createSequence(), DB_common::getSequenceName(),
+     *      DB_common::nextID()
+     * @access public
+     */
+    function dropSequence($seq_name)
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ tableInfo()
+
+    /**
+     * Returns information about a table or a result set
+     *
+     * The format of the resulting array depends on which <var>$mode</var>
+     * you select.  The sample output below is based on this query:
+     * <pre>
+     *    SELECT tblFoo.fldID, tblFoo.fldPhone, tblBar.fldId
+     *    FROM tblFoo
+     *    JOIN tblBar ON tblFoo.fldId = tblBar.fldId
+     * </pre>
+     *
+     * <ul>
+     * <li>
+     *
+     * <kbd>null</kbd> (default)
+     *   <pre>
+     *   [0] => Array (
+     *       [table] => tblFoo
+     *       [name] => fldId
+     *       [type] => int
+     *       [len] => 11
+     *       [flags] => primary_key not_null
+     *   )
+     *   [1] => Array (
+     *       [table] => tblFoo
+     *       [name] => fldPhone
+     *       [type] => string
+     *       [len] => 20
+     *       [flags] =>
+     *   )
+     *   [2] => Array (
+     *       [table] => tblBar
+     *       [name] => fldId
+     *       [type] => int
+     *       [len] => 11
+     *       [flags] => primary_key not_null
+     *   )
+     *   </pre>
+     *
+     * </li><li>
+     *
+     * <kbd>DB_TABLEINFO_ORDER</kbd>
+     *
+     *   <p>In addition to the information found in the default output,
+     *   a notation of the number of columns is provided by the
+     *   <samp>num_fields</samp> element while the <samp>order</samp>
+     *   element provides an array with the column names as the keys and
+     *   their location index number (corresponding to the keys in the
+     *   the default output) as the values.</p>
+     *
+     *   <p>If a result set has identical field names, the last one is
+     *   used.</p>
+     *
+     *   <pre>
+     *   [num_fields] => 3
+     *   [order] => Array (
+     *       [fldId] => 2
+     *       [fldTrans] => 1
+     *   )
+     *   </pre>
+     *
+     * </li><li>
+     *
+     * <kbd>DB_TABLEINFO_ORDERTABLE</kbd>
+     *
+     *   <p>Similar to <kbd>DB_TABLEINFO_ORDER</kbd> but adds more
+     *   dimensions to the array in which the table names are keys and
+     *   the field names are sub-keys.  This is helpful for queries that
+     *   join tables which have identical field names.</p>
+     *
+     *   <pre>
+     *   [num_fields] => 3
+     *   [ordertable] => Array (
+     *       [tblFoo] => Array (
+     *           [fldId] => 0
+     *           [fldPhone] => 1
+     *       )
+     *       [tblBar] => Array (
+     *           [fldId] => 2
+     *       )
+     *   )
+     *   </pre>
+     *
+     * </li>
+     * </ul>
+     *
+     * The <samp>flags</samp> element contains a space separated list
+     * of extra information about the field.  This data is inconsistent
+     * between DBMS's due to the way each DBMS works.
+     *   + <samp>primary_key</samp>
+     *   + <samp>unique_key</samp>
+     *   + <samp>multiple_key</samp>
+     *   + <samp>not_null</samp>
+     *
+     * Most DBMS's only provide the <samp>table</samp> and <samp>flags</samp>
+     * elements if <var>$result</var> is a table name.  The following DBMS's
+     * provide full information from queries:
+     *   + fbsql
+     *   + mysql
+     *
+     * If the 'portability' option has <samp>DB_PORTABILITY_LOWERCASE</samp>
+     * turned on, the names of tables and fields will be lowercased.
+     *
+     * @param object|string  $result  DB_result object from a query or a
+     *                                string containing the name of a table.
+     *                                While this also accepts a query result
+     *                                resource identifier, this behavior is
+     *                                deprecated.
+     * @param int  $mode   either unused or one of the tableInfo modes:
+     *                     <kbd>DB_TABLEINFO_ORDERTABLE</kbd>,
+     *                     <kbd>DB_TABLEINFO_ORDER</kbd> or
+     *                     <kbd>DB_TABLEINFO_FULL</kbd> (which does both).
+     *                     These are bitwise, so the first two can be
+     *                     combined using <kbd>|</kbd>.
+     * @return array  an associative array with the information requested.
+     *                If something goes wrong an error object is returned.
+     *
+     * @see DB_common::setOption()
+     * @access public
+     */
+    function tableInfo($result, $mode = null)
+    {
+        /*
+         * If the DB_<driver> class has a tableInfo() method, that one
+         * overrides this one.  But, if the driver doesn't have one,
+         * this method runs and tells users about that fact.
+         */
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ getTables()
+
+    /**
+     * @deprecated  Deprecated in release 1.2 or lower
+     */
+    function getTables()
+    {
+        return $this->getListOf('tables');
+    }
+
+    // }}}
+    // {{{ getListOf()
+
+    /**
+     * list internal DB info
+     * valid values for $type are db dependent,
+     * often: databases, users, view, functions
+     *
+     * @param string $type type of requested info
+     *
+     * @return mixed DB_Error or the requested data
+     *
+     * @access public
+     */
+    function getListOf($type)
+    {
+        $sql = $this->getSpecialQuery($type);
+        if ($sql === null) {                                // No support
+            return $this->raiseError(DB_ERROR_UNSUPPORTED);
+        } elseif (is_int($sql) || DB::isError($sql)) {      // Previous error
+            return $this->raiseError($sql);
+        } elseif (is_array($sql)) {                         // Already the result
+            return $sql;
+        }
+        return $this->getCol($sql);                         // Launch this query
+    }
+
+    // }}}
+    // {{{ getSpecialQuery()
+
+    /**
+     * Returns the query needed to get some backend info
+     *
+     * @param string $type What kind of info you want to retrieve
+     *
+     * @return string The SQL query string
+     *
+     * @access public
+     */
+    function getSpecialQuery($type)
+    {
+        return $this->raiseError(DB_ERROR_UNSUPPORTED);
+    }
+
+    // }}}
+    // {{{ _rtrimArrayValues()
+
+    /**
+     * Right trim all strings in an array
+     *
+     * @param array  $array  the array to be trimmed (passed by reference)
+     * @return void
+     * @access private
+     */
+    function _rtrimArrayValues(&$array) {
+        foreach ($array as $key => $value) {
+            if (is_string($value)) {
+                $array[$key] = rtrim($value);
+            }
+        }
+    }
+
+    // }}}
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/dbase.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/dbase.php
new file mode 100755 (executable)
index 0000000..bbcd9e1
--- /dev/null
@@ -0,0 +1,218 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Tomas V.V.Cox <cox@idecnet.com>                              |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+
+// XXX legend:
+//  You have to compile your PHP with the --enable-dbase option
+
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's dbase
+ * extension.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Stig Bakken <ssb@php.net>
+ */
+class DB_dbase extends DB_common
+{
+    // {{{ properties
+
+    var $connection;
+    var $phptype, $dbsyntax;
+    var $prepare_tokens = array();
+    var $prepare_types = array();
+    var $transaction_opcount = 0;
+    var $res_row = array();
+    var $result = 0;
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * DB_mysql constructor.
+     *
+     * @access public
+     */
+    function DB_dbase()
+    {
+        $this->DB_common();
+        $this->phptype = 'dbase';
+        $this->dbsyntax = 'dbase';
+        $this->features = array(
+            'prepare'       => false,
+            'pconnect'      => false,
+            'transactions'  => false,
+            'limit'         => false
+        );
+        $this->errorcode_map = array();
+    }
+
+    // }}}
+    // {{{ connect()
+
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('dbase')) {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+        $this->dsn = $dsninfo;
+        ob_start();
+        $conn  = dbase_open($dsninfo['database'], 0);
+        $error = ob_get_contents();
+        ob_end_clean();
+        if (!$conn) {
+            return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
+                                     null, null, strip_tags($error));
+        }
+        $this->connection = $conn;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ disconnect()
+
+    function disconnect()
+    {
+        $ret = dbase_close($this->connection);
+        $this->connection = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ &query()
+
+    function &query($query = null)
+    {
+        // emulate result resources
+        $this->res_row[$this->result] = 0;
+        $tmp =& new DB_result($this, $this->result++);
+        return $tmp;
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row and insert the data into an existing array.
+     *
+     * Formating of the array and the data therein are configurable.
+     * See DB_result::fetchInto() for more information.
+     *
+     * @param resource $result    query result identifier
+     * @param array    $arr       (reference) array where data from the row
+     *                            should be placed
+     * @param int      $fetchmode how the resulting array should be indexed
+     * @param int      $rownum    the row number to fetch
+     *
+     * @return mixed DB_OK on success, NULL when end of result set is
+     *               reached or on failure
+     *
+     * @see DB_result::fetchInto()
+     * @access private
+     */
+    function fetchInto($result, &$arr, $fetchmode, $rownum=null)
+    {
+        if ($rownum === null) {
+            $rownum = $this->res_row[$result]++;
+        }
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            $arr = @dbase_get_record_with_names($this->connection, $rownum);
+            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
+                $arr = array_change_key_case($arr, CASE_LOWER);
+            }
+        } else {
+            $arr = @dbase_get_record($this->connection, $rownum);
+        }
+        if (!$arr) {
+            return null;
+        }
+        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
+            $this->_rtrimArrayValues($arr);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    function numCols($foo)
+    {
+        return dbase_numfields($this->connection);
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    function numRows($foo)
+    {
+        return dbase_numrecords($this->connection);
+    }
+
+    // }}}
+    // {{{ quoteSmart()
+
+    /**
+     * Format input so it can be safely used in a query
+     *
+     * @param mixed $in  data to be quoted
+     *
+     * @return mixed Submitted variable's type = returned value:
+     *               + null = the string <samp>NULL</samp>
+     *               + boolean = <samp>T</samp> if true or
+     *                 <samp>F</samp> if false.  Use the <kbd>Logical</kbd>
+     *                 data type.
+     *               + integer or double = the unquoted number
+     *               + other (including strings and numeric strings) =
+     *                 the data with single quotes escaped by preceeding
+     *                 single quotes then the whole string is encapsulated
+     *                 between single quotes
+     *
+     * @internal
+     */
+    function quoteSmart($in)
+    {
+        if (is_int($in) || is_double($in)) {
+            return $in;
+        } elseif (is_bool($in)) {
+            return $in ? 'T' : 'F';
+        } elseif (is_null($in)) {
+            return 'NULL';
+        } else {
+            return "'" . $this->escapeSimple($in) . "'";
+        }
+    }
+
+    // }}}
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/fbsql.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/fbsql.php
new file mode 100755 (executable)
index 0000000..73093c4
--- /dev/null
@@ -0,0 +1,652 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Frank M. Kromann <frank@frontbase.com>                       |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+
+// XXX legend:
+//
+// XXX ERRORMSG: The error message from the fbsql function should
+//               be registered here.
+//
+// TODO/wishlist:
+// longReadlen
+// binmode
+
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's FrontBase
+ * extension.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Frank M. Kromann <frank@frontbase.com>
+ */
+class DB_fbsql extends DB_common
+{
+    // {{{ properties
+
+    var $connection;
+    var $phptype, $dbsyntax;
+    var $prepare_tokens = array();
+    var $prepare_types = array();
+    var $num_rows = array();
+    var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * DB_fbsql constructor.
+     *
+     * @access public
+     */
+    function DB_fbsql()
+    {
+        $this->DB_common();
+        $this->phptype = 'fbsql';
+        $this->dbsyntax = 'fbsql';
+        $this->features = array(
+            'prepare' => false,
+            'pconnect' => true,
+            'transactions' => true,
+            'limit' => 'emulate'
+        );
+        $this->errorcode_map = array(
+            1004 => DB_ERROR_CANNOT_CREATE,
+            1005 => DB_ERROR_CANNOT_CREATE,
+            1006 => DB_ERROR_CANNOT_CREATE,
+            1007 => DB_ERROR_ALREADY_EXISTS,
+            1008 => DB_ERROR_CANNOT_DROP,
+            1046 => DB_ERROR_NODBSELECTED,
+            1050 => DB_ERROR_ALREADY_EXISTS,
+            1051 => DB_ERROR_NOSUCHTABLE,
+            1054 => DB_ERROR_NOSUCHFIELD,
+            1062 => DB_ERROR_ALREADY_EXISTS,
+            1064 => DB_ERROR_SYNTAX,
+            1100 => DB_ERROR_NOT_LOCKED,
+            1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
+            1146 => DB_ERROR_NOSUCHTABLE,
+        );
+    }
+
+    // }}}
+    // {{{ connect()
+
+    /**
+     * Connect to a database and log in as the specified user.
+     *
+     * @param $dsn the data source name (see DB::parseDSN for syntax)
+     * @param $persistent (optional) whether the connection should
+     *        be persistent
+     * @access public
+     * @return int DB_OK on success, a DB error on failure
+     */
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('fbsql')) {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+
+        $this->dsn = $dsninfo;
+        $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
+
+        $php_errormsg = '';
+        $connect_function = $persistent ? 'fbsql_pconnect' : 'fbsql_connect';
+
+        if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
+            $conn = @$connect_function($dbhost, $dsninfo['username'],
+                                       $dsninfo['password']);
+        } elseif ($dbhost && $dsninfo['username']) {
+            $conn = @$connect_function($dbhost, $dsninfo['username']);
+        } elseif ($dbhost) {
+            $conn = @$connect_function($dbhost);
+        } else {
+            $conn = false;
+        }
+        if (!$conn) {
+            if (empty($php_errormsg)) {
+                return $this->raiseError(DB_ERROR_CONNECT_FAILED);
+            } else {
+                return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
+                                         null, $php_errormsg);
+            }
+        }
+
+        if ($dsninfo['database']) {
+            if (!fbsql_select_db($dsninfo['database'], $conn)) {
+                return $this->fbsqlRaiseError();
+            }
+        }
+
+        $this->connection = $conn;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ disconnect()
+
+    /**
+     * Log out and disconnect from the database.
+     *
+     * @access public
+     *
+     * @return bool TRUE on success, FALSE if not connected.
+     */
+    function disconnect()
+    {
+        $ret = fbsql_close($this->connection);
+        $this->connection = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ simpleQuery()
+
+    /**
+     * Send a query to fbsql and return the results as a fbsql resource
+     * identifier.
+     *
+     * @param the SQL query
+     *
+     * @access public
+     *
+     * @return mixed returns a valid fbsql result for successful SELECT
+     * queries, DB_OK for other successful queries.  A DB error is
+     * returned on failure.
+     */
+    function simpleQuery($query)
+    {
+        $this->last_query = $query;
+        $query = $this->modifyQuery($query);
+        $result = @fbsql_query("$query;", $this->connection);
+        if (!$result) {
+            return $this->fbsqlRaiseError();
+        }
+        // Determine which queries that should return data, and which
+        // should return an error code only.
+        if (DB::isManip($query)) {
+            return DB_OK;
+        }
+        $numrows = $this->numrows($result);
+        if (is_object($numrows)) {
+            return $numrows;
+        }
+        $this->num_rows[$result] = $numrows;
+        return $result;
+    }
+
+    // }}}
+    // {{{ nextResult()
+
+    /**
+     * Move the internal fbsql result pointer to the next available result
+     *
+     * @param a valid fbsql result resource
+     *
+     * @access public
+     *
+     * @return true if a result is available otherwise return false
+     */
+    function nextResult($result)
+    {
+        return @fbsql_next_result($result);
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row and insert the data into an existing array.
+     *
+     * Formating of the array and the data therein are configurable.
+     * See DB_result::fetchInto() for more information.
+     *
+     * @param resource $result    query result identifier
+     * @param array    $arr       (reference) array where data from the row
+     *                            should be placed
+     * @param int      $fetchmode how the resulting array should be indexed
+     * @param int      $rownum    the row number to fetch
+     *
+     * @return mixed DB_OK on success, NULL when end of result set is
+     *               reached or on failure
+     *
+     * @see DB_result::fetchInto()
+     * @access private
+     */
+    function fetchInto($result, &$arr, $fetchmode, $rownum=null)
+    {
+        if ($rownum !== null) {
+            if (!@fbsql_data_seek($result, $rownum)) {
+                return null;
+            }
+        }
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            $arr = @fbsql_fetch_array($result, FBSQL_ASSOC);
+            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
+                $arr = array_change_key_case($arr, CASE_LOWER);
+            }
+        } else {
+            $arr = @fbsql_fetch_row($result);
+        }
+        if (!$arr) {
+            $errno = @fbsql_errno($this->connection);
+            if (!$errno) {
+                return NULL;
+            }
+            return $this->fbsqlRaiseError($errno);
+        }
+        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
+            $this->_rtrimArrayValues($arr);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ freeResult()
+
+    /**
+     * Free the internal resources associated with $result.
+     *
+     * @param $result fbsql result identifier
+     *
+     * @access public
+     *
+     * @return bool TRUE on success, FALSE if $result is invalid
+     */
+    function freeResult($result)
+    {
+        return @fbsql_free_result($result);
+    }
+
+    // }}}
+    // {{{ autoCommit()
+
+    function autoCommit($onoff=false)
+    {
+        if ($onoff) {
+            $this->query("SET COMMIT TRUE");
+        } else {
+            $this->query("SET COMMIT FALSE");
+        }
+    }
+
+    // }}}
+    // {{{ commit()
+
+    function commit()
+    {
+        fbsql_commit();
+    }
+
+    // }}}
+    // {{{ rollback()
+
+    function rollback()
+    {
+        fbsql_rollback();
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    /**
+     * Get the number of columns in a result set.
+     *
+     * @param $result fbsql result identifier
+     *
+     * @access public
+     *
+     * @return int the number of columns per row in $result
+     */
+    function numCols($result)
+    {
+        $cols = @fbsql_num_fields($result);
+
+        if (!$cols) {
+            return $this->fbsqlRaiseError();
+        }
+
+        return $cols;
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    /**
+     * Get the number of rows in a result set.
+     *
+     * @param $result fbsql result identifier
+     *
+     * @access public
+     *
+     * @return int the number of rows in $result
+     */
+    function numRows($result)
+    {
+        $rows = @fbsql_num_rows($result);
+        if ($rows === null) {
+            return $this->fbsqlRaiseError();
+        }
+        return $rows;
+    }
+
+    // }}}
+    // {{{ affectedRows()
+
+    /**
+     * Gets the number of rows affected by the data manipulation
+     * query.  For other queries, this function returns 0.
+     *
+     * @return number of rows affected by the last query
+     */
+    function affectedRows()
+    {
+        if (DB::isManip($this->last_query)) {
+            $result = @fbsql_affected_rows($this->connection);
+        } else {
+            $result = 0;
+        }
+        return $result;
+     }
+
+    // }}}
+    // {{{ errorNative()
+
+    /**
+     * Get the native error code of the last error (if any) that
+     * occured on the current connection.
+     *
+     * @access public
+     *
+     * @return int native fbsql error code
+     */
+    function errorNative()
+    {
+        return fbsql_errno($this->connection);
+    }
+
+    // }}}
+    // {{{ nextId()
+
+    /**
+     * Returns the next free id in a sequence
+     *
+     * @param string  $seq_name  name of the sequence
+     * @param boolean $ondemand  when true, the seqence is automatically
+     *                           created if it does not exist
+     *
+     * @return int  the next id number in the sequence.  DB_Error if problem.
+     *
+     * @internal
+     * @see DB_common::nextID()
+     * @access public
+     */
+    function nextId($seq_name, $ondemand = true)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        $repeat = 0;
+        do {
+            $result = $this->query("INSERT INTO ${seqname} VALUES(NULL)");
+            if ($ondemand && DB::isError($result) &&
+                $result->getCode() == DB_ERROR_NOSUCHTABLE) {
+                $repeat = 1;
+                $result = $this->createSequence($seq_name);
+                if (DB::isError($result)) {
+                    return $result;
+                }
+            } else {
+                $repeat = 0;
+            }
+        } while ($repeat);
+        if (DB::isError($result)) {
+            return $result;
+        }
+        return fbsql_insert_id($this->connection);
+    }
+
+    /**
+     * Creates a new sequence
+     *
+     * @param string $seq_name  name of the new sequence
+     *
+     * @return int  DB_OK on success.  A DB_Error object is returned if
+     *              problems arise.
+     *
+     * @internal
+     * @see DB_common::createSequence()
+     * @access public
+     */
+    function createSequence($seq_name)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        return $this->query("CREATE TABLE ${seqname} ".
+                            '(id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'.
+                            ' PRIMARY KEY(id))');
+    }
+
+    // }}}
+    // {{{ dropSequence()
+
+    /**
+     * Deletes a sequence
+     *
+     * @param string $seq_name  name of the sequence to be deleted
+     *
+     * @return int  DB_OK on success.  DB_Error if problems.
+     *
+     * @internal
+     * @see DB_common::dropSequence()
+     * @access public
+     */
+    function dropSequence($seq_name)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        return $this->query("DROP TABLE ${seqname} RESTRICT");
+    }
+
+    // }}}
+    // {{{ modifyQuery()
+
+    function modifyQuery($query)
+    {
+        if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
+            // "DELETE FROM table" gives 0 affected rows in fbsql.
+            // This little hack lets you know how many rows were deleted.
+            if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
+                $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
+                                      'DELETE FROM \1 WHERE 1=1', $query);
+            }
+        }
+        return $query;
+    }
+
+    // }}}
+    // {{{ quoteSmart()
+
+    /**
+     * Format input so it can be safely used in a query
+     *
+     * @param mixed $in  data to be quoted
+     *
+     * @return mixed Submitted variable's type = returned value:
+     *               + null = the string <samp>NULL</samp>
+     *               + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp>
+     *               + integer or double = the unquoted number
+     *               + other (including strings and numeric strings) =
+     *                 the data escaped according to MySQL's settings
+     *                 then encapsulated between single quotes
+     *
+     * @internal
+     */
+    function quoteSmart($in)
+    {
+        if (is_int($in) || is_double($in)) {
+            return $in;
+        } elseif (is_bool($in)) {
+            return $in ? 'TRUE' : 'FALSE';
+        } elseif (is_null($in)) {
+            return 'NULL';
+        } else {
+            return "'" . $this->escapeSimple($in) . "'";
+        }
+    }
+
+    // }}}
+    // {{{ fbsqlRaiseError()
+
+    /**
+     * Gather information about an error, then use that info to create a
+     * DB error object and finally return that object.
+     *
+     * @param  integer  $errno  PEAR error number (usually a DB constant) if
+     *                          manually raising an error
+     * @return object  DB error object
+     * @see DB_common::errorCode()
+     * @see DB_common::raiseError()
+     */
+    function fbsqlRaiseError($errno = null)
+    {
+        if ($errno === null) {
+            $errno = $this->errorCode(fbsql_errno($this->connection));
+        }
+        return $this->raiseError($errno, null, null, null,
+                        fbsql_error($this->connection));
+    }
+
+    // }}}
+    // {{{ tableInfo()
+
+    /**
+     * Returns information about a table or a result set.
+     *
+     * @param object|string  $result  DB_result object from a query or a
+     *                                string containing the name of a table
+     * @param int            $mode    a valid tableInfo mode
+     * @return array  an associative array with the information requested
+     *                or an error object if something is wrong
+     * @access public
+     * @internal
+     * @see DB_common::tableInfo()
+     */
+    function tableInfo($result, $mode = null) {
+        if (isset($result->result)) {
+            /*
+             * Probably received a result object.
+             * Extract the result resource identifier.
+             */
+            $id = $result->result;
+            $got_string = false;
+        } elseif (is_string($result)) {
+            /*
+             * Probably received a table name.
+             * Create a result resource identifier.
+             */
+            $id = @fbsql_list_fields($this->dsn['database'],
+                                     $result, $this->connection);
+            $got_string = true;
+        } else {
+            /*
+             * Probably received a result resource identifier.
+             * Copy it.
+             * Depricated.  Here for compatibility only.
+             */
+            $id = $result;
+            $got_string = false;
+        }
+
+        if (!is_resource($id)) {
+            return $this->fbsqlRaiseError(DB_ERROR_NEED_MORE_DATA);
+        }
+
+        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
+            $case_func = 'strtolower';
+        } else {
+            $case_func = 'strval';
+        }
+
+        $count = @fbsql_num_fields($id);
+
+        // made this IF due to performance (one if is faster than $count if's)
+        if (!$mode) {
+            for ($i=0; $i<$count; $i++) {
+                $res[$i]['table'] = $case_func(@fbsql_field_table($id, $i));
+                $res[$i]['name']  = $case_func(@fbsql_field_name($id, $i));
+                $res[$i]['type']  = @fbsql_field_type($id, $i);
+                $res[$i]['len']   = @fbsql_field_len($id, $i);
+                $res[$i]['flags'] = @fbsql_field_flags($id, $i);
+            }
+        } else { // full
+            $res["num_fields"]= $count;
+
+            for ($i=0; $i<$count; $i++) {
+                $res[$i]['table'] = $case_func(@fbsql_field_table($id, $i));
+                $res[$i]['name']  = $case_func(@fbsql_field_name($id, $i));
+                $res[$i]['type']  = @fbsql_field_type($id, $i);
+                $res[$i]['len']   = @fbsql_field_len($id, $i);
+                $res[$i]['flags'] = @fbsql_field_flags($id, $i);
+
+                if ($mode & DB_TABLEINFO_ORDER) {
+                    $res['order'][$res[$i]['name']] = $i;
+                }
+                if ($mode & DB_TABLEINFO_ORDERTABLE) {
+                    $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
+                }
+            }
+        }
+
+        // free the result only if we were called on a table
+        if ($got_string) {
+            @fbsql_free_result($id);
+        }
+        return $res;
+    }
+
+    // }}}
+    // {{{ getSpecialQuery()
+
+    /**
+     * Returns the query needed to get some backend info
+     * @param string $type What kind of info you want to retrieve
+     * @return string The SQL query string
+     */
+    function getSpecialQuery($type)
+    {
+        switch ($type) {
+            case 'tables':
+                return 'select "table_name" from information_schema.tables';
+            default:
+                return null;
+        }
+    }
+
+    // }}}
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/ibase.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/ibase.php
new file mode 100755 (executable)
index 0000000..0d68979
--- /dev/null
@@ -0,0 +1,780 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Sterling Hughes <sterling@php.net>                           |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+
+// Bugs:
+//  - If dbsyntax is not firebird, the limitQuery may fail
+
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's Interbase
+ * extension.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Sterling Hughes <sterling@php.net>
+ */
+class DB_ibase extends DB_common
+{
+
+    // {{{ properties
+
+    var $connection;
+    var $phptype, $dbsyntax;
+    var $autocommit = 1;
+    var $manip_query = array();
+
+    // }}}
+    // {{{ constructor
+
+    function DB_ibase()
+    {
+        $this->DB_common();
+        $this->phptype = 'ibase';
+        $this->dbsyntax = 'ibase';
+        $this->features = array(
+            'prepare' => true,
+            'pconnect' => true,
+            'transactions' => true,
+            'limit' => false
+        );
+        // just a few of the tons of Interbase error codes listed in the
+        // Language Reference section of the Interbase manual
+        $this->errorcode_map = array(
+            -104 => DB_ERROR_SYNTAX,
+            -150 => DB_ERROR_ACCESS_VIOLATION,
+            -151 => DB_ERROR_ACCESS_VIOLATION,
+            -155 => DB_ERROR_NOSUCHTABLE,
+            88   => DB_ERROR_NOSUCHTABLE,
+            -157 => DB_ERROR_NOSUCHFIELD,
+            -158 => DB_ERROR_VALUE_COUNT_ON_ROW,
+            -170 => DB_ERROR_MISMATCH,
+            -171 => DB_ERROR_MISMATCH,
+            -172 => DB_ERROR_INVALID,
+            -204 => DB_ERROR_INVALID,
+            -205 => DB_ERROR_NOSUCHFIELD,
+            -206 => DB_ERROR_NOSUCHFIELD,
+            -208 => DB_ERROR_INVALID,
+            -219 => DB_ERROR_NOSUCHTABLE,
+            -297 => DB_ERROR_CONSTRAINT,
+            -530 => DB_ERROR_CONSTRAINT,
+            -607 => DB_ERROR_NOSUCHTABLE,
+            -803 => DB_ERROR_CONSTRAINT,
+            -551 => DB_ERROR_ACCESS_VIOLATION,
+            -552 => DB_ERROR_ACCESS_VIOLATION,
+            -922 => DB_ERROR_NOSUCHDB,
+            -923 => DB_ERROR_CONNECT_FAILED,
+            -924 => DB_ERROR_CONNECT_FAILED
+        );
+    }
+
+    // }}}
+    // {{{ connect()
+
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('interbase')) {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+        $this->dsn = $dsninfo;
+        $dbhost = $dsninfo['hostspec'] ?
+                  ($dsninfo['hostspec'] . ':' . $dsninfo['database']) :
+                  $dsninfo['database'];
+
+        $connect_function = $persistent ? 'ibase_pconnect' : 'ibase_connect';
+
+        $params = array();
+        $params[] = $dbhost;
+        $params[] = $dsninfo['username'] ? $dsninfo['username'] : null;
+        $params[] = $dsninfo['password'] ? $dsninfo['password'] : null;
+        $params[] = isset($dsninfo['charset']) ? $dsninfo['charset'] : null;
+        $params[] = isset($dsninfo['buffers']) ? $dsninfo['buffers'] : null;
+        $params[] = isset($dsninfo['dialect']) ? $dsninfo['dialect'] : null;
+        $params[] = isset($dsninfo['role'])    ? $dsninfo['role'] : null;
+
+        $conn = @call_user_func_array($connect_function, $params);
+        if (!$conn) {
+            return $this->ibaseRaiseError(DB_ERROR_CONNECT_FAILED);
+        }
+        $this->connection = $conn;
+        if ($this->dsn['dbsyntax'] == 'firebird') {
+            $this->features['limit'] = 'alter';
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ disconnect()
+
+    function disconnect()
+    {
+        $ret = @ibase_close($this->connection);
+        $this->connection = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ simpleQuery()
+
+    function simpleQuery($query)
+    {
+        $ismanip = DB::isManip($query);
+        $this->last_query = $query;
+        $query = $this->modifyQuery($query);
+        $result = @ibase_query($this->connection, $query);
+        if (!$result) {
+            return $this->ibaseRaiseError();
+        }
+        if ($this->autocommit && $ismanip) {
+            ibase_commit($this->connection);
+        }
+        // Determine which queries that should return data, and which
+        // should return an error code only.
+        return $ismanip ? DB_OK : $result;
+    }
+
+    // }}}
+    // {{{ modifyLimitQuery()
+
+    /**
+     * This method is used by backends to alter limited queries
+     * Uses the new FIRST n SKIP n Firebird 1.0 syntax, so it is
+     * only compatible with Firebird 1.x
+     *
+     * @param string  $query query to modify
+     * @param integer $from  the row to start to fetching
+     * @param integer $count the numbers of rows to fetch
+     *
+     * @return the new (modified) query
+     * @author Ludovico Magnocavallo <ludo@sumatrasolutions.com>
+     * @access private
+     */
+    function modifyLimitQuery($query, $from, $count)
+    {
+        if ($this->dsn['dbsyntax'] == 'firebird') {
+            //$from++; // SKIP starts from 1, ie SKIP 1 starts from the first record
+                           // (cox) Seems that SKIP starts in 0
+            $query = preg_replace('/^\s*select\s(.*)$/is',
+                                  "SELECT FIRST $count SKIP $from $1", $query);
+        }
+        return $query;
+    }
+
+    // }}}
+    // {{{ nextResult()
+
+    /**
+     * Move the internal ibase result pointer to the next available result
+     *
+     * @param a valid fbsql result resource
+     *
+     * @access public
+     *
+     * @return true if a result is available otherwise return false
+     */
+    function nextResult($result)
+    {
+        return false;
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row and insert the data into an existing array.
+     *
+     * Formating of the array and the data therein are configurable.
+     * See DB_result::fetchInto() for more information.
+     *
+     * @param resource $result    query result identifier
+     * @param array    $arr       (reference) array where data from the row
+     *                            should be placed
+     * @param int      $fetchmode how the resulting array should be indexed
+     * @param int      $rownum    the row number to fetch
+     *
+     * @return mixed DB_OK on success, NULL when end of result set is
+     *               reached or on failure
+     *
+     * @see DB_result::fetchInto()
+     * @access private
+     */
+    function fetchInto($result, &$arr, $fetchmode, $rownum=null)
+    {
+        if ($rownum !== NULL) {
+            return $this->ibaseRaiseError(DB_ERROR_NOT_CAPABLE);
+        }
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            if (function_exists('ibase_fetch_assoc')) {
+                $arr = @ibase_fetch_assoc($result);
+            } else {
+                $arr = get_object_vars(ibase_fetch_object($result));
+            }
+            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
+                $arr = array_change_key_case($arr, CASE_LOWER);
+            }
+        } else {
+            $arr = @ibase_fetch_row($result);
+        }
+        if (!$arr) {
+            if ($errmsg = ibase_errmsg()) {
+                return $this->ibaseRaiseError(null, $errmsg);
+            } else {
+                return null;
+            }
+        }
+        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
+            $this->_rtrimArrayValues($arr);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ freeResult()
+
+    function freeResult($result)
+    {
+        return @ibase_free_result($result);
+    }
+
+    // }}}
+    // {{{ freeQuery()
+
+    function freeQuery($query)
+    {
+        ibase_free_query($query);
+        return true;
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    function numCols($result)
+    {
+        $cols = ibase_num_fields($result);
+        if (!$cols) {
+            return $this->ibaseRaiseError();
+        }
+        return $cols;
+    }
+
+    // }}}
+    // {{{ prepare()
+
+    /**
+     * Prepares a query for multiple execution with execute().
+     *
+     * prepare() requires a generic query as string like <code>
+     *    INSERT INTO numbers VALUES (?, ?, ?)
+     * </code>.  The <kbd>?</kbd> characters are placeholders.
+     *
+     * Three types of placeholders can be used:
+     *   + <kbd>?</kbd>  a quoted scalar value, i.e. strings, integers
+     *   + <kbd>!</kbd>  value is inserted 'as is'
+     *   + <kbd>&</kbd>  requires a file name.  The file's contents get
+     *                     inserted into the query (i.e. saving binary
+     *                     data in a db)
+     *
+     * Use backslashes to escape placeholder characters if you don't want
+     * them to be interpreted as placeholders.  Example: <code>
+     *    "UPDATE foo SET col=? WHERE col='over \& under'"
+     * </code>
+     *
+     * @param string $query query to be prepared
+     * @return mixed DB statement resource on success. DB_Error on failure.
+     */
+    function prepare($query)
+    {
+        $tokens   = preg_split('/((?<!\\\)[&?!])/', $query, -1,
+                               PREG_SPLIT_DELIM_CAPTURE);
+        $token    = 0;
+        $types    = array();
+        $newquery = '';
+
+        foreach ($tokens as $key => $val) {
+            switch ($val) {
+                case '?':
+                    $types[$token++] = DB_PARAM_SCALAR;
+                    break;
+                case '&':
+                    $types[$token++] = DB_PARAM_OPAQUE;
+                    break;
+                case '!':
+                    $types[$token++] = DB_PARAM_MISC;
+                    break;
+                default:
+                    $tokens[$key] = preg_replace('/\\\([&?!])/', "\\1", $val);
+                    $newquery .= $tokens[$key] . '?';
+            }
+        }
+
+        $newquery = substr($newquery, 0, -1);
+        $this->last_query = $query;
+        $newquery = $this->modifyQuery($newquery);
+        $stmt = ibase_prepare($this->connection, $newquery);
+        $this->prepare_types[(int)$stmt] = $types;
+        $this->manip_query[(int)$stmt]   = DB::isManip($query);
+        return $stmt;
+    }
+
+    // }}}
+    // {{{ execute()
+
+    /**
+     * Executes a DB statement prepared with prepare().
+     *
+     * @param resource  $stmt  a DB statement resource returned from prepare()
+     * @param mixed  $data  array, string or numeric data to be used in
+     *                      execution of the statement.  Quantity of items
+     *                      passed must match quantity of placeholders in
+     *                      query:  meaning 1 for non-array items or the
+     *                      quantity of elements in the array.
+     * @return object  a new DB_Result or a DB_Error when fail
+     * @see DB_ibase::prepare()
+     * @access public
+     */
+    function &execute($stmt, $data = array())
+    {
+        if (!is_array($data)) {
+            $data = array($data);
+        }
+
+        $types =& $this->prepare_types[$stmt];
+        if (count($types) != count($data)) {
+            $tmp =& $this->raiseError(DB_ERROR_MISMATCH);
+            return $tmp;
+        }
+
+        $i = 0;
+        foreach ($data as $key => $value) {
+            if ($types[$i] == DB_PARAM_MISC) {
+                /*
+                 * ibase doesn't seem to have the ability to pass a
+                 * parameter along unchanged, so strip off quotes from start
+                 * and end, plus turn two single quotes to one single quote,
+                 * in order to avoid the quotes getting escaped by
+                 * ibase and ending up in the database.
+                 */
+                $data[$key] = preg_replace("/^'(.*)'$/", "\\1", $data[$key]);
+                $data[$key] = str_replace("''", "'", $data[$key]);
+            } elseif ($types[$i] == DB_PARAM_OPAQUE) {
+                $fp = @fopen($data[$key], 'rb');
+                if (!$fp) {
+                    $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
+                    return $tmp;
+                }
+                $data[$key] = fread($fp, filesize($data[$key]));
+                fclose($fp);
+            }
+            $i++;
+        }
+
+        array_unshift($data, $stmt);
+
+        $res = call_user_func_array('ibase_execute', $data);
+        if (!$res) {
+            $tmp =& $this->ibaseRaiseError();
+            return $tmp;
+        }
+        /* XXX need this?
+        if ($this->autocommit && $this->manip_query[(int)$stmt]) {
+            ibase_commit($this->connection);
+        }*/
+        if ($this->manip_query[(int)$stmt]) {
+            $tmp = DB_OK;
+        } else {
+            $tmp =& new DB_result($this, $res);
+        }
+        return $tmp;
+    }
+
+    /**
+     * Free the internal resources associated with a prepared query.
+     *
+     * @param $stmt The interbase_query resource type
+     *
+     * @return bool TRUE on success, FALSE if $result is invalid
+     */
+    function freePrepared($stmt)
+    {
+        if (!is_resource($stmt)) {
+            return false;
+        }
+        ibase_free_query($stmt);
+        unset($this->prepare_tokens[(int)$stmt]);
+        unset($this->prepare_types[(int)$stmt]);
+        unset($this->manip_query[(int)$stmt]);
+        return true;
+    }
+
+    // }}}
+    // {{{ autoCommit()
+
+    function autoCommit($onoff = false)
+    {
+        $this->autocommit = $onoff ? 1 : 0;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ commit()
+
+    function commit()
+    {
+        return ibase_commit($this->connection);
+    }
+
+    // }}}
+    // {{{ rollback()
+
+    function rollback($trans_number)
+    {
+        return ibase_rollback($this->connection, $trans_number);
+    }
+
+    // }}}
+    // {{{ transactionInit()
+
+    function transactionInit($trans_args = 0)
+    {
+        return $trans_args ? ibase_trans($trans_args, $this->connection) : ibase_trans();
+    }
+
+    // }}}
+    // {{{ nextId()
+
+    /**
+     * Returns the next free id in a sequence
+     *
+     * @param string  $seq_name  name of the sequence
+     * @param boolean $ondemand  when true, the seqence is automatically
+     *                           created if it does not exist
+     *
+     * @return int  the next id number in the sequence.  DB_Error if problem.
+     *
+     * @internal
+     * @see DB_common::nextID()
+     * @access public
+     */
+    function nextId($seq_name, $ondemand = true)
+    {
+        $sqn = strtoupper($this->getSequenceName($seq_name));
+        $repeat = 0;
+        do {
+            $this->pushErrorHandling(PEAR_ERROR_RETURN);
+            $result =& $this->query("SELECT GEN_ID(${sqn}, 1) "
+                                   . 'FROM RDB$GENERATORS '
+                                   . "WHERE RDB\$GENERATOR_NAME='${sqn}'");
+            $this->popErrorHandling();
+            if ($ondemand && DB::isError($result)) {
+                $repeat = 1;
+                $result = $this->createSequence($seq_name);
+                if (DB::isError($result)) {
+                    return $result;
+                }
+            } else {
+                $repeat = 0;
+            }
+        } while ($repeat);
+        if (DB::isError($result)) {
+            return $this->raiseError($result);
+        }
+        $arr = $result->fetchRow(DB_FETCHMODE_ORDERED);
+        $result->free();
+        return $arr[0];
+    }
+
+    // }}}
+    // {{{ createSequence()
+
+    /**
+     * Create the sequence
+     *
+     * @param string $seq_name the name of the sequence
+     * @return mixed DB_OK on success or DB error on error
+     * @access public
+     */
+    function createSequence($seq_name)
+    {
+        $sqn = strtoupper($this->getSequenceName($seq_name));
+        $this->pushErrorHandling(PEAR_ERROR_RETURN);
+        $result = $this->query("CREATE GENERATOR ${sqn}");
+        $this->popErrorHandling();
+
+        return $result;
+    }
+
+    // }}}
+    // {{{ dropSequence()
+
+    /**
+     * Drop a sequence
+     *
+     * @param string $seq_name the name of the sequence
+     * @return mixed DB_OK on success or DB error on error
+     * @access public
+     */
+    function dropSequence($seq_name)
+    {
+        $sqn = strtoupper($this->getSequenceName($seq_name));
+        return $this->query('DELETE FROM RDB$GENERATORS '
+                            . "WHERE RDB\$GENERATOR_NAME='${sqn}'");
+    }
+
+    // }}}
+    // {{{ _ibaseFieldFlags()
+
+    /**
+     * get the Flags of a Field
+     *
+     * @param string $field_name the name of the field
+     * @param string $table_name the name of the table
+     *
+     * @return string The flags of the field ("primary_key", "unique_key", "not_null"
+     *                "default", "computed" and "blob" are supported)
+     * @access private
+     */
+    function _ibaseFieldFlags($field_name, $table_name)
+    {
+        $sql = 'SELECT R.RDB$CONSTRAINT_TYPE CTYPE'
+               .' FROM RDB$INDEX_SEGMENTS I'
+               .'  JOIN RDB$RELATION_CONSTRAINTS R ON I.RDB$INDEX_NAME=R.RDB$INDEX_NAME'
+               .' WHERE I.RDB$FIELD_NAME=\'' . $field_name . '\''
+               .'  AND UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\'';
+
+        $result = ibase_query($this->connection, $sql);
+        if (!$result) {
+            return $this->ibaseRaiseError();
+        }
+
+        $flags = '';
+        if ($obj = @ibase_fetch_object($result)) {
+            ibase_free_result($result);
+            if (isset($obj->CTYPE)  && trim($obj->CTYPE) == 'PRIMARY KEY') {
+                $flags .= 'primary_key ';
+            }
+            if (isset($obj->CTYPE)  && trim($obj->CTYPE) == 'UNIQUE') {
+                $flags .= 'unique_key ';
+            }
+        }
+
+        $sql = 'SELECT R.RDB$NULL_FLAG AS NFLAG,'
+               .'  R.RDB$DEFAULT_SOURCE AS DSOURCE,'
+               .'  F.RDB$FIELD_TYPE AS FTYPE,'
+               .'  F.RDB$COMPUTED_SOURCE AS CSOURCE'
+               .' FROM RDB$RELATION_FIELDS R '
+               .'  JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME'
+               .' WHERE UPPER(R.RDB$RELATION_NAME)=\'' . strtoupper($table_name) . '\''
+               .'  AND R.RDB$FIELD_NAME=\'' . $field_name . '\'';
+
+        $result = ibase_query($this->connection, $sql);
+        if (!$result) {
+            return $this->ibaseRaiseError();
+        }
+        if ($obj = @ibase_fetch_object($result)) {
+            ibase_free_result($result);
+            if (isset($obj->NFLAG)) {
+                $flags .= 'not_null ';
+            }
+            if (isset($obj->DSOURCE)) {
+                $flags .= 'default ';
+            }
+            if (isset($obj->CSOURCE)) {
+                $flags .= 'computed ';
+            }
+            if (isset($obj->FTYPE)  && $obj->FTYPE == 261) {
+                $flags .= 'blob ';
+            }
+        }
+
+        return trim($flags);
+    }
+
+    // }}}
+    // {{{ tableInfo()
+
+    /**
+     * Returns information about a table or a result set.
+     *
+     * NOTE: only supports 'table' and 'flags' if <var>$result</var>
+     * is a table name.
+     *
+     * @param object|string  $result  DB_result object from a query or a
+     *                                string containing the name of a table
+     * @param int            $mode    a valid tableInfo mode
+     * @return array  an associative array with the information requested
+     *                or an error object if something is wrong
+     * @access public
+     * @internal
+     * @see DB_common::tableInfo()
+     */
+    function tableInfo($result, $mode = null)
+    {
+        if (isset($result->result)) {
+            /*
+             * Probably received a result object.
+             * Extract the result resource identifier.
+             */
+            $id = $result->result;
+            $got_string = false;
+        } elseif (is_string($result)) {
+            /*
+             * Probably received a table name.
+             * Create a result resource identifier.
+             */
+             $id = @ibase_query($this->connection,
+                                "SELECT * FROM $result WHERE 1=0");
+            $got_string = true;
+        } else {
+            /*
+             * Probably received a result resource identifier.
+             * Copy it.
+             * Depricated.  Here for compatibility only.
+             */
+             $id = $result;
+            $got_string = false;
+        }
+
+        if (!is_resource($id)) {
+            return $this->ibaseRaiseError(DB_ERROR_NEED_MORE_DATA);
+        }
+
+        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
+            $case_func = 'strtolower';
+        } else {
+            $case_func = 'strval';
+        }
+
+        $count = @ibase_num_fields($id);
+
+        // made this IF due to performance (one if is faster than $count if's)
+        if (!$mode) {
+            for ($i=0; $i<$count; $i++) {
+                $info = @ibase_field_info($id, $i);
+                $res[$i]['table'] = $got_string ? $case_func($result) : '';
+                $res[$i]['name']  = $case_func($info['name']);
+                $res[$i]['type']  = $info['type'];
+                $res[$i]['len']   = $info['length'];
+                $res[$i]['flags'] = ($got_string) ? $this->_ibaseFieldFlags($info['name'], $result) : '';
+            }
+        } else { // full
+            $res['num_fields']= $count;
+
+            for ($i=0; $i<$count; $i++) {
+                $info = @ibase_field_info($id, $i);
+                $res[$i]['table'] = $got_string ? $case_func($result) : '';
+                $res[$i]['name']  = $case_func($info['name']);
+                $res[$i]['type']  = $info['type'];
+                $res[$i]['len']   = $info['length'];
+                $res[$i]['flags'] = ($got_string) ? $this->_ibaseFieldFlags($info['name'], $result) : '';
+
+                if ($mode & DB_TABLEINFO_ORDER) {
+                    $res['order'][$res[$i]['name']] = $i;
+                }
+                if ($mode & DB_TABLEINFO_ORDERTABLE) {
+                    $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
+                }
+            }
+        }
+
+        // free the result only if we were called on a table
+        if ($got_string) {
+            ibase_free_result($id);
+        }
+        return $res;
+    }
+
+    // }}}
+    // {{{ ibaseRaiseError()
+
+    /**
+     * Gather information about an error, then use that info to create a
+     * DB error object and finally return that object.
+     *
+     * @param  integer  $db_errno  PEAR error number (usually a DB constant) if
+     *                             manually raising an error
+     * @param  string  $native_errmsg  text of error message if known
+     * @return object  DB error object
+     * @see DB_common::errorCode()
+     * @see DB_common::raiseError()
+     */
+    function &ibaseRaiseError($db_errno = null, $native_errmsg = null)
+    {
+        if ($native_errmsg === null) {
+            $native_errmsg = ibase_errmsg();
+        }
+        // memo for the interbase php module hackers: we need something similar
+        // to mysql_errno() to retrieve error codes instead of this ugly hack
+        if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $native_errmsg, $m)) {
+            $native_errno = (int)$m[2];
+        } else {
+            $native_errno = null;
+        }
+        // try to map the native error to the DB one
+        if ($db_errno === null) {
+            if ($native_errno) {
+                // try to interpret Interbase error code (that's why we need ibase_errno()
+                // in the interbase module to return the real error code)
+                switch ($native_errno) {
+                    case -204:
+                        if (is_int(strpos($m[3], 'Table unknown'))) {
+                            $db_errno = DB_ERROR_NOSUCHTABLE;
+                        }
+                        break;
+                    default:
+                        $db_errno = $this->errorCode($native_errno);
+                }
+            } else {
+                $error_regexps = array(
+                    '/[tT]able not found/' => DB_ERROR_NOSUCHTABLE,
+                    '/[tT]able .* already exists/' => DB_ERROR_ALREADY_EXISTS,
+                    '/violation of [\w ]+ constraint/' => DB_ERROR_CONSTRAINT,
+                    '/conversion error from string/' => DB_ERROR_INVALID_NUMBER,
+                    '/no permission for/' => DB_ERROR_ACCESS_VIOLATION,
+                    '/arithmetic exception, numeric overflow, or string truncation/' => DB_ERROR_DIVZERO
+                );
+                foreach ($error_regexps as $regexp => $code) {
+                    if (preg_match($regexp, $native_errmsg)) {
+                        $db_errno = $code;
+                        $native_errno = null;
+                        break;
+                    }
+                }
+            }
+        }
+        $tmp =& $this->raiseError($db_errno, null, null, null, $native_errmsg);
+        return $tmp;
+    }
+
+    // }}}
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/ifx.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/ifx.php
new file mode 100755 (executable)
index 0000000..5ce1ffa
--- /dev/null
@@ -0,0 +1,556 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Tomas V.V.Cox <cox@idecnet.com>                              |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+
+// Legend:
+// For more info on Informix errors see:
+// http://www.informix.com/answers/english/ierrors.htm
+//
+// TODO:
+//  - set needed env Informix vars on connect
+//  - implement native prepare/execute
+
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's Informix
+ * extension.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Tomas V.V.Cox <cox@idecnet.com>
+ */
+class DB_ifx extends DB_common
+{
+    // {{{ properties
+
+    var $connection;
+    var $affected = 0;
+    var $dsn = array();
+    var $transaction_opcount = 0;
+    var $autocommit = true;
+    var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
+
+    // }}}
+    // {{{ constructor
+
+    function DB_ifx()
+    {
+        $this->phptype = 'ifx';
+        $this->dbsyntax = 'ifx';
+        $this->features = array(
+            'prepare' => false,
+            'pconnect' => true,
+            'transactions' => true,
+            'limit' => 'emulate'
+        );
+        $this->errorcode_map = array(
+            '-201'    => DB_ERROR_SYNTAX,
+            '-206'    => DB_ERROR_NOSUCHTABLE,
+            '-217'    => DB_ERROR_NOSUCHFIELD,
+            '-329'    => DB_ERROR_NODBSELECTED,
+            '-1204'   => DB_ERROR_INVALID_DATE,
+            '-1205'   => DB_ERROR_INVALID_DATE,
+            '-1206'   => DB_ERROR_INVALID_DATE,
+            '-1209'   => DB_ERROR_INVALID_DATE,
+            '-1210'   => DB_ERROR_INVALID_DATE,
+            '-1212'   => DB_ERROR_INVALID_DATE
+       );
+    }
+
+    // }}}
+    // {{{ connect()
+
+    /**
+     * Connect to a database and log in as the specified user.
+     *
+     * @param $dsn the data source name (see DB::parseDSN for syntax)
+     * @param $persistent (optional) whether the connection should
+     *        be persistent
+     *
+     * @return int DB_OK on success, a DB error code on failure
+     */
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('informix') &&
+            !DB::assertExtension('Informix'))
+        {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+        $this->dsn = $dsninfo;
+        $dbhost = $dsninfo['hostspec'] ? '@' . $dsninfo['hostspec'] : '';
+        $dbname = $dsninfo['database'] ? $dsninfo['database'] . $dbhost : '';
+        $user = $dsninfo['username'] ? $dsninfo['username'] : '';
+        $pw = $dsninfo['password'] ? $dsninfo['password'] : '';
+
+        $connect_function = $persistent ? 'ifx_pconnect' : 'ifx_connect';
+
+        $this->connection = @$connect_function($dbname, $user, $pw);
+        if (!is_resource($this->connection)) {
+            return $this->ifxraiseError(DB_ERROR_CONNECT_FAILED);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ disconnect()
+
+    /**
+     * Log out and disconnect from the database.
+     *
+     * @return bool TRUE on success, FALSE if not connected.
+     */
+    function disconnect()
+    {
+        $ret = @ifx_close($this->connection);
+        $this->connection = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ simpleQuery()
+
+    /**
+     * Send a query to Informix and return the results as a
+     * Informix resource identifier.
+     *
+     * @param $query the SQL query
+     *
+     * @return int returns a valid Informix result for successful SELECT
+     * queries, DB_OK for other successful queries.  A DB error code
+     * is returned on failure.
+     */
+    function simpleQuery($query)
+    {
+        $ismanip = DB::isManip($query);
+        $this->last_query = $query;
+        if (preg_match('/(SELECT)/i', $query)) {    //TESTME: Use !DB::isManip()?
+            // the scroll is needed for fetching absolute row numbers
+            // in a select query result
+            $result = @ifx_query($query, $this->connection, IFX_SCROLL);
+        } else {
+            if (!$this->autocommit && $ismanip) {
+                if ($this->transaction_opcount == 0) {
+                    $result = @ifx_query('BEGIN WORK', $this->connection);
+                    if (!$result) {
+                        return $this->ifxraiseError();
+                    }
+                }
+                $this->transaction_opcount++;
+            }
+            $result = @ifx_query($query, $this->connection);
+        }
+        if (!$result) {
+            return $this->ifxraiseError();
+        }
+        $this->affected = ifx_affected_rows($result);
+        // Determine which queries should return data, and which
+        // should return an error code only.
+        if (preg_match('/(SELECT)/i', $query)) {
+            return $result;
+        }
+        // XXX Testme: free results inside a transaction
+        // may cause to stop it and commit the work?
+
+        // Result has to be freed even with a insert or update
+        ifx_free_result($result);
+
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ nextResult()
+
+    /**
+     * Move the internal ifx result pointer to the next available result
+     *
+     * @param a valid fbsql result resource
+     *
+     * @access public
+     *
+     * @return true if a result is available otherwise return false
+     */
+    function nextResult($result)
+    {
+        return false;
+    }
+
+    // }}}
+    // {{{ affectedRows()
+
+    /**
+     * Gets the number of rows affected by the last query.
+     * if the last query was a select, returns an _estimate_ value.
+     *
+     * @return number of rows affected by the last query
+     */
+    function affectedRows()
+    {
+        return $this->affected;
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row and insert the data into an existing array.
+     *
+     * Formating of the array and the data therein are configurable.
+     * See DB_result::fetchInto() for more information.
+     *
+     * @param resource $result    query result identifier
+     * @param array    $arr       (reference) array where data from the row
+     *                            should be placed
+     * @param int      $fetchmode how the resulting array should be indexed
+     * @param int      $rownum    the row number to fetch
+     *
+     * @return mixed DB_OK on success, NULL when end of result set is
+     *               reached or on failure
+     *
+     * @see DB_result::fetchInto()
+     * @access private
+     */
+    function fetchInto($result, &$arr, $fetchmode, $rownum=null)
+    {
+        if (($rownum !== null) && ($rownum < 0)) {
+            return null;
+        }
+        if ($rownum === null) {
+            /*
+             * Even though fetch_row() should return the next row  if
+             * $rownum is null, it doesn't in all cases.  Bug 598.
+             */
+            $rownum = 'NEXT';
+        }
+        if (!$arr = @ifx_fetch_row($result, $rownum)) {
+            return null;
+        }
+        if ($fetchmode !== DB_FETCHMODE_ASSOC) {
+            $i=0;
+            $order = array();
+            foreach ($arr as $val) {
+                $order[$i++] = $val;
+            }
+            $arr = $order;
+        } elseif ($fetchmode == DB_FETCHMODE_ASSOC &&
+                  $this->options['portability'] & DB_PORTABILITY_LOWERCASE)
+        {
+            $arr = array_change_key_case($arr, CASE_LOWER);
+        }
+        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
+            $this->_rtrimArrayValues($arr);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    function numRows($result)
+    {
+        return $this->raiseError(DB_ERROR_NOT_CAPABLE);
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    /**
+     * Get the number of columns in a result set.
+     *
+     * @param $result Informix result identifier
+     *
+     * @return int the number of columns per row in $result
+     */
+    function numCols($result)
+    {
+        if (!$cols = @ifx_num_fields($result)) {
+            return $this->ifxraiseError();
+        }
+        return $cols;
+    }
+
+    // }}}
+    // {{{ freeResult()
+
+    /**
+     * Free the internal resources associated with $result.
+     *
+     * @param $result Informix result identifier
+     *
+     * @return bool TRUE on success, FALSE if $result is invalid
+     */
+    function freeResult($result)
+    {
+        return @ifx_free_result($result);
+    }
+
+    // }}}
+    // {{{ autoCommit()
+
+    /**
+     * Enable/disable automatic commits
+     */
+    function autoCommit($onoff = true)
+    {
+        // XXX if $this->transaction_opcount > 0, we should probably
+        // issue a warning here.
+        $this->autocommit = $onoff ? true : false;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ commit()
+
+    /**
+     * Commit the current transaction.
+     */
+    function commit()
+    {
+        if ($this->transaction_opcount > 0) {
+            $result = @ifx_query('COMMIT WORK', $this->connection);
+            $this->transaction_opcount = 0;
+            if (!$result) {
+                return $this->ifxRaiseError();
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ rollback()
+
+    /**
+     * Roll back (undo) the current transaction.
+     */
+    function rollback()
+    {
+        if ($this->transaction_opcount > 0) {
+            $result = @ifx_query('ROLLBACK WORK', $this->connection);
+            $this->transaction_opcount = 0;
+            if (!$result) {
+                return $this->ifxRaiseError();
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ ifxraiseError()
+
+    /**
+     * Gather information about an error, then use that info to create a
+     * DB error object and finally return that object.
+     *
+     * @param  integer  $errno  PEAR error number (usually a DB constant) if
+     *                          manually raising an error
+     * @return object  DB error object
+     * @see errorNative()
+     * @see errorCode()
+     * @see DB_common::raiseError()
+     */
+    function ifxraiseError($errno = null)
+    {
+        if ($errno === null) {
+            $errno = $this->errorCode(ifx_error());
+        }
+
+        return $this->raiseError($errno, null, null, null,
+                            $this->errorNative());
+    }
+
+    // }}}
+    // {{{ errorCode()
+
+    /**
+     * Map native error codes to DB's portable ones.
+     *
+     * Requires that the DB implementation's constructor fills
+     * in the <var>$errorcode_map</var> property.
+     *
+     * @param  string  $nativecode  error code returned by the database
+     * @return int a portable DB error code, or DB_ERROR if this DB
+     * implementation has no mapping for the given error code.
+     */
+    function errorCode($nativecode)
+    {
+        if (ereg('SQLCODE=(.*)]', $nativecode, $match)) {
+            $code = $match[1];
+            if (isset($this->errorcode_map[$code])) {
+                return $this->errorcode_map[$code];
+            }
+        }
+        return DB_ERROR;
+    }
+
+    // }}}
+    // {{{ errorNative()
+
+    /**
+     * Get the native error message of the last error (if any) that
+     * occured on the current connection.
+     *
+     * @return int native Informix error code
+     */
+    function errorNative()
+    {
+        return ifx_error() . ' ' . ifx_errormsg();
+    }
+
+    // }}}
+    // {{{ getSpecialQuery()
+
+    /**
+     * Returns the query needed to get some backend info
+     * @param string $type What kind of info you want to retrieve
+     * @return string The SQL query string
+     */
+    function getSpecialQuery($type)
+    {
+        switch ($type) {
+            case 'tables':
+                return 'select tabname from systables where tabid >= 100';
+            default:
+                return null;
+        }
+    }
+
+    // }}}
+    // {{{ tableInfo()
+
+    /**
+     * Returns information about a table or a result set.
+     *
+     * NOTE: only supports 'table' if <var>$result</var> is a table name.
+     *
+     * If analyzing a query result and the result has duplicate field names,
+     * an error will be raised saying
+     * <samp>can't distinguish duplicate field names</samp>.
+     *
+     * @param object|string  $result  DB_result object from a query or a
+     *                                string containing the name of a table 
+     * @param int            $mode    a valid tableInfo mode
+     * @return array  an associative array with the information requested
+     *                or an error object if something is wrong
+     * @access public
+     * @internal
+     * @since 1.6.0
+     * @see DB_common::tableInfo()
+     */
+    function tableInfo($result, $mode = null)
+    {
+        if (isset($result->result)) {
+            /*
+             * Probably received a result object.
+             * Extract the result resource identifier.
+             */
+            $id = $result->result;
+            $got_string = false;
+        } elseif (is_string($result)) {
+            /*
+             * Probably received a table name.
+             * Create a result resource identifier.
+             */
+            $id = @ifx_query("SELECT * FROM $result WHERE 1=0",
+                             $this->connection);
+            $got_string = true;
+        } else {
+            /*
+             * Probably received a result resource identifier.
+             * Copy it.
+             */
+            $id = $result;
+            $got_string = false;
+        }
+
+        if (!is_resource($id)) {
+            return $this->ifxRaiseError(DB_ERROR_NEED_MORE_DATA);
+        }
+
+        $flds = @ifx_fieldproperties($id);
+        $count = @ifx_num_fields($id);
+
+        if (count($flds) != $count) {
+            return $this->raiseError("can't distinguish duplicate field names");
+        }
+
+        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
+            $case_func = 'strtolower';
+        } else {
+            $case_func = 'strval';
+        }
+        
+        $i = 0;
+        // made this IF due to performance (one if is faster than $count if's)
+        if (!$mode) {
+            foreach ($flds as $key => $value) {
+                $props = explode(';', $value);
+
+                $res[$i]['table'] = $got_string ? $case_func($result) : '';
+                $res[$i]['name']  = $case_func($key);
+                $res[$i]['type']  = $props[0];
+                $res[$i]['len']   = $props[1];
+                $res[$i]['flags'] = $props[4] == 'N' ? 'not_null' : '';
+                $i++;
+            }
+
+        } else { // full
+            $res['num_fields'] = $count;
+
+            foreach ($flds as $key => $value) {
+                $props = explode(';', $value);
+
+                $res[$i]['table'] = $got_string ? $case_func($result) : '';
+                $res[$i]['name']  = $case_func($key);
+                $res[$i]['type']  = $props[0];
+                $res[$i]['len']   = $props[1];
+                $res[$i]['flags'] = $props[4] == 'N' ? 'not_null' : '';
+
+                if ($mode & DB_TABLEINFO_ORDER) {
+                    $res['order'][$res[$i]['name']] = $i;
+                }
+                if ($mode & DB_TABLEINFO_ORDERTABLE) {
+                    $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
+                }
+                $i++;
+            }
+        }
+
+        // free the result only if we were called on a table
+        if ($got_string) {
+            @ifx_free_result($id);
+        }
+        return $res;
+    }
+
+    // }}}
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/msql.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/msql.php
new file mode 100755 (executable)
index 0000000..35a4ad4
--- /dev/null
@@ -0,0 +1,239 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Sterling Hughes <sterling@php.net>                           |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's Mini-SQL
+ * extension.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Sterling Hughes <sterling@php.net>
+ */
+class DB_msql extends DB_common
+{
+    // {{{ properties
+
+    var $connection;
+    var $phptype, $dbsyntax;
+    var $prepare_tokens = array();
+    var $prepare_types = array();
+
+    // }}}
+    // {{{ constructor
+
+    function DB_msql()
+    {
+        $this->DB_common();
+        $this->phptype = 'msql';
+        $this->dbsyntax = 'msql';
+        $this->features = array(
+            'prepare' => false,
+            'pconnect' => true,
+            'transactions' => false,
+            'limit' => 'emulate'
+        );
+    }
+
+    // }}}
+    // {{{ connect()
+
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('msql')) {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+
+        $this->dsn = $dsninfo;
+        $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
+
+        $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
+
+        if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
+            $conn = $connect_function($dbhost, $dsninfo['username'],
+                                      $dsninfo['password']);
+        } elseif ($dbhost && $dsninfo['username']) {
+            $conn = $connect_function($dbhost, $dsninfo['username']);
+        } else {
+            $conn = $connect_function($dbhost);
+        }
+        if (!$conn) {
+            $this->raiseError(DB_ERROR_CONNECT_FAILED);
+        }
+        if (!@msql_select_db($dsninfo['database'], $conn)){
+            return $this->raiseError(DB_ERROR_NODBSELECTED);
+        }
+        $this->connection = $conn;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ disconnect()
+
+    function disconnect()
+    {
+        $ret = @msql_close($this->connection);
+        $this->connection = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ simpleQuery()
+
+    function simpleQuery($query)
+    {
+        $this->last_query = $query;
+        $query = $this->modifyQuery($query);
+        $result = @msql_query($query, $this->connection);
+        if (!$result) {
+            return $this->raiseError();
+        }
+        // Determine which queries that should return data, and which
+        // should return an error code only.
+        return DB::isManip($query) ? DB_OK : $result;
+    }
+
+
+    // }}}
+    // {{{ nextResult()
+
+    /**
+     * Move the internal msql result pointer to the next available result
+     *
+     * @param a valid fbsql result resource
+     *
+     * @access public
+     *
+     * @return true if a result is available otherwise return false
+     */
+    function nextResult($result)
+    {
+        return false;
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row and insert the data into an existing array.
+     *
+     * Formating of the array and the data therein are configurable.
+     * See DB_result::fetchInto() for more information.
+     *
+     * @param resource $result    query result identifier
+     * @param array    $arr       (reference) array where data from the row
+     *                            should be placed
+     * @param int      $fetchmode how the resulting array should be indexed
+     * @param int      $rownum    the row number to fetch
+     *
+     * @return mixed DB_OK on success, NULL when end of result set is
+     *               reached or on failure
+     *
+     * @see DB_result::fetchInto()
+     * @access private
+     */
+    function fetchInto($result, &$arr, $fetchmode, $rownum=null)
+    {
+        if ($rownum !== null) {
+            if (!@msql_data_seek($result, $rownum)) {
+                return null;
+            }
+        }
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            $arr = @msql_fetch_array($result, MSQL_ASSOC);
+            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
+                $arr = array_change_key_case($arr, CASE_LOWER);
+            }
+        } else {
+            $arr = @msql_fetch_row($result);
+        }
+        if (!$arr) {
+            if ($error = msql_error()) {
+                return $this->raiseError($error);
+            } else {
+                return null;
+            }
+        }
+        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
+            $this->_rtrimArrayValues($arr);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ freeResult()
+
+    function freeResult($result)
+    {
+        return @msql_free_result($result);
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    function numCols($result)
+    {
+        $cols = @msql_num_fields($result);
+        if (!$cols) {
+            return $this->raiseError();
+        }
+        return $cols;
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    function numRows($result)
+    {
+        $rows = @msql_num_rows($result);
+        if (!$rows) {
+            return $this->raiseError();
+        }
+        return $rows;
+    }
+
+    // }}}
+    // {{{ affected()
+
+    /**
+     * Gets the number of rows affected by a query.
+     *
+     * @return number of rows affected by the last query
+     */
+    function affectedRows()
+    {
+        return @msql_affected_rows($this->connection);
+    }
+
+    // }}}
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/mssql.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/mssql.php
new file mode 100755 (executable)
index 0000000..c72bd09
--- /dev/null
@@ -0,0 +1,734 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Sterling Hughes <sterling@php.net>                           |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's Microsoft SQL Server
+ * extension.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Sterling Hughes <sterling@php.net>
+ */
+class DB_mssql extends DB_common
+{
+    // {{{ properties
+
+    var $connection;
+    var $phptype, $dbsyntax;
+    var $prepare_tokens = array();
+    var $prepare_types = array();
+    var $transaction_opcount = 0;
+    var $autocommit = true;
+    var $_db = null;
+
+    // }}}
+    // {{{ constructor
+
+    function DB_mssql()
+    {
+        $this->DB_common();
+        $this->phptype = 'mssql';
+        $this->dbsyntax = 'mssql';
+        $this->features = array(
+            'prepare' => false,
+            'pconnect' => true,
+            'transactions' => true,
+            'limit' => 'emulate'
+        );
+        // XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX
+        $this->errorcode_map = array(
+            170   => DB_ERROR_SYNTAX,
+            207   => DB_ERROR_NOSUCHFIELD,
+            208   => DB_ERROR_NOSUCHTABLE,
+            245   => DB_ERROR_INVALID_NUMBER,
+            547   => DB_ERROR_CONSTRAINT,
+            2627  => DB_ERROR_CONSTRAINT,
+            2714  => DB_ERROR_ALREADY_EXISTS,
+            3701  => DB_ERROR_NOSUCHTABLE,
+            8134  => DB_ERROR_DIVZERO,
+        );
+    }
+
+    // }}}
+    // {{{ connect()
+
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('mssql') && !DB::assertExtension('sybase')
+            && !DB::assertExtension('sybase_ct'))
+        {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+        $this->dsn = $dsninfo;
+        $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
+        $dbhost .= $dsninfo['port'] ? ':' . $dsninfo['port'] : '';
+
+        $connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';
+
+        if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
+            $conn = @$connect_function($dbhost, $dsninfo['username'],
+                                       $dsninfo['password']);
+        } elseif ($dbhost && $dsninfo['username']) {
+            $conn = @$connect_function($dbhost, $dsninfo['username']);
+        } else {
+            $conn = @$connect_function($dbhost);
+        }
+        if (!$conn) {
+            return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
+                                         null, mssql_get_last_message());
+        }
+        if ($dsninfo['database']) {
+            if (!@mssql_select_db($dsninfo['database'], $conn)) {
+                return $this->raiseError(DB_ERROR_NODBSELECTED, null, null,
+                                         null, mssql_get_last_message());
+            }
+            $this->_db = $dsninfo['database'];
+        }
+        $this->connection = $conn;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ disconnect()
+
+    function disconnect()
+    {
+        $ret = @mssql_close($this->connection);
+        $this->connection = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ simpleQuery()
+
+    function simpleQuery($query)
+    {
+        $ismanip = DB::isManip($query);
+        $this->last_query = $query;
+        if (!@mssql_select_db($this->_db, $this->connection)) {
+            return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
+        }
+        $query = $this->modifyQuery($query);
+        if (!$this->autocommit && $ismanip) {
+            if ($this->transaction_opcount == 0) {
+                $result = @mssql_query('BEGIN TRAN', $this->connection);
+                if (!$result) {
+                    return $this->mssqlRaiseError();
+                }
+            }
+            $this->transaction_opcount++;
+        }
+        $result = @mssql_query($query, $this->connection);
+        if (!$result) {
+            return $this->mssqlRaiseError();
+        }
+        // Determine which queries that should return data, and which
+        // should return an error code only.
+        return $ismanip ? DB_OK : $result;
+    }
+
+    // }}}
+    // {{{ nextResult()
+
+    /**
+     * Move the internal mssql result pointer to the next available result
+     *
+     * @param a valid fbsql result resource
+     *
+     * @access public
+     *
+     * @return true if a result is available otherwise return false
+     */
+    function nextResult($result)
+    {
+        return mssql_next_result($result);
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row and insert the data into an existing array.
+     *
+     * Formating of the array and the data therein are configurable.
+     * See DB_result::fetchInto() for more information.
+     *
+     * @param resource $result    query result identifier
+     * @param array    $arr       (reference) array where data from the row
+     *                            should be placed
+     * @param int      $fetchmode how the resulting array should be indexed
+     * @param int      $rownum    the row number to fetch
+     *
+     * @return mixed DB_OK on success, NULL when end of result set is
+     *               reached or on failure
+     *
+     * @see DB_result::fetchInto()
+     * @access private
+     */
+    function fetchInto($result, &$arr, $fetchmode, $rownum=null)
+    {
+        if ($rownum !== null) {
+            if (!@mssql_data_seek($result, $rownum)) {
+                return null;
+            }
+        }
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            $arr = @mssql_fetch_array($result, MSSQL_ASSOC);
+            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
+                $arr = array_change_key_case($arr, CASE_LOWER);
+            }
+        } else {
+            $arr = @mssql_fetch_row($result);
+        }
+        if (!$arr) {
+            /* This throws informative error messages,
+               don't use it for now
+            if ($msg = mssql_get_last_message()) {
+                return $this->raiseError($msg);
+            }
+            */
+            return null;
+        }
+        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
+            $this->_rtrimArrayValues($arr);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ freeResult()
+
+    function freeResult($result)
+    {
+        return @mssql_free_result($result);
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    function numCols($result)
+    {
+        $cols = @mssql_num_fields($result);
+        if (!$cols) {
+            return $this->mssqlRaiseError();
+        }
+        return $cols;
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    function numRows($result)
+    {
+        $rows = @mssql_num_rows($result);
+        if ($rows === false) {
+            return $this->mssqlRaiseError();
+        }
+        return $rows;
+    }
+
+    // }}}
+    // {{{ autoCommit()
+
+    /**
+     * Enable/disable automatic commits
+     */
+    function autoCommit($onoff = false)
+    {
+        // XXX if $this->transaction_opcount > 0, we should probably
+        // issue a warning here.
+        $this->autocommit = $onoff ? true : false;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ commit()
+
+    /**
+     * Commit the current transaction.
+     */
+    function commit()
+    {
+        if ($this->transaction_opcount > 0) {
+            if (!@mssql_select_db($this->_db, $this->connection)) {
+                return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
+            }
+            $result = @mssql_query('COMMIT TRAN', $this->connection);
+            $this->transaction_opcount = 0;
+            if (!$result) {
+                return $this->mssqlRaiseError();
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ rollback()
+
+    /**
+     * Roll back (undo) the current transaction.
+     */
+    function rollback()
+    {
+        if ($this->transaction_opcount > 0) {
+            if (!@mssql_select_db($this->_db, $this->connection)) {
+                return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
+            }
+            $result = @mssql_query('ROLLBACK TRAN', $this->connection);
+            $this->transaction_opcount = 0;
+            if (!$result) {
+                return $this->mssqlRaiseError();
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ affectedRows()
+
+    /**
+     * Gets the number of rows affected by the last query.
+     * if the last query was a select, returns 0.
+     *
+     * @return number of rows affected by the last query or DB_ERROR
+     */
+    function affectedRows()
+    {
+        if (DB::isManip($this->last_query)) {
+            $res = @mssql_query('select @@rowcount', $this->connection);
+            if (!$res) {
+                return $this->mssqlRaiseError();
+            }
+            $ar = @mssql_fetch_row($res);
+            if (!$ar) {
+                $result = 0;
+            } else {
+                @mssql_free_result($res);
+                $result = $ar[0];
+            }
+        } else {
+            $result = 0;
+        }
+        return $result;
+    }
+
+    // }}}
+    // {{{ nextId()
+
+    /**
+     * Returns the next free id in a sequence
+     *
+     * @param string  $seq_name  name of the sequence
+     * @param boolean $ondemand  when true, the seqence is automatically
+     *                           created if it does not exist
+     *
+     * @return int  the next id number in the sequence.  DB_Error if problem.
+     *
+     * @internal
+     * @see DB_common::nextID()
+     * @access public
+     */
+    function nextId($seq_name, $ondemand = true)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        if (!@mssql_select_db($this->_db, $this->connection)) {
+            return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
+        }
+        $repeat = 0;
+        do {
+            $this->pushErrorHandling(PEAR_ERROR_RETURN);
+            $result = $this->query("INSERT INTO $seqname (vapor) VALUES (0)");
+            $this->popErrorHandling();
+            if ($ondemand && DB::isError($result) &&
+                ($result->getCode() == DB_ERROR || $result->getCode() == DB_ERROR_NOSUCHTABLE))
+            {
+                $repeat = 1;
+                $result = $this->createSequence($seq_name);
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+            } elseif (!DB::isError($result)) {
+                $result =& $this->query("SELECT @@IDENTITY FROM $seqname");
+                $repeat = 0;
+            } else {
+                $repeat = false;
+            }
+        } while ($repeat);
+        if (DB::isError($result)) {
+            return $this->raiseError($result);
+        }
+        $result = $result->fetchRow(DB_FETCHMODE_ORDERED);
+        return $result[0];
+    }
+
+    /**
+     * Creates a new sequence
+     *
+     * @param string $seq_name  name of the new sequence
+     *
+     * @return int  DB_OK on success.  A DB_Error object is returned if
+     *              problems arise.
+     *
+     * @internal
+     * @see DB_common::createSequence()
+     * @access public
+     */
+    function createSequence($seq_name)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        return $this->query("CREATE TABLE $seqname ".
+                            '([id] [int] IDENTITY (1, 1) NOT NULL ,' .
+                            '[vapor] [int] NULL)');
+    }
+
+    // }}}
+    // {{{ dropSequence()
+
+    /**
+     * Deletes a sequence
+     *
+     * @param string $seq_name  name of the sequence to be deleted
+     *
+     * @return int  DB_OK on success.  DB_Error if problems.
+     *
+     * @internal
+     * @see DB_common::dropSequence()
+     * @access public
+     */
+    function dropSequence($seq_name)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        return $this->query("DROP TABLE $seqname");
+    }
+
+    // }}}
+    // {{{ errorNative()
+
+    /**
+     * Determine MS SQL Server error code by querying @@ERROR.
+     *
+     * @return mixed  mssql's native error code or DB_ERROR if unknown.
+     */
+    function errorNative()
+    {
+        $res = mssql_query('select @@ERROR as ErrorCode', $this->connection);
+        if (!$res) {
+            return DB_ERROR;
+        }
+        $row = mssql_fetch_row($res);
+        return $row[0];
+    }
+
+    // }}}
+    // {{{ errorCode()
+
+    /**
+     * Determine PEAR::DB error code from mssql's native codes.
+     *
+     * If <var>$nativecode</var> isn't known yet, it will be looked up.
+     *
+     * @param  mixed  $nativecode  mssql error code, if known
+     * @return integer  an error number from a DB error constant
+     * @see errorNative()
+     */
+    function errorCode($nativecode = null)
+    {
+        if (!$nativecode) {
+            $nativecode = $this->errorNative();
+        }
+        if (isset($this->errorcode_map[$nativecode])) {
+            return $this->errorcode_map[$nativecode];
+        } else {
+            return DB_ERROR;
+        }
+    }
+
+    // }}}
+    // {{{ mssqlRaiseError()
+
+    /**
+     * Gather information about an error, then use that info to create a
+     * DB error object and finally return that object.
+     *
+     * @param  integer  $code  PEAR error number (usually a DB constant) if
+     *                         manually raising an error
+     * @return object  DB error object
+     * @see errorCode()
+     * @see errorNative()
+     * @see DB_common::raiseError()
+     */
+    function mssqlRaiseError($code = null)
+    {
+        $message = mssql_get_last_message();
+        if (!$code) {
+            $code = $this->errorNative();
+        }
+        return $this->raiseError($this->errorCode($code), null, null, null,
+                                 "$code - $message");
+    }
+
+    // }}}
+    // {{{ tableInfo()
+
+    /**
+     * Returns information about a table or a result set.
+     *
+     * NOTE: only supports 'table' and 'flags' if <var>$result</var>
+     * is a table name.
+     *
+     * @param object|string  $result  DB_result object from a query or a
+     *                                string containing the name of a table
+     * @param int            $mode    a valid tableInfo mode
+     * @return array  an associative array with the information requested
+     *                or an error object if something is wrong
+     * @access public
+     * @internal
+     * @see DB_common::tableInfo()
+     */
+    function tableInfo($result, $mode = null)
+    {
+        if (isset($result->result)) {
+            /*
+             * Probably received a result object.
+             * Extract the result resource identifier.
+             */
+            $id = $result->result;
+            $got_string = false;
+        } elseif (is_string($result)) {
+            /*
+             * Probably received a table name.
+             * Create a result resource identifier.
+             */
+            if (!@mssql_select_db($this->_db, $this->connection)) {
+                return $this->mssqlRaiseError(DB_ERROR_NODBSELECTED);
+            }
+            $id = @mssql_query("SELECT * FROM $result WHERE 1=0",
+                               $this->connection);
+            $got_string = true;
+        } else {
+            /*
+             * Probably received a result resource identifier.
+             * Copy it.
+             * Depricated.  Here for compatibility only.
+             */
+            $id = $result;
+            $got_string = false;
+        }
+
+        if (!is_resource($id)) {
+            return $this->mssqlRaiseError(DB_ERROR_NEED_MORE_DATA);
+        }
+
+        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
+            $case_func = 'strtolower';
+        } else {
+            $case_func = 'strval';
+        }
+
+        $count = @mssql_num_fields($id);
+
+        // made this IF due to performance (one if is faster than $count if's)
+        if (!$mode) {
+            for ($i=0; $i<$count; $i++) {
+                $res[$i]['table'] = $got_string ? $case_func($result) : '';
+                $res[$i]['name']  = $case_func(@mssql_field_name($id, $i));
+                $res[$i]['type']  = @mssql_field_type($id, $i);
+                $res[$i]['len']   = @mssql_field_length($id, $i);
+                // We only support flags for tables
+                $res[$i]['flags'] = $got_string ? $this->_mssql_field_flags($result, $res[$i]['name']) : '';
+            }
+
+        } else { // full
+            $res['num_fields']= $count;
+
+            for ($i=0; $i<$count; $i++) {
+                $res[$i]['table'] = $got_string ? $case_func($result) : '';
+                $res[$i]['name']  = $case_func(@mssql_field_name($id, $i));
+                $res[$i]['type']  = @mssql_field_type($id, $i);
+                $res[$i]['len']   = @mssql_field_length($id, $i);
+                // We only support flags for tables
+                $res[$i]['flags'] = $got_string ? $this->_mssql_field_flags($result, $res[$i]['name']) : '';
+
+                if ($mode & DB_TABLEINFO_ORDER) {
+                    $res['order'][$res[$i]['name']] = $i;
+                }
+                if ($mode & DB_TABLEINFO_ORDERTABLE) {
+                    $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
+                }
+            }
+        }
+
+        // free the result only if we were called on a table
+        if ($got_string) {
+            @mssql_free_result($id);
+        }
+        return $res;
+    }
+
+    // }}}
+    // {{{ getSpecialQuery()
+
+    /**
+     * Returns the query needed to get some backend info
+     * @param string $type What kind of info you want to retrieve
+     * @return string The SQL query string
+     */
+    function getSpecialQuery($type)
+    {
+        switch ($type) {
+            case 'tables':
+                return "select name from sysobjects where type = 'U' order by name";
+            case 'views':
+                return "select name from sysobjects where type = 'V'";
+            default:
+                return null;
+        }
+    }
+
+    // }}}
+    // {{{ _mssql_field_flags()
+
+    /**
+     * Get the flags for a field, currently supports "not_null", "primary_key",
+     * "auto_increment" (mssql identity), "timestamp" (mssql timestamp),
+     * "unique_key" (mssql unique index, unique check or primary_key) and
+     * "multiple_key" (multikey index)
+     *
+     * mssql timestamp is NOT similar to the mysql timestamp so this is maybe
+     * not useful at all - is the behaviour of mysql_field_flags that primary
+     * keys are alway unique? is the interpretation of multiple_key correct?
+     *
+     * @param string The table name
+     * @param string The field
+     * @author Joern Barthel <j_barthel@web.de>
+     * @access private
+     */
+    function _mssql_field_flags($table, $column)
+    {
+        static $tableName = null;
+        static $flags = array();
+
+        if ($table != $tableName) {
+
+            $flags = array();
+            $tableName = $table;
+
+            // get unique and primary keys
+            $res = $this->getAll("EXEC SP_HELPINDEX[$table]", DB_FETCHMODE_ASSOC);
+
+            foreach ($res as $val) {
+                $keys = explode(', ', $val['index_keys']);
+
+                if (sizeof($keys) > 1) {
+                    foreach ($keys as $key) {
+                        $this->_add_flag($flags[$key], 'multiple_key');
+                    }
+                }
+
+                if (strpos($val['index_description'], 'primary key')) {
+                    foreach ($keys as $key) {
+                        $this->_add_flag($flags[$key], 'primary_key');
+                    }
+                } elseif (strpos($val['index_description'], 'unique')) {
+                    foreach ($keys as $key) {
+                        $this->_add_flag($flags[$key], 'unique_key');
+                    }
+                }
+            }
+
+            // get auto_increment, not_null and timestamp
+            $res = $this->getAll("EXEC SP_COLUMNS[$table]", DB_FETCHMODE_ASSOC);
+
+            foreach ($res as $val) {
+                $val = array_change_key_case($val, CASE_LOWER);
+                if ($val['nullable'] == '0') {
+                    $this->_add_flag($flags[$val['column_name']], 'not_null');
+                }
+                if (strpos($val['type_name'], 'identity')) {
+                    $this->_add_flag($flags[$val['column_name']], 'auto_increment');
+                }
+                if (strpos($val['type_name'], 'timestamp')) {
+                    $this->_add_flag($flags[$val['column_name']], 'timestamp');
+                }
+            }
+        }
+
+        if (array_key_exists($column, $flags)) {
+            return(implode(' ', $flags[$column]));
+        }
+        return '';
+    }
+
+    // }}}
+    // {{{ _add_flag()
+
+    /**
+     * Adds a string to the flags array if the flag is not yet in there
+     * - if there is no flag present the array is created.
+     *
+     * @param reference  Reference to the flag-array
+     * @param value      The flag value
+     * @access private
+     * @author Joern Barthel <j_barthel@web.de>
+     */
+    function _add_flag (&$array, $value)
+    {
+        if (!is_array($array)) {
+            $array = array($value);
+        } elseif (!in_array($value, $array)) {
+            array_push($array, $value);
+        }
+    }
+
+    // }}}
+    // {{{ quoteIdentifier()
+
+    /**
+     * Quote a string so it can be safely used as a table / column name
+     *
+     * Quoting style depends on which database driver is being used.
+     *
+     * @param string $str  identifier name to be quoted
+     *
+     * @return string  quoted identifier string
+     *
+     * @since 1.6.0
+     * @access public
+     */
+    function quoteIdentifier($str)
+    {
+        return '[' . str_replace(']', ']]', $str) . ']';
+    }
+
+    // }}}
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/mysql.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/mysql.php
new file mode 100755 (executable)
index 0000000..006a690
--- /dev/null
@@ -0,0 +1,910 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Stig Bakken <ssb@php.net>                                    |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+
+// XXX legend:
+//
+// XXX ERRORMSG: The error message from the mysql function should
+//               be registered here.
+//
+// TODO/wishlist:
+// longReadlen
+// binmode
+
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's MySQL
+ * extension.
+ *
+ * This is for MySQL versions 4.0 and below.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Stig Bakken <ssb@php.net>
+ */
+class DB_mysql extends DB_common
+{
+    // {{{ properties
+
+    var $connection;
+    var $phptype, $dbsyntax;
+    var $prepare_tokens = array();
+    var $prepare_types = array();
+    var $num_rows = array();
+    var $transaction_opcount = 0;
+    var $autocommit = true;
+    var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
+    var $_db = false;
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * DB_mysql constructor.
+     *
+     * @access public
+     */
+    function DB_mysql()
+    {
+        $this->DB_common();
+        $this->phptype = 'mysql';
+        $this->dbsyntax = 'mysql';
+        $this->features = array(
+            'prepare' => false,
+            'pconnect' => true,
+            'transactions' => true,
+            'limit' => 'alter'
+        );
+        $this->errorcode_map = array(
+            1004 => DB_ERROR_CANNOT_CREATE,
+            1005 => DB_ERROR_CANNOT_CREATE,
+            1006 => DB_ERROR_CANNOT_CREATE,
+            1007 => DB_ERROR_ALREADY_EXISTS,
+            1008 => DB_ERROR_CANNOT_DROP,
+            1022 => DB_ERROR_ALREADY_EXISTS,
+            1046 => DB_ERROR_NODBSELECTED,
+            1050 => DB_ERROR_ALREADY_EXISTS,
+            1051 => DB_ERROR_NOSUCHTABLE,
+            1054 => DB_ERROR_NOSUCHFIELD,
+            1062 => DB_ERROR_ALREADY_EXISTS,
+            1064 => DB_ERROR_SYNTAX,
+            1100 => DB_ERROR_NOT_LOCKED,
+            1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
+            1146 => DB_ERROR_NOSUCHTABLE,
+            1048 => DB_ERROR_CONSTRAINT,
+            1216 => DB_ERROR_CONSTRAINT
+        );
+    }
+
+    // }}}
+
+    // {{{ connect()
+
+    /**
+     * Connect to a database and log in as the specified user.
+     *
+     * @param $dsn the data source name (see DB::parseDSN for syntax)
+     * @param $persistent (optional) whether the connection should
+     *        be persistent
+     * @access public
+     * @return int DB_OK on success, a DB error on failure
+     */
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('mysql')) {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+        $this->dsn = $dsninfo;
+        if ($dsninfo['protocol'] && $dsninfo['protocol'] == 'unix') {
+            $dbhost = ':' . $dsninfo['socket'];
+        } else {
+            $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
+            if ($dsninfo['port']) {
+                $dbhost .= ':' . $dsninfo['port'];
+            }
+        }
+        
+        $connect_function = $persistent ? 'mysql_pconnect' : 'mysql_connect';
+
+        if ($dbhost && $dsninfo['username'] && isset($dsninfo['password'])) {
+            $conn = @$connect_function($dbhost, $dsninfo['username'],
+                                       $dsninfo['password']);
+        } elseif ($dbhost && $dsninfo['username']) {
+            $conn = @$connect_function($dbhost, $dsninfo['username']);
+        } elseif ($dbhost) {
+            $conn = @$connect_function($dbhost);
+        } else {
+            $conn = false;
+        }
+        if (!$conn) {
+            if (($err = @mysql_error()) != '') {
+                return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
+                                         null, $err);
+            } elseif (empty($php_errormsg)) {
+                return $this->raiseError(DB_ERROR_CONNECT_FAILED);
+            } else {
+                return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
+                                         null, $php_errormsg);
+            }
+        }
+
+        if ($dsninfo['database']) {
+            if (!@mysql_select_db($dsninfo['database'], $conn)) {
+               switch(mysql_errno($conn)) {
+                        case 1049:
+                            return $this->raiseError(DB_ERROR_NOSUCHDB, null, null,
+                                                     null, mysql_error($conn));
+                        case 1044:
+                             return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null,
+                                                      null, mysql_error($conn));
+                        default:
+                            return $this->raiseError(DB_ERROR, null, null,
+                                                     null, mysql_error($conn));
+                    }
+            }
+            // fix to allow calls to different databases in the same script
+            $this->_db = $dsninfo['database'];
+        }
+
+        if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
+            $this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
+            $this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
+        }
+
+        $this->connection = $conn;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ disconnect()
+
+    /**
+     * Log out and disconnect from the database.
+     *
+     * @access public
+     *
+     * @return bool TRUE on success, FALSE if not connected.
+     */
+    function disconnect()
+    {
+        $ret = mysql_close($this->connection);
+        $this->connection = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ simpleQuery()
+
+    /**
+     * Send a query to MySQL and return the results as a MySQL resource
+     * identifier.
+     *
+     * @param the SQL query
+     *
+     * @access public
+     *
+     * @return mixed returns a valid MySQL result for successful SELECT
+     * queries, DB_OK for other successful queries.  A DB error is
+     * returned on failure.
+     */
+    function simpleQuery($query)
+    {
+        $ismanip = DB::isManip($query);
+        $this->last_query = $query;
+        $query = $this->modifyQuery($query);
+        if ($this->_db) {
+            if (!@mysql_select_db($this->_db, $this->connection)) {
+                return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+            }
+        }
+        if (!$this->autocommit && $ismanip) {
+            if ($this->transaction_opcount == 0) {
+                $result = @mysql_query('SET AUTOCOMMIT=0', $this->connection);
+                $result = @mysql_query('BEGIN', $this->connection);
+                if (!$result) {
+                    return $this->mysqlRaiseError();
+                }
+            }
+            $this->transaction_opcount++;
+        }
+        $result = @mysql_query($query, $this->connection);
+        if (!$result) {
+            return $this->mysqlRaiseError();
+        }
+        if (is_resource($result)) {
+            $numrows = $this->numrows($result);
+            if (is_object($numrows)) {
+                return $numrows;
+            }
+            $this->num_rows[(int)$result] = $numrows;
+            return $result;
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ nextResult()
+
+    /**
+     * Move the internal mysql result pointer to the next available result
+     *
+     * This method has not been implemented yet.
+     *
+     * @param a valid sql result resource
+     *
+     * @access public
+     *
+     * @return false
+     */
+    function nextResult($result)
+    {
+        return false;
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row and insert the data into an existing array.
+     *
+     * Formating of the array and the data therein are configurable.
+     * See DB_result::fetchInto() for more information.
+     *
+     * @param resource $result    query result identifier
+     * @param array    $arr       (reference) array where data from the row
+     *                            should be placed
+     * @param int      $fetchmode how the resulting array should be indexed
+     * @param int      $rownum    the row number to fetch
+     *
+     * @return mixed DB_OK on success, NULL when end of result set is
+     *               reached or on failure
+     *
+     * @see DB_result::fetchInto()
+     * @access private
+     */
+    function fetchInto($result, &$arr, $fetchmode, $rownum=null)
+    {
+        if ($rownum !== null) {
+            if (!@mysql_data_seek($result, $rownum)) {
+                return null;
+            }
+        }
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            $arr = @mysql_fetch_array($result, MYSQL_ASSOC);
+            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
+                $arr = array_change_key_case($arr, CASE_LOWER);
+            }
+        } else {
+            $arr = @mysql_fetch_row($result);
+        }
+        if (!$arr) {
+            // See: http://bugs.php.net/bug.php?id=22328
+            // for why we can't check errors on fetching
+            return null;
+            /*
+            $errno = @mysql_errno($this->connection);
+            if (!$errno) {
+                return NULL;
+            }
+            return $this->mysqlRaiseError($errno);
+            */
+        }
+        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
+            /*
+             * Even though this DBMS already trims output, we do this because
+             * a field might have intentional whitespace at the end that
+             * gets removed by DB_PORTABILITY_RTRIM under another driver.
+             */
+            $this->_rtrimArrayValues($arr);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ freeResult()
+
+    /**
+     * Free the internal resources associated with $result.
+     *
+     * @param $result MySQL result identifier
+     *
+     * @access public
+     *
+     * @return bool TRUE on success, FALSE if $result is invalid
+     */
+    function freeResult($result)
+    {
+        unset($this->num_rows[(int)$result]);
+        return @mysql_free_result($result);
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    /**
+     * Get the number of columns in a result set.
+     *
+     * @param $result MySQL result identifier
+     *
+     * @access public
+     *
+     * @return int the number of columns per row in $result
+     */
+    function numCols($result)
+    {
+        $cols = @mysql_num_fields($result);
+
+        if (!$cols) {
+            return $this->mysqlRaiseError();
+        }
+
+        return $cols;
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    /**
+     * Get the number of rows in a result set.
+     *
+     * @param $result MySQL result identifier
+     *
+     * @access public
+     *
+     * @return int the number of rows in $result
+     */
+    function numRows($result)
+    {
+        $rows = @mysql_num_rows($result);
+        if ($rows === null) {
+            return $this->mysqlRaiseError();
+        }
+        return $rows;
+    }
+
+    // }}}
+    // {{{ autoCommit()
+
+    /**
+     * Enable/disable automatic commits
+     */
+    function autoCommit($onoff = false)
+    {
+        // XXX if $this->transaction_opcount > 0, we should probably
+        // issue a warning here.
+        $this->autocommit = $onoff ? true : false;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ commit()
+
+    /**
+     * Commit the current transaction.
+     */
+    function commit()
+    {
+        if ($this->transaction_opcount > 0) {
+            if ($this->_db) {
+                if (!@mysql_select_db($this->_db, $this->connection)) {
+                    return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+                }
+            }
+            $result = @mysql_query('COMMIT', $this->connection);
+            $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
+            $this->transaction_opcount = 0;
+            if (!$result) {
+                return $this->mysqlRaiseError();
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ rollback()
+
+    /**
+     * Roll back (undo) the current transaction.
+     */
+    function rollback()
+    {
+        if ($this->transaction_opcount > 0) {
+            if ($this->_db) {
+                if (!@mysql_select_db($this->_db, $this->connection)) {
+                    return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+                }
+            }
+            $result = @mysql_query('ROLLBACK', $this->connection);
+            $result = @mysql_query('SET AUTOCOMMIT=1', $this->connection);
+            $this->transaction_opcount = 0;
+            if (!$result) {
+                return $this->mysqlRaiseError();
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ affectedRows()
+
+    /**
+     * Gets the number of rows affected by the data manipulation
+     * query.  For other queries, this function returns 0.
+     *
+     * @return number of rows affected by the last query
+     */
+    function affectedRows()
+    {
+        if (DB::isManip($this->last_query)) {
+            $result = @mysql_affected_rows($this->connection);
+        } else {
+            $result = 0;
+        }
+        return $result;
+     }
+
+    // }}}
+    // {{{ errorNative()
+
+    /**
+     * Get the native error code of the last error (if any) that
+     * occured on the current connection.
+     *
+     * @access public
+     *
+     * @return int native MySQL error code
+     */
+    function errorNative()
+    {
+        return mysql_errno($this->connection);
+    }
+
+    // }}}
+    // {{{ nextId()
+
+    /**
+     * Returns the next free id in a sequence
+     *
+     * @param string  $seq_name  name of the sequence
+     * @param boolean $ondemand  when true, the seqence is automatically
+     *                           created if it does not exist
+     *
+     * @return int  the next id number in the sequence.  DB_Error if problem.
+     *
+     * @internal
+     * @see DB_common::nextID()
+     * @access public
+     */
+    function nextId($seq_name, $ondemand = true)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        do {
+            $repeat = 0;
+            $this->pushErrorHandling(PEAR_ERROR_RETURN);
+            $result = $this->query("UPDATE ${seqname} ".
+                                   'SET id=LAST_INSERT_ID(id+1)');
+            $this->popErrorHandling();
+            if ($result == DB_OK) {
+                /** COMMON CASE **/
+                $id = mysql_insert_id($this->connection);
+                if ($id != 0) {
+                    return $id;
+                }
+                /** EMPTY SEQ TABLE **/
+                // Sequence table must be empty for some reason, so fill it and return 1
+                // Obtain a user-level lock
+                $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+                if ($result == 0) {
+                    // Failed to get the lock, bail with a DB_ERROR_NOT_LOCKED error
+                    return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
+                }
+
+                // add the default value
+                $result = $this->query("REPLACE INTO ${seqname} VALUES (0)");
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+
+                // Release the lock
+                $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+                // We know what the result will be, so no need to try again
+                return 1;
+
+            /** ONDEMAND TABLE CREATION **/
+            } elseif ($ondemand && DB::isError($result) &&
+                $result->getCode() == DB_ERROR_NOSUCHTABLE)
+            {
+                $result = $this->createSequence($seq_name);
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                } else {
+                    $repeat = 1;
+                }
+
+            /** BACKWARDS COMPAT **/
+            } elseif (DB::isError($result) &&
+                      $result->getCode() == DB_ERROR_ALREADY_EXISTS)
+            {
+                // see _BCsequence() comment
+                $result = $this->_BCsequence($seqname);
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+                $repeat = 1;
+            }
+        } while ($repeat);
+
+        return $this->raiseError($result);
+    }
+
+    // }}}
+    // {{{ createSequence()
+
+    /**
+     * Creates a new sequence
+     *
+     * @param string $seq_name  name of the new sequence
+     *
+     * @return int  DB_OK on success.  A DB_Error object is returned if
+     *              problems arise.
+     *
+     * @internal
+     * @see DB_common::createSequence()
+     * @access public
+     */
+    function createSequence($seq_name)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        $res = $this->query("CREATE TABLE ${seqname} ".
+                            '(id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'.
+                            ' PRIMARY KEY(id))');
+        if (DB::isError($res)) {
+            return $res;
+        }
+        // insert yields value 1, nextId call will generate ID 2
+        $res = $this->query("INSERT INTO ${seqname} VALUES(0)");
+        if (DB::isError($res)) {
+            return $res;
+        }
+        // so reset to zero
+        return $this->query("UPDATE ${seqname} SET id = 0;");
+    }
+
+    // }}}
+    // {{{ dropSequence()
+
+    /**
+     * Deletes a sequence
+     *
+     * @param string $seq_name  name of the sequence to be deleted
+     *
+     * @return int  DB_OK on success.  DB_Error if problems.
+     *
+     * @internal
+     * @see DB_common::dropSequence()
+     * @access public
+     */
+    function dropSequence($seq_name)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        return $this->query("DROP TABLE ${seqname}");
+    }
+
+    // }}}
+    // {{{ _BCsequence()
+
+    /**
+     * Backwards compatibility with old sequence emulation implementation
+     * (clean up the dupes)
+     *
+     * @param string $seqname The sequence name to clean up
+     * @return mixed DB_Error or true
+     */
+    function _BCsequence($seqname)
+    {
+        // Obtain a user-level lock... this will release any previous
+        // application locks, but unlike LOCK TABLES, it does not abort
+        // the current transaction and is much less frequently used.
+        $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
+        if (DB::isError($result)) {
+            return $result;
+        }
+        if ($result == 0) {
+            // Failed to get the lock, can't do the conversion, bail
+            // with a DB_ERROR_NOT_LOCKED error
+            return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
+        }
+
+        $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}");
+        if (DB::isError($highest_id)) {
+            return $highest_id;
+        }
+        // This should kill all rows except the highest
+        // We should probably do something if $highest_id isn't
+        // numeric, but I'm at a loss as how to handle that...
+        $result = $this->query("DELETE FROM ${seqname} WHERE id <> $highest_id");
+        if (DB::isError($result)) {
+            return $result;
+        }
+
+        // If another thread has been waiting for this lock,
+        // it will go thru the above procedure, but will have no
+        // real effect
+        $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
+        if (DB::isError($result)) {
+            return $result;
+        }
+        return true;
+    }
+
+    // }}}
+    // {{{ quoteIdentifier()
+
+    /**
+     * Quote a string so it can be safely used as a table or column name
+     *
+     * Quoting style depends on which database driver is being used.
+     *
+     * MySQL can't handle the backtick character (<kbd>`</kbd>) in
+     * table or column names.
+     *
+     * @param string $str  identifier name to be quoted
+     *
+     * @return string  quoted identifier string
+     *
+     * @since 1.6.0
+     * @access public
+     * @internal
+     */
+    function quoteIdentifier($str)
+    {
+        return '`' . $str . '`';
+    }
+
+    // }}}
+    // {{{ quote()
+
+    /**
+     * @deprecated  Deprecated in release 1.6.0
+     * @internal
+     */
+    function quote($str) {
+        return $this->quoteSmart($str);
+    }
+
+    // }}}
+    // {{{ escapeSimple()
+
+    /**
+     * Escape a string according to the current DBMS's standards
+     *
+     * @param string $str  the string to be escaped
+     *
+     * @return string  the escaped string
+     *
+     * @internal
+     */
+    function escapeSimple($str) {
+        if(function_exists('mysql_real_escape_string')) {
+            return mysql_real_escape_string($str, $this->connection);
+        } else {
+            return mysql_escape_string($str);
+        }
+    }
+
+    // }}}
+    // {{{ modifyQuery()
+
+    function modifyQuery($query)
+    {
+        if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
+            // "DELETE FROM table" gives 0 affected rows in MySQL.
+            // This little hack lets you know how many rows were deleted.
+            if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
+                $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
+                                      'DELETE FROM \1 WHERE 1=1', $query);
+            }
+        }
+        return $query;
+    }
+
+    // }}}
+    // {{{ modifyLimitQuery()
+
+    function modifyLimitQuery($query, $from, $count)
+    {
+        if (DB::isManip($query)) {
+            return $query . " LIMIT $count";
+        } else {
+            return $query . " LIMIT $from, $count";
+        }
+    }
+
+    // }}}
+    // {{{ mysqlRaiseError()
+
+    /**
+     * Gather information about an error, then use that info to create a
+     * DB error object and finally return that object.
+     *
+     * @param  integer  $errno  PEAR error number (usually a DB constant) if
+     *                          manually raising an error
+     * @return object  DB error object
+     * @see DB_common::errorCode()
+     * @see DB_common::raiseError()
+     */
+    function mysqlRaiseError($errno = null)
+    {
+        if ($errno === null) {
+            $errno = $this->errorCode(mysql_errno($this->connection));
+        }
+        return $this->raiseError($errno, null, null, null,
+                                 @mysql_errno($this->connection) . ' ** ' .
+                                 @mysql_error($this->connection));
+    }
+
+    // }}}
+    // {{{ tableInfo()
+
+    /**
+     * Returns information about a table or a result set.
+     *
+     * @param object|string  $result  DB_result object from a query or a
+     *                                string containing the name of a table
+     * @param int            $mode    a valid tableInfo mode
+     * @return array  an associative array with the information requested
+     *                or an error object if something is wrong
+     * @access public
+     * @internal
+     * @see DB_common::tableInfo()
+     */
+    function tableInfo($result, $mode = null) {
+        if (isset($result->result)) {
+            /*
+             * Probably received a result object.
+             * Extract the result resource identifier.
+             */
+            $id = $result->result;
+            $got_string = false;
+        } elseif (is_string($result)) {
+            /*
+             * Probably received a table name.
+             * Create a result resource identifier.
+             */
+            $id = @mysql_list_fields($this->dsn['database'],
+                                     $result, $this->connection);
+            $got_string = true;
+        } else {
+            /*
+             * Probably received a result resource identifier.
+             * Copy it.
+             * Deprecated.  Here for compatibility only.
+             */
+            $id = $result;
+            $got_string = false;
+        }
+
+        if (!is_resource($id)) {
+            return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA);
+        }
+
+        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
+            $case_func = 'strtolower';
+        } else {
+            $case_func = 'strval';
+        }
+
+        $count = @mysql_num_fields($id);
+
+        // made this IF due to performance (one if is faster than $count if's)
+        if (!$mode) {
+            for ($i=0; $i<$count; $i++) {
+                $res[$i]['table'] = $case_func(@mysql_field_table($id, $i));
+                $res[$i]['name']  = $case_func(@mysql_field_name($id, $i));
+                $res[$i]['type']  = @mysql_field_type($id, $i);
+                $res[$i]['len']   = @mysql_field_len($id, $i);
+                $res[$i]['flags'] = @mysql_field_flags($id, $i);
+            }
+        } else { // full
+            $res['num_fields']= $count;
+
+            for ($i=0; $i<$count; $i++) {
+                $res[$i]['table'] = $case_func(@mysql_field_table($id, $i));
+                $res[$i]['name']  = $case_func(@mysql_field_name($id, $i));
+                $res[$i]['type']  = @mysql_field_type($id, $i);
+                $res[$i]['len']   = @mysql_field_len($id, $i);
+                $res[$i]['flags'] = @mysql_field_flags($id, $i);
+
+                if ($mode & DB_TABLEINFO_ORDER) {
+                    $res['order'][$res[$i]['name']] = $i;
+                }
+                if ($mode & DB_TABLEINFO_ORDERTABLE) {
+                    $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
+                }
+            }
+        }
+
+        // free the result only if we were called on a table
+        if ($got_string) {
+            @mysql_free_result($id);
+        }
+        return $res;
+    }
+
+    // }}}
+    // {{{ getSpecialQuery()
+
+    /**
+     * Returns the query needed to get some backend info
+     * @param string $type What kind of info you want to retrieve
+     * @return string The SQL query string
+     */
+    function getSpecialQuery($type)
+    {
+        switch ($type) {
+            case 'tables':
+                return 'SHOW TABLES';
+            case 'views':
+                return DB_ERROR_NOT_CAPABLE;
+            case 'users':
+                $sql = 'select distinct User from user';
+                if($this->dsn['database'] != 'mysql') {
+                    $dsn = $this->dsn;
+                    $dsn['database'] = 'mysql';
+                    if (DB::isError($db = DB::connect($dsn))) {
+                        return $db;
+                    }
+                    $sql = $db->getCol($sql);
+                    $db->disconnect();
+                    // XXX Fixme the mysql driver should take care of this
+                    if (!@mysql_select_db($this->dsn['database'], $this->connection)) {
+                        return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+                    }
+                }
+                return $sql;
+            case 'databases':
+                return 'SHOW DATABASES';
+            default:
+                return null;
+        }
+    }
+
+    // }}}
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/mysql4.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/mysql4.php
new file mode 100755 (executable)
index 0000000..badcaa6
--- /dev/null
@@ -0,0 +1,885 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: Chaillan Nicolas <nicos@php.net>                             |
+// | Based on mysql.php by Stig Bakken <ssb@php.net>                      |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+
+// NOTE:  The tableInfo() method must be redone because the functions it
+// relies on no longer exist in the new extension.
+//
+// EXPERIMENTAL
+
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's mysqli
+ * extension.
+ *
+ * This is for MySQL versions 4.1 and above.  Requires PHP 5.
+ *
+ * Note that persistent connections no longer exist.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   Chaillan Nicolas <nicos@php.net>
+ */
+class DB_mysql4 extends DB_common
+{
+    // {{{ properties
+
+    var $connection;
+    var $phptype, $dbsyntax;
+    var $prepare_tokens = array();
+    var $prepare_types = array();
+    var $num_rows = array();
+    var $transaction_opcount = 0;
+    var $autocommit = true;
+    var $fetchmode = DB_FETCHMODE_ORDERED; /* Default fetch mode */
+    var $_db = false;
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * DB_mysql constructor.
+     *
+     * @access public
+     */
+    function DB_mysql4()
+    {
+        $this->DB_common();
+        $this->phptype = 'mysql4';
+        $this->dbsyntax = 'mysql4';
+        $this->features = array(
+            'prepare' => false,
+            'ssl' => true,
+            'transactions' => true,
+            'limit' => 'alter'
+        );
+        $this->errorcode_map = array(
+            1004 => DB_ERROR_CANNOT_CREATE,
+            1005 => DB_ERROR_CANNOT_CREATE,
+            1006 => DB_ERROR_CANNOT_CREATE,
+            1007 => DB_ERROR_ALREADY_EXISTS,
+            1008 => DB_ERROR_CANNOT_DROP,
+            1022 => DB_ERROR_ALREADY_EXISTS,
+            1046 => DB_ERROR_NODBSELECTED,
+            1050 => DB_ERROR_ALREADY_EXISTS,
+            1051 => DB_ERROR_NOSUCHTABLE,
+            1054 => DB_ERROR_NOSUCHFIELD,
+            1062 => DB_ERROR_ALREADY_EXISTS,
+            1064 => DB_ERROR_SYNTAX,
+            1100 => DB_ERROR_NOT_LOCKED,
+            1136 => DB_ERROR_VALUE_COUNT_ON_ROW,
+            1146 => DB_ERROR_NOSUCHTABLE,
+            1048 => DB_ERROR_CONSTRAINT,
+            1216 => DB_ERROR_CONSTRAINT,
+        );
+    }
+
+    // }}}
+    // {{{ connect()
+
+    /**
+     * Connect to a database and log in as the specified user.
+     *
+     * @param string $dsn the data source name (see DB::parseDSN for syntax)
+     * @param boolean $persistent (optional) whether the connection should
+     *                            be persistent
+     * @return mixed DB_OK on success, a DB error on failure
+     * @access public
+     */
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('mysqli')) {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+
+        $this->dsn = $dsninfo;
+        if ($dsninfo['protocol'] && $dsninfo['protocol'] == 'unix') {
+            $dbhost = ':' . $dsninfo['socket'];
+        } else {
+            $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
+            if ($dsninfo['port']) {
+                $dbhost .= ':' . $dsninfo['port'];
+            }
+        }
+
+        $ssl_mode = $this->getOption('ssl') === true ? 'CLIENT_SSL' : NULL;
+
+        @ini_set('track_errors', true);
+
+        if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
+            // Need to verify if arguments are okay
+            $conn = @mysqli_connect($dbhost, $dsninfo['username'],
+                                    $dsninfo['password'], $ssl_mode);
+        } elseif ($dbhost && isset($dsninfo['username'])) {
+            $conn = @mysqli_connect($dbhost, $dsninfo['username'], NULL,
+                                    $ssl_mode);
+        } elseif ($dbhost) {
+            $conn = @mysqli_connect($dbhost, NULL, NULL, $ssl_mode);
+        } else {
+            $conn = false;
+        }
+
+        @ini_restore('track_errors');
+
+        if (!$conn) {
+            if (($err = @mysqli_error()) != '') {
+                return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
+                                         null, $err);
+            } elseif (empty($php_errormsg)) {
+                return $this->raiseError(DB_ERROR_CONNECT_FAILED);
+            } else {
+                return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null,
+                                         null, $php_errormsg);
+            }
+        }
+
+        if ($dsninfo['database']) {
+            if (!@mysqli_select_db($dsninfo['database'], $conn)) {
+                switch(mysqli_errno($conn)) {
+                    case 1049:
+                        return $this->raiseError(DB_ERROR_NOSUCHDB, null, null,
+                                                 null, mysqli_error($conn));
+                    case 1044:
+                         return $this->raiseError(DB_ERROR_ACCESS_VIOLATION, null, null,
+                                                  null, mysqli_error($conn));
+                    default:
+                        return $this->raiseError(DB_ERROR, null, null,
+                                                 null, mysqli_error($conn));
+                }
+            }
+            // fix to allow calls to different databases in the same script
+            $this->_db = $dsninfo['database'];
+        }
+
+        if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {
+            $this->errorcode_map[1022] = DB_ERROR_CONSTRAINT;
+            $this->errorcode_map[1062] = DB_ERROR_CONSTRAINT;
+        }
+
+        $this->connection = $conn;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ disconnect()
+
+    /**
+     * Log out and disconnect from the database.
+     *
+     * @return boolean TRUE on success, FALSE if not connected
+     * @access public
+     */
+    function disconnect()
+    {
+        $ret = mysqli_close($this->connection);
+        $this->connection = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ simpleQuery()
+
+    /**
+     * Send a query to MySQL and return the results as a MySQL resource
+     * identifier.
+     *
+     * @param string $query the SQL query
+     * @return mixed a valid MySQL result for successful SELECT
+     *               queries, DB_OK for other successful queries.
+     *               A DB error is returned on failure.
+     * @access public
+     */
+    function simpleQuery($query)
+    {
+        $ismanip = DB::isManip($query);
+        $this->last_query = $query;
+        $query = $this->modifyQuery($query);
+        if ($this->_db) {
+            if (!@mysqli_select_db($this->_db, $this->connection)) {
+                return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+            }
+        }
+        if (!$this->autocommit && $ismanip) {
+            if ($this->transaction_opcount == 0) {
+                $result = @mysqli_query('SET AUTOCOMMIT=0', $this->connection);
+                $result = @mysqli_query('BEGIN', $this->connection);
+                if (!$result) {
+                    return $this->mysqlRaiseError();
+                }
+            }
+            $this->transaction_opcount++;
+        }
+        $result = @mysqli_query($query, $this->connection);
+        if (!$result) {
+            return $this->mysqlRaiseError();
+        }
+        if (is_resource($result)) {
+            $numrows = $this->numrows($result);
+            if (is_object($numrows)) {
+                return $numrows;
+            }
+            $this->num_rows[(int)$result] = $numrows;
+            return $result;
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ nextResult()
+
+    /**
+     * Move the internal mysql result pointer to the next available result.
+     *
+     * This method has not been implemented yet.
+     *
+     * @param resource $result a valid sql result resource
+     * @return false
+     * @access public
+     */
+    function nextResult($result)
+    {
+        return false;
+    }
+
+    // }}}
+    // {{{ fetchInto()
+
+    /**
+     * Fetch a row and insert the data into an existing array.
+     *
+     * Formating of the array and the data therein are configurable.
+     * See DB_result::fetchInto() for more information.
+     *
+     * @param resource $result    query result identifier
+     * @param array    $arr       (reference) array where data from the row
+     *                            should be placed
+     * @param int      $fetchmode how the resulting array should be indexed
+     * @param int      $rownum    the row number to fetch
+     *
+     * @return mixed DB_OK on success, NULL when end of result set is
+     *               reached or on failure
+     *
+     * @see DB_result::fetchInto()
+     * @access private
+     */
+    function fetchInto($result, &$arr, $fetchmode, $rownum=null)
+    {
+        if ($rownum !== null) {
+            if (!@mysqli_data_seek($result, $rownum)) {
+                return null;
+            }
+        }
+        if ($fetchmode & DB_FETCHMODE_ASSOC) {
+            $arr = @mysqli_fetch_array($result, MYSQLI_ASSOC);
+            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
+                $arr = array_change_key_case($arr, CASE_LOWER);
+            }
+        } else {
+            $arr = @mysqli_fetch_row($result);
+        }
+        if (!$arr) {
+            $errno = @mysqli_errno($this->connection);
+            if (!$errno) {
+                return NULL;
+            }
+            return $this->mysqlRaiseError($errno);
+        }
+        if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
+            /*
+             * Even though this DBMS already trims output, we do this because
+             * a field might have intentional whitespace at the end that
+             * gets removed by DB_PORTABILITY_RTRIM under another driver.
+             */
+            $this->_rtrimArrayValues($arr);
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ freeResult()
+
+    /**
+     * Free the internal resources associated with $result.
+     *
+     * @param resource $result MySQL result identifier
+     * @return bool TRUE on success, FALSE if $result is invalid
+     * @access public
+     */
+    function freeResult($result)
+    {
+        unset($this->num_rows[(int)$result]);
+        return @mysqli_free_result($result);
+    }
+
+    // }}}
+    // {{{ numCols()
+
+    /**
+     * Get the number of columns in a result set.
+     *
+     * @param $result MySQL result identifier
+     *
+     * @access public
+     *
+     * @return int the number of columns per row in $result
+     */
+    function numCols($result)
+    {
+        $cols = @mysqli_num_fields($result);
+
+        if (!$cols) {
+            return $this->mysqlRaiseError();
+        }
+
+        return $cols;
+    }
+
+    // }}}
+    // {{{ numRows()
+
+    /**
+     * Get the number of rows in a result set.
+     *
+     * @param resource $result MySQL result identifier
+     * @return int the number of rows in $result
+     * @access public
+     */
+    function numRows($result)
+    {
+        $rows = @mysqli_num_rows($result);
+        if ($rows === null) {
+            return $this->mysqlRaiseError();
+        }
+        return $rows;
+    }
+
+    // }}}
+    // {{{ autoCommit()
+
+    /**
+     * Enable/disable automatic commits.
+     */
+    function autoCommit($onoff = false)
+    {
+        // XXX if $this->transaction_opcount > 0, we should probably
+        // issue a warning here.
+        $this->autocommit = $onoff ? true : false;
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ commit()
+
+    /**
+     * Commit the current transaction.
+     */
+    function commit()
+    {
+        if ($this->transaction_opcount > 0) {
+            if ($this->_db) {
+                if (!@mysqli_select_db($this->_db, $this->connection)) {
+                    return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+                }
+            }
+            $result = @mysqli_query('COMMIT', $this->connection);
+            $result = @mysqli_query('SET AUTOCOMMIT=1', $this->connection);
+            $this->transaction_opcount = 0;
+            if (!$result) {
+                return $this->mysqlRaiseError();
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ rollback()
+
+    /**
+     * Roll back (undo) the current transaction.
+     */
+    function rollback()
+    {
+        if ($this->transaction_opcount > 0) {
+            if ($this->_db) {
+                if (!@mysqli_select_db($this->_db, $this->connection)) {
+                    return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+                }
+            }
+            $result = @mysqli_query('ROLLBACK', $this->connection);
+            $result = @mysqli_query('SET AUTOCOMMIT=1', $this->connection);
+            $this->transaction_opcount = 0;
+            if (!$result) {
+                return $this->mysqlRaiseError();
+            }
+        }
+        return DB_OK;
+    }
+
+    // }}}
+    // {{{ affectedRows()
+
+    /**
+     * Gets the number of rows affected by the data manipulation
+     * query.  For other queries, this function returns 0.
+     *
+     * @return integer number of rows affected by the last query
+     */
+    function affectedRows()
+    {
+        if (DB::isManip($this->last_query)) {
+            $result = @mysqli_affected_rows($this->connection);
+        } else {
+            $result = 0;
+        }
+        return $result;
+     }
+
+    // }}}
+    // {{{ errorNative()
+
+    /**
+     * Get the native error code of the last error (if any) that
+     * occured on the current connection.
+     *
+     * @return int native MySQL error code
+     * @access public
+     */
+    function errorNative()
+    {
+        return mysqli_errno($this->connection);
+    }
+
+    // }}}
+    // {{{ nextId()
+
+    /**
+     * Returns the next free id in a sequence
+     *
+     * @param string  $seq_name  name of the sequence
+     * @param boolean $ondemand  when true, the seqence is automatically
+     *                           created if it does not exist
+     *
+     * @return int  the next id number in the sequence.  DB_Error if problem.
+     *
+     * @internal
+     * @see DB_common::nextID()
+     * @access public
+     */
+    function nextId($seq_name, $ondemand = true)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        do {
+            $repeat = 0;
+            $this->pushErrorHandling(PEAR_ERROR_RETURN);
+            $result = $this->query("UPDATE ${seqname} ".
+                                   'SET id=LAST_INSERT_ID(id+1)');
+            $this->popErrorHandling();
+            if ($result == DB_OK) {
+                /** COMMON CASE **/
+                $id = @mysqli_insert_id($this->connection);
+                if ($id != 0) {
+                    return $id;
+                }
+                /** EMPTY SEQ TABLE **/
+                // Sequence table must be empty for some reason, so fill it and return 1
+                // Obtain a user-level lock
+                $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+                if ($result == 0) {
+                    // Failed to get the lock, bail with a DB_ERROR_NOT_LOCKED error
+                    return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
+                }
+
+                // add the default value
+                $result = $this->query("REPLACE INTO ${seqname} VALUES (0)");
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+
+                // Release the lock
+                $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+                // We know what the result will be, so no need to try again
+                return 1;
+
+            /** ONDEMAND TABLE CREATION **/
+            } elseif ($ondemand && DB::isError($result) &&
+                $result->getCode() == DB_ERROR_NOSUCHTABLE)
+            {
+                $result = $this->createSequence($seq_name);
+                // Since createSequence initializes the ID to be 1,
+                // we do not need to retrieve the ID again (or we will get 2)
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                } else {
+                    // First ID of a newly created sequence is 1
+                    return 1;
+                }
+
+            /** BACKWARDS COMPAT **/
+            } elseif (DB::isError($result) &&
+                      $result->getCode() == DB_ERROR_ALREADY_EXISTS)
+            {
+                // see _BCsequence() comment
+                $result = $this->_BCsequence($seqname);
+                if (DB::isError($result)) {
+                    return $this->raiseError($result);
+                }
+                $repeat = 1;
+            }
+        } while ($repeat);
+
+        return $this->raiseError($result);
+    }
+
+    /**
+     * Creates a new sequence
+     *
+     * @param string $seq_name  name of the new sequence
+     *
+     * @return int  DB_OK on success.  A DB_Error object is returned if
+     *              problems arise.
+     *
+     * @internal
+     * @see DB_common::createSequence()
+     * @access public
+     */
+    function createSequence($seq_name)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        $res = $this->query("CREATE TABLE ${seqname} ".
+                            '(id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL,'.
+                            ' PRIMARY KEY(id))');
+        if (DB::isError($res)) {
+            return $res;
+        }
+        // insert yields value 1, nextId call will generate ID 2
+        return $this->query("INSERT INTO ${seqname} VALUES(0)");
+    }
+
+    // }}}
+    // {{{ dropSequence()
+
+    /**
+     * Deletes a sequence
+     *
+     * @param string $seq_name  name of the sequence to be deleted
+     *
+     * @return int  DB_OK on success.  DB_Error if problems.
+     *
+     * @internal
+     * @see DB_common::dropSequence()
+     * @access public
+     */
+    function dropSequence($seq_name)
+    {
+        $seqname = $this->getSequenceName($seq_name);
+        return $this->query("DROP TABLE ${seqname}");
+    }
+
+    // }}}
+    // {{{ _BCsequence()
+
+    /**
+     * Backwards compatibility with old sequence emulation implementation
+     * (clean up the dupes).
+     *
+     * @param string $seqname The sequence name to clean up
+     * @return mixed DB_Error or true
+     */
+    function _BCsequence($seqname)
+    {
+        // Obtain a user-level lock... this will release any previous
+        // application locks, but unlike LOCK TABLES, it does not abort
+        // the current transaction and is much less frequently used.
+        $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)");
+        if (DB::isError($result)) {
+            return $result;
+        }
+        if ($result == 0) {
+            // Failed to get the lock, can't do the conversion, bail
+            // with a DB_ERROR_NOT_LOCKED error
+            return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED);
+        }
+
+        $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}");
+        if (DB::isError($highest_id)) {
+            return $highest_id;
+        }
+        // This should kill all rows except the highest
+        // We should probably do something if $highest_id isn't
+        // numeric, but I'm at a loss as how to handle that...
+        $result = $this->query("DELETE FROM ${seqname} WHERE id <> $highest_id");
+        if (DB::isError($result)) {
+            return $result;
+        }
+
+        // If another thread has been waiting for this lock,
+        // it will go thru the above procedure, but will have no
+        // real effect
+        $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')");
+        if (DB::isError($result)) {
+            return $result;
+        }
+        return true;
+    }
+
+    // }}}
+    // {{{ quoteIdentifier()
+
+    /**
+     * Quote a string so it can be safely used as a table or column name
+     *
+     * Quoting style depends on which database driver is being used.
+     *
+     * MySQL can't handle the backtick character (<kbd>`</kbd>) in
+     * table or column names.
+     *
+     * @param string $str  identifier name to be quoted
+     *
+     * @return string  quoted identifier string
+     *
+     * @since 1.6.0
+     * @access public
+     * @internal
+     */
+    function quoteIdentifier($str)
+    {
+        return '`' . $str . '`';
+    }
+
+    // }}}
+    // {{{ escapeSimple()
+
+    /**
+     * Escape a string according to the current DBMS's standards
+     *
+     * @param string $str  the string to be escaped
+     *
+     * @return string  the escaped string
+     *
+     * @internal
+     */
+    function escapeSimple($str) {
+        return mysqli_real_escape_string($str, $this->connection);
+    }
+
+    // }}}
+    // {{{ modifyQuery()
+
+    function modifyQuery($query)
+    {
+        if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) {
+            // "DELETE FROM table" gives 0 affected rows in MySQL.
+            // This little hack lets you know how many rows were deleted.
+            if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) {
+                $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/',
+                                      'DELETE FROM \1 WHERE 1=1', $query);
+            }
+        }
+        return $query;
+    }
+
+    // }}}
+    // {{{ modifyLimitQuery()
+
+    function modifyLimitQuery($query, $from, $count)
+    {
+        if (DB::isManip($query)) {
+            return $query . " LIMIT $count";
+        } else {
+            return $query . " LIMIT $from, $count";
+        }
+    }
+
+    // }}}
+    // {{{ mysqlRaiseError()
+
+    /**
+     * Gather information about an error, then use that info to create a
+     * DB error object and finally return that object.
+     *
+     * @param  integer  $errno  PEAR error number (usually a DB constant) if
+     *                          manually raising an error
+     * @return object  DB error object
+     * @see DB_common::errorCode()
+     * @see DB_common::raiseError()
+     */
+    function mysqlRaiseError($errno = null)
+    {
+        if ($errno === null) {
+            $errno = $this->errorCode(mysqli_errno($this->connection));
+        }
+        return $this->raiseError($errno, null, null, null,
+                                 @mysqli_errno($this->connection) . ' ** ' .
+                                 @mysqli_error($this->connection));
+    }
+
+    // }}}
+    // {{{ tableInfo()
+
+    /**
+     * Returns information about a table or a result set.
+     *
+     * WARNING: this method will probably not work because the mysqli_*()
+     * functions it relies upon may not exist.
+     *
+     * @param object|string  $result  DB_result object from a query or a
+     *                                string containing the name of a table
+     * @param int            $mode    a valid tableInfo mode
+     * @return array  an associative array with the information requested
+     *                or an error object if something is wrong
+     * @access public
+     * @internal
+     * @see DB_common::tableInfo()
+     */
+    function tableInfo($result, $mode = null) {
+        if (isset($result->result)) {
+            /*
+             * Probably received a result object.
+             * Extract the result resource identifier.
+             */
+            $id = $result->result;
+            $got_string = false;
+        } elseif (is_string($result)) {
+            /*
+             * Probably received a table name.
+             * Create a result resource identifier.
+             */
+            $id = @mysqli_list_fields($this->dsn['database'],
+                                     $result, $this->connection);
+            $got_string = true;
+        } else {
+            /*
+             * Probably received a result resource identifier.
+             * Copy it.
+             * Depricated.  Here for compatibility only.
+             */
+            $id = $result;
+            $got_string = false;
+        }
+
+        if (!is_resource($id)) {
+            return $this->mysqlRaiseError(DB_ERROR_NEED_MORE_DATA);
+        }
+
+        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
+            $case_func = 'strtolower';
+        } else {
+            $case_func = 'strval';
+        }
+
+        $count = @mysqli_num_fields($id);
+
+        // made this IF due to performance (one if is faster than $count if's)
+        if (!$mode) {
+            for ($i=0; $i<$count; $i++) {
+                $res[$i]['table'] = $case_func(@mysqli_field_table($id, $i));
+                $res[$i]['name']  = $case_func(@mysqli_field_name($id, $i));
+                $res[$i]['type']  = @mysqli_field_type($id, $i);
+                $res[$i]['len']   = @mysqli_field_len($id, $i);
+                $res[$i]['flags'] = @mysqli_field_flags($id, $i);
+            }
+        } else { // full
+            $res['num_fields']= $count;
+
+            for ($i=0; $i<$count; $i++) {
+                $res[$i]['table'] = $case_func(@mysqli_field_table($id, $i));
+                $res[$i]['name']  = $case_func(@mysqli_field_name($id, $i));
+                $res[$i]['type']  = @mysqli_field_type($id, $i);
+                $res[$i]['len']   = @mysqli_field_len($id, $i);
+                $res[$i]['flags'] = @mysqli_field_flags($id, $i);
+
+                if ($mode & DB_TABLEINFO_ORDER) {
+                    $res['order'][$res[$i]['name']] = $i;
+                }
+                if ($mode & DB_TABLEINFO_ORDERTABLE) {
+                    $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
+                }
+            }
+        }
+
+        // free the result only if we were called on a table
+        if ($got_string) {
+            @mysqli_free_result($id);
+        }
+        return $res;
+    }
+
+    // }}}
+    // {{{ getSpecialQuery()
+
+    /**
+     * Returns the query needed to get some backend info.
+     *
+     * @param string $type What kind of info you want to retrieve
+     * @return string The SQL query string
+     */
+    function getSpecialQuery($type)
+    {
+        switch ($type) {
+            case 'tables':
+                return 'SHOW TABLES';
+            case 'views':
+                return DB_ERROR_NOT_CAPABLE;
+            case 'users':
+                $sql = 'select distinct User from user';
+                if($this->dsn['database'] != 'mysql') {
+                    $dsn = $this->dsn;
+                    $dsn['database'] = 'mysql';
+                    if (DB::isError($db = DB::connect($dsn))) {
+                        return $db;
+                    }
+                    $sql = $db->getCol($sql);
+                    $db->disconnect();
+                    // XXX Fixme the mysql driver should take care of this
+                    if (!@mysqli_select_db($this->dsn['database'], $this->connection)) {
+                        return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED);
+                    }
+                }
+                return $sql;
+            case 'databases':
+                return 'SHOW DATABASES';
+            default:
+                return null;
+        }
+    }
+
+   // }}}
+
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+
+?>
diff --git a/typo3/sysext/dbal/DB-1.6.0RC6/DB/oci8.php b/typo3/sysext/dbal/DB-1.6.0RC6/DB/oci8.php
new file mode 100755 (executable)
index 0000000..88ac5d7
--- /dev/null
@@ -0,0 +1,857 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2004 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license,      |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Author: James L. Pine <jlp@valinux.com>                              |
+// | Maintainer: Daniel Convissor <danielc@php.net>                       |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+
+// be aware...  OCIError() only appears to return anything when given a
+// statement, so functions return the generic DB_ERROR instead of more
+// useful errors that have to do with feedback from the database.
+
+
+require_once 'DB/common.php';
+
+/**
+ * Database independent query interface definition for PHP's Oracle 8
+ * call-interface extension.
+ *
+ * Definitely works with versions 8 and 9 of Oracle.
+ *
+ * @package  DB
+ * @version  $Id$
+ * @category Database
+ * @author   James L. Pine <jlp@valinux.com>
+ */
+class DB_oci8 extends DB_common
+{
+    // {{{ properties
+
+    var $connection;
+    var $phptype, $dbsyntax;
+    var $manip_query = array();
+    var $prepare_types = array();
+    var $autoCommit = 1;
+    var $last_stmt = false;
+
+    // }}}
+    // {{{ constructor
+
+    function DB_oci8()
+    {
+        $this->DB_common();
+        $this->phptype = 'oci8';
+        $this->dbsyntax = 'oci8';
+        $this->features = array(
+            'prepare' => false,
+            'pconnect' => true,
+            'transactions' => true,
+            'limit' => 'alter'
+        );
+        $this->errorcode_map = array(
+            1 => DB_ERROR_CONSTRAINT,
+            900 => DB_ERROR_SYNTAX,
+            904 => DB_ERROR_NOSUCHFIELD,
+            921 => DB_ERROR_SYNTAX,
+            923 => DB_ERROR_SYNTAX,
+            942 => DB_ERROR_NOSUCHTABLE,
+            955 => DB_ERROR_ALREADY_EXISTS,
+            1476 => DB_ERROR_DIVZERO,
+            1722 => DB_ERROR_INVALID_NUMBER,
+            2289 => DB_ERROR_NOSUCHTABLE,
+            2291 => DB_ERROR_CONSTRAINT,
+            2449 => DB_ERROR_CONSTRAINT,
+        );
+    }
+
+    // }}}
+    // {{{ connect()
+
+    /**
+     * Connect to a database and log in as the specified user.
+     *
+     * @param $dsn the data source name (see DB::parseDSN for syntax)
+     * @param $persistent (optional) whether the connection should
+     *        be persistent
+     *
+     * @return int DB_OK on success, a DB error code on failure
+     */
+    function connect($dsninfo, $persistent = false)
+    {
+        if (!DB::assertExtension('oci8')) {
+            return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
+        }
+        $this->dsn = $dsninfo;
+
+        $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon';
+
+        if ($dsninfo['hostspec']) {
+            $conn = @$connect_function($dsninfo['username'],
+                                       $dsninfo['password'],
+                                       $dsninfo['hostspec']);
+        } elseif ($dsninfo['username'] || $dsninfo['password']) {