[Astrospaces-commits] SF.net SVN: astrospaces: [38] trunk/functions
Brought to you by:
p3net
From: <cal...@us...> - 2007-07-30 04:57:49
|
Revision: 38 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=38&view=rev Author: caleb870 Date: 2007-07-29 21:57:52 -0700 (Sun, 29 Jul 2007) Log Message: ----------- Adding ADOdb lite. Added Paths: ----------- trunk/functions/adodb-datadict.inc.php trunk/functions/adodb-error.inc.php trunk/functions/adodb-errorhandler.inc.php trunk/functions/adodb-errorpear.inc.php trunk/functions/adodb-exceptions.inc.php trunk/functions/adodb-perf-module.inc.php trunk/functions/adodb-perf.inc.php trunk/functions/adodb-time.inc.php trunk/functions/adodb-xmlschema.inc.php trunk/functions/adodb.config.php trunk/functions/adodb.inc.php trunk/functions/adodbSQL_drivers/ trunk/functions/adodbSQL_drivers/fbsql/ trunk/functions/adodbSQL_drivers/fbsql/fbsql_datadict.inc trunk/functions/adodbSQL_drivers/fbsql/fbsql_date_module.inc trunk/functions/adodbSQL_drivers/fbsql/fbsql_driver.inc trunk/functions/adodbSQL_drivers/fbsql/fbsql_extend_module.inc trunk/functions/adodbSQL_drivers/fbsql/fbsql_meta_module.inc trunk/functions/adodbSQL_drivers/fbsql/fbsql_transaction_module.inc trunk/functions/adodbSQL_drivers/gladius/ trunk/functions/adodbSQL_drivers/gladius/gladius_datadict.inc trunk/functions/adodbSQL_drivers/gladius/gladius_date_module.inc trunk/functions/adodbSQL_drivers/gladius/gladius_driver.inc trunk/functions/adodbSQL_drivers/gladius/gladius_extend_module.inc trunk/functions/adodbSQL_drivers/gladius/gladius_meta_module.inc trunk/functions/adodbSQL_drivers/gladius/gladius_transaction_module.inc trunk/functions/adodbSQL_drivers/maxdb/ trunk/functions/adodbSQL_drivers/maxdb/maxdb_datadict.inc trunk/functions/adodbSQL_drivers/maxdb/maxdb_date_module.inc trunk/functions/adodbSQL_drivers/maxdb/maxdb_driver.inc trunk/functions/adodbSQL_drivers/maxdb/maxdb_extend_module.inc trunk/functions/adodbSQL_drivers/maxdb/maxdb_meta_module.inc trunk/functions/adodbSQL_drivers/maxdb/maxdb_transaction_module.inc trunk/functions/adodbSQL_drivers/msql/ trunk/functions/adodbSQL_drivers/msql/msql_datadict.inc trunk/functions/adodbSQL_drivers/msql/msql_date_module.inc trunk/functions/adodbSQL_drivers/msql/msql_driver.inc trunk/functions/adodbSQL_drivers/msql/msql_extend_module.inc trunk/functions/adodbSQL_drivers/msql/msql_meta_module.inc trunk/functions/adodbSQL_drivers/msql/msql_transaction_module.inc trunk/functions/adodbSQL_drivers/mssql/ trunk/functions/adodbSQL_drivers/mssql/mssql_datadict.inc trunk/functions/adodbSQL_drivers/mssql/mssql_date_module.inc trunk/functions/adodbSQL_drivers/mssql/mssql_driver.inc trunk/functions/adodbSQL_drivers/mssql/mssql_extend_module.inc trunk/functions/adodbSQL_drivers/mssql/mssql_meta_module.inc trunk/functions/adodbSQL_drivers/mssql/mssql_transaction_module.inc trunk/functions/adodbSQL_drivers/mssqlpo/ trunk/functions/adodbSQL_drivers/mssqlpo/mssqlpo_datadict.inc trunk/functions/adodbSQL_drivers/mssqlpo/mssqlpo_date_module.inc trunk/functions/adodbSQL_drivers/mssqlpo/mssqlpo_driver.inc trunk/functions/adodbSQL_drivers/mssqlpo/mssqlpo_extend_module.inc trunk/functions/adodbSQL_drivers/mssqlpo/mssqlpo_meta_module.inc trunk/functions/adodbSQL_drivers/mssqlpo/mssqlpo_transaction_module.inc trunk/functions/adodbSQL_drivers/mysql/ trunk/functions/adodbSQL_drivers/mysql/mysql_datadict.inc trunk/functions/adodbSQL_drivers/mysql/mysql_date_module.inc trunk/functions/adodbSQL_drivers/mysql/mysql_driver.inc trunk/functions/adodbSQL_drivers/mysql/mysql_extend_module.inc trunk/functions/adodbSQL_drivers/mysql/mysql_meta_module.inc trunk/functions/adodbSQL_drivers/mysql/mysql_perfmon_module.inc trunk/functions/adodbSQL_drivers/mysql/mysql_transaction_module.inc trunk/functions/adodbSQL_drivers/mysqli/ trunk/functions/adodbSQL_drivers/mysqli/mysqli_datadict.inc trunk/functions/adodbSQL_drivers/mysqli/mysqli_date_module.inc trunk/functions/adodbSQL_drivers/mysqli/mysqli_driver.inc trunk/functions/adodbSQL_drivers/mysqli/mysqli_extend_module.inc trunk/functions/adodbSQL_drivers/mysqli/mysqli_meta_module.inc trunk/functions/adodbSQL_drivers/mysqli/mysqli_perfmon_module.inc trunk/functions/adodbSQL_drivers/mysqli/mysqli_transaction_module.inc trunk/functions/adodbSQL_drivers/mysqlt/ trunk/functions/adodbSQL_drivers/mysqlt/mysqlt_datadict.inc trunk/functions/adodbSQL_drivers/mysqlt/mysqlt_date_module.inc trunk/functions/adodbSQL_drivers/mysqlt/mysqlt_driver.inc trunk/functions/adodbSQL_drivers/mysqlt/mysqlt_extend_module.inc trunk/functions/adodbSQL_drivers/mysqlt/mysqlt_meta_module.inc trunk/functions/adodbSQL_drivers/mysqlt/mysqlt_perfmon_module.inc trunk/functions/adodbSQL_drivers/mysqlt/mysqlt_transaction_module.inc trunk/functions/adodbSQL_drivers/odbc/ trunk/functions/adodbSQL_drivers/odbc/odbc_datadict.inc trunk/functions/adodbSQL_drivers/odbc/odbc_date_module.inc trunk/functions/adodbSQL_drivers/odbc/odbc_driver.inc trunk/functions/adodbSQL_drivers/odbc/odbc_extend_module.inc trunk/functions/adodbSQL_drivers/odbc/odbc_meta_module.inc trunk/functions/adodbSQL_drivers/odbc/odbc_transaction_module.inc trunk/functions/adodbSQL_drivers/postgres/ trunk/functions/adodbSQL_drivers/postgres/postgres_datadict.inc trunk/functions/adodbSQL_drivers/postgres/postgres_date_module.inc trunk/functions/adodbSQL_drivers/postgres/postgres_driver.inc trunk/functions/adodbSQL_drivers/postgres/postgres_extend_module.inc trunk/functions/adodbSQL_drivers/postgres/postgres_meta_module.inc trunk/functions/adodbSQL_drivers/postgres/postgres_transaction_module.inc trunk/functions/adodbSQL_drivers/postgres64/ trunk/functions/adodbSQL_drivers/postgres64/postgres64_datadict.inc trunk/functions/adodbSQL_drivers/postgres64/postgres64_date_module.inc trunk/functions/adodbSQL_drivers/postgres64/postgres64_driver.inc trunk/functions/adodbSQL_drivers/postgres64/postgres64_extend_module.inc trunk/functions/adodbSQL_drivers/postgres64/postgres64_meta_module.inc trunk/functions/adodbSQL_drivers/postgres64/postgres64_transaction_module.inc trunk/functions/adodbSQL_drivers/postgres7/ trunk/functions/adodbSQL_drivers/postgres7/postgres7_datadict.inc trunk/functions/adodbSQL_drivers/postgres7/postgres7_date_module.inc trunk/functions/adodbSQL_drivers/postgres7/postgres7_driver.inc trunk/functions/adodbSQL_drivers/postgres7/postgres7_extend_module.inc trunk/functions/adodbSQL_drivers/postgres7/postgres7_meta_module.inc trunk/functions/adodbSQL_drivers/postgres7/postgres7_transaction_module.inc trunk/functions/adodbSQL_drivers/postgres8/ trunk/functions/adodbSQL_drivers/postgres8/postgres8_datadict.inc trunk/functions/adodbSQL_drivers/postgres8/postgres8_date_module.inc trunk/functions/adodbSQL_drivers/postgres8/postgres8_driver.inc trunk/functions/adodbSQL_drivers/postgres8/postgres8_extend_module.inc trunk/functions/adodbSQL_drivers/postgres8/postgres8_meta_module.inc trunk/functions/adodbSQL_drivers/postgres8/postgres8_transaction_module.inc trunk/functions/adodbSQL_drivers/sqlite/ trunk/functions/adodbSQL_drivers/sqlite/sqlite_datadict.inc trunk/functions/adodbSQL_drivers/sqlite/sqlite_date_module.inc trunk/functions/adodbSQL_drivers/sqlite/sqlite_driver.inc trunk/functions/adodbSQL_drivers/sqlite/sqlite_extend_module.inc trunk/functions/adodbSQL_drivers/sqlite/sqlite_meta_module.inc trunk/functions/adodbSQL_drivers/sqlite/sqlite_transaction_module.inc trunk/functions/adodbSQL_drivers/sqlitepo/ trunk/functions/adodbSQL_drivers/sqlitepo/sqlitepo_datadict.inc trunk/functions/adodbSQL_drivers/sqlitepo/sqlitepo_date_module.inc trunk/functions/adodbSQL_drivers/sqlitepo/sqlitepo_driver.inc trunk/functions/adodbSQL_drivers/sqlitepo/sqlitepo_extend_module.inc trunk/functions/adodbSQL_drivers/sqlitepo/sqlitepo_meta_module.inc trunk/functions/adodbSQL_drivers/sqlitepo/sqlitepo_transaction_module.inc trunk/functions/adodbSQL_drivers/sybase/ trunk/functions/adodbSQL_drivers/sybase/sybase_datadict.inc trunk/functions/adodbSQL_drivers/sybase/sybase_date_module.inc trunk/functions/adodbSQL_drivers/sybase/sybase_driver.inc trunk/functions/adodbSQL_drivers/sybase/sybase_extend_module.inc trunk/functions/adodbSQL_drivers/sybase/sybase_meta_module.inc trunk/functions/adodbSQL_drivers/sybase/sybase_transaction_module.inc trunk/functions/adodbSQL_drivers/sybase_ase/ trunk/functions/adodbSQL_drivers/sybase_ase/sybase_ase_datadict.inc trunk/functions/adodbSQL_drivers/sybase_ase/sybase_ase_date_module.inc trunk/functions/adodbSQL_drivers/sybase_ase/sybase_ase_driver.inc trunk/functions/adodbSQL_drivers/sybase_ase/sybase_ase_extend_module.inc trunk/functions/adodbSQL_drivers/sybase_ase/sybase_ase_meta_module.inc trunk/functions/adodbSQL_drivers/sybase_ase/sybase_ase_transaction_module.inc trunk/functions/documentation/ trunk/functions/documentation/adodb_license.txt trunk/functions/documentation/adodb_lite_commands.html trunk/functions/documentation/adodb_lite_datadictionary.html trunk/functions/documentation/adodb_lite_debugconsole.html trunk/functions/documentation/adodb_lite_errorhandling.html trunk/functions/documentation/adodb_lite_howtoinstall.html trunk/functions/documentation/adodb_lite_modulecreation.html trunk/functions/documentation/adodb_lite_modules.html trunk/functions/documentation/adodb_lite_performancemonitor.html trunk/functions/documentation/adodb_lite_sessions.html trunk/functions/documentation/changelog.txt trunk/functions/documentation/example_generic_module.inc trunk/functions/documentation/example_module.inc trunk/functions/documentation/images/ trunk/functions/documentation/images/dot_b.gif trunk/functions/documentation/images/e05.gif trunk/functions/documentation/images/fon_bar01.gif trunk/functions/documentation/images/query_de.gif trunk/functions/documentation/license.txt trunk/functions/documentation/readme.txt trunk/functions/documentation/style.css trunk/functions/generic_modules/ trunk/functions/generic_modules/adodblite_module.inc trunk/functions/generic_modules/menu_module.inc trunk/functions/generic_modules/object_module.inc trunk/functions/generic_modules/pear_module.inc trunk/functions/lang/ trunk/functions/lang/adodb-ar.inc.php trunk/functions/lang/adodb-bg.inc.php trunk/functions/lang/adodb-bgutf8.inc.php trunk/functions/lang/adodb-ca.inc.php trunk/functions/lang/adodb-cn.inc.php trunk/functions/lang/adodb-cz.inc.php trunk/functions/lang/adodb-da.inc.php trunk/functions/lang/adodb-de.inc.php trunk/functions/lang/adodb-en.inc.php trunk/functions/lang/adodb-es.inc.php trunk/functions/lang/adodb-esperanto.inc.php trunk/functions/lang/adodb-fr.inc.php trunk/functions/lang/adodb-hu.inc.php trunk/functions/lang/adodb-it.inc.php trunk/functions/lang/adodb-nl.inc.php trunk/functions/lang/adodb-pl.inc.php trunk/functions/lang/adodb-pt-br.inc.php trunk/functions/lang/adodb-ro.inc.php trunk/functions/lang/adodb-ru1251.inc.php trunk/functions/lang/adodb-sv.inc.php trunk/functions/lang/adodb-uk1251.inc.php trunk/functions/query_debug_console/ trunk/functions/query_debug_console/query_debug_console.php trunk/functions/query_debug_console/query_debug_console.tpl trunk/functions/session/ trunk/functions/session/adodb-compress-bzip2.php trunk/functions/session/adodb-compress-gzip.php trunk/functions/session/adodb-cryptsession.php trunk/functions/session/adodb-encrypt-mcrypt.php trunk/functions/session/adodb-encrypt-md5.php trunk/functions/session/adodb-encrypt-ordcrypt.php trunk/functions/session/adodb-encrypt-secret.php trunk/functions/session/adodb-encrypt-sha1.php trunk/functions/session/adodb-session.php trunk/functions/session/adodb-sessions.mysql.sql trunk/functions/session/session_schema.xml trunk/functions/tests/ trunk/functions/tests/adodblite_thumb.jpg trunk/functions/tests/pj trunk/functions/tests/test_adodb_lite.php trunk/functions/tests/test_adodb_lite_sessions.php trunk/functions/tests/test_datadictionary.php trunk/functions/tests/xmlschema.xml trunk/functions/tohtml.inc.php trunk/functions/xmlschema.dtd Added: trunk/functions/adodb-datadict.inc.php =================================================================== --- trunk/functions/adodb-datadict.inc.php (rev 0) +++ trunk/functions/adodb-datadict.inc.php 2007-07-30 04:57:52 UTC (rev 38) @@ -0,0 +1,838 @@ +<?php + +/** + V4.65 22 July 2005 (c) 2000-2005 John Lim (jl...@na...). All rights reserved. + Released under both BSD license and Lesser GPL library license. + Whenever there is any discrepancy between the two licenses, + the BSD license will take precedence. + + Set tabs to 4 for best viewing. + + DOCUMENTATION: + + See adodb/tests/test-datadict.php for docs and examples. + + Modified 3 October, 2005 for use with ADOdb Lite by Mark Dickenson +*/ + +/* + Test script for parser +*/ + +// security - hide paths +if (!defined('ADODB_DIR')) die(); + +if (!function_exists('ctype_alnum')) { + function ctype_alnum($text) { + return preg_match('/^[a-z0-9]*$/i', $text); + } +} + +function _array_change_key_case($an_array) +{ + if (is_array($an_array)) { + $new_array = array(); + foreach($an_array as $key=>$value) + $new_array[strtoupper($key)] = $value; + + return $new_array; + } + + return $an_array; +} + +/** + Parse arguments, treat "text" (text) and 'text' as quotation marks. + To escape, use "" or '' or )) + + Will read in "abc def" sans quotes, as: abc def + Same with 'abc def'. + However if `abc def`, then will read in as `abc def` + + @param endstmtchar Character that indicates end of statement + @param tokenchars Include the following characters in tokens apart from A-Z and 0-9 + @returns 2 dimensional array containing parsed tokens. +*/ +function Lens_ParseArgs($args,$endstmtchar=',',$tokenchars='_.-') +{ + $pos = 0; + $intoken = false; + $stmtno = 0; + $endquote = false; + $tokens = array(); + $tokens[$stmtno] = array(); + $max = strlen($args); + $quoted = false; + + while ($pos < $max) { + $ch = substr($args,$pos,1); + switch($ch) { + case ' ': + case "\t": + case "\n": + case "\r": + if (!$quoted) { + if ($intoken) { + $intoken = false; + $tokens[$stmtno][] = implode('',$tokarr); + } + break; + } + $tokarr[] = $ch; + break; + case '`': + if ($intoken) $tokarr[] = $ch; + case '(': + case ')': + case '"': + case "'": + if ($intoken) { + if (empty($endquote)) { + $tokens[$stmtno][] = implode('',$tokarr); + if ($ch == '(') $endquote = ')'; + else $endquote = $ch; + $quoted = true; + $intoken = true; + $tokarr = array(); + } else if ($endquote == $ch) { + $ch2 = substr($args,$pos+1,1); + if ($ch2 == $endquote) { + $pos += 1; + $tokarr[] = $ch2; + } else { + $quoted = false; + $intoken = false; + $tokens[$stmtno][] = implode('',$tokarr); + $endquote = ''; + } + } else + $tokarr[] = $ch; + }else { + if ($ch == '(') $endquote = ')'; + else $endquote = $ch; + $quoted = true; + $intoken = true; + $tokarr = array(); + if ($ch == '`') $tokarr[] = '`'; + } + break; + default: + if (!$intoken) { + if ($ch == $endstmtchar) { + $stmtno += 1; + $tokens[$stmtno] = array(); + break; + } + $intoken = true; + $quoted = false; + $endquote = false; + $tokarr = array(); + } + if ($quoted) $tokarr[] = $ch; + else if (ctype_alnum($ch) || strpos($tokenchars,$ch) !== false) $tokarr[] = $ch; + else { + if ($ch == $endstmtchar) { + $tokens[$stmtno][] = implode('',$tokarr); + $stmtno += 1; + $tokens[$stmtno] = array(); + $intoken = false; + $tokarr = array(); + break; + } + $tokens[$stmtno][] = implode('',$tokarr); + $tokens[$stmtno][] = $ch; + $intoken = false; + } + } + $pos += 1; + } + if ($intoken) $tokens[$stmtno][] = implode('',$tokarr); + + return $tokens; +} + + +class ADODB_DataDict { + var $connection; + var $debug = false; + var $dropTable = 'DROP TABLE %s'; + var $renameTable = 'RENAME TABLE %s TO %s'; + var $dropIndex = 'DROP INDEX %s'; + var $addCol = ' ADD'; + var $alterCol = ' ALTER COLUMN'; + var $dropCol = ' DROP COLUMN'; + var $renameColumn = 'ALTER TABLE %s RENAME COLUMN %s TO %s'; // table, old-column, new-column, column-definitions (not used by default) + var $nameRegex = '\w'; + var $nameRegexBrackets = 'a-zA-Z0-9_\(\)'; + var $schema = false; + var $serverInfo = array(); + var $autoIncrement = false; + var $invalidResizeTypes4 = array('CLOB','BLOB','TEXT','DATE','TIME'); // for changetablesql + var $blobSize = 100; /// any varchar/char field this size or greater is treated as a blob + /// in other words, we use a text area for editting. + var $metaTablesSQL; + var $metaColumnsSQL; + var $debug_echo = true; + var $fetchMode; + var $raiseErrorFn; + + function SetFetchMode($mode) + { + GLOBAL $ADODB_FETCH_MODE; + $old = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = $mode; + return $old; + } + + function outp($text) + { + $this->debug_output = "<br>\n(" . $this->dbtype . "): ".htmlspecialchars($text)."<br>\n"; + if($this->debug_echo) + echo $this->debug_output; + } + + function GetCommentSQL($table,$col) + { + return false; + } + + function SetCommentSQL($table,$col,$cmt) + { + return false; + } + + /** + * @param ttype can either be 'VIEW' or 'TABLE' or false. + * If false, both views and tables are returned. + * "VIEW" returns only views + * "TABLE" returns only tables + * @param showSchema returns the schema/user with the table name, eg. USER.TABLE + * @param mask is the input mask - only supported by oci8 and postgresql + * + * @return array of tables for current database. + */ + + function MetaTables() + { + if (!$this->connection->IsConnected()) return array(); + return $this->connection->MetaTables(); + } + + /** + * List columns in a database as an array of ADOFieldObjects. + * See top of file for definition of object. + * + * @param table table name to query + * @param upper uppercase table name (required by some databases) + * @schema is optional database schema to use - not supported by all databases. + * + * @return array of ADOFieldObjects for current table. + */ + + function MetaColumns($tab, $upper=true, $schema=false) + { + if (!$this->connection->IsConnected()) return array(); + return $this->connection->MetaColumns($this->TableName($tab), $upper, $schema); + } + + /** + * @returns an array with the primary key columns in it. + */ + + function MetaPrimaryKeys($tab,$owner=false,$intkey=false) + { + if (!$this->connection->IsConnected()) return array(); + return $this->connection->MetaPrimaryKeys($this->TableName($tab), $owner, $intkey); + } + + /** + * List indexes on a table as an array. + * @param table table name to query + * @param primary true to only show primary keys. Not actually used for most databases + * + * @return array of indexes on current table. Each element represents an index, and is itself an associative array. + + Array ( + [name_of_index] => Array + ( + [unique] => true or false + [columns] => Array + ( + [0] => firstname + [1] => lastname + ) + ) + */ + + function MetaIndexes($table, $primary = false, $owner = false) + { + if (!$this->connection->IsConnected()) return array(); + return $this->connection->MetaIndexes($this->TableName($table), $primary, $owner); + } + + function MetaType($t,$len=-1,$fieldobj=false) + { + return $this->connection->MetaType($t,$len,$fieldobj); + } + + function ActualType($meta) + { + return $meta; + } + + function NameQuote($name = NULL,$allowBrackets=false) + { + if (!is_string($name)) { + return FALSE; + } + + $name = trim($name); + + if ( !is_object($this->connection) ) { + return $name; + } + + $quote = $this->connection->nameQuote; + + // if name is of the form `name`, quote it + if ( preg_match('/^`(.+)`$/', $name, $matches) ) { + return $quote . $matches[1] . $quote; + } + + // if name contains special characters, quote it + $regex = ($allowBrackets) ? $this->nameRegexBrackets : $this->nameRegex; + + if ( !preg_match('/^[' . $regex . ']+$/', $name) ) { + return $quote . $name . $quote; + } + + return $name; + } + + function TableName($name) + { + if ( $this->schema ) { + return $this->NameQuote($this->schema) .'.'. $this->NameQuote($name); + } + return $this->NameQuote($name); + } + + // Executes the sql array returned by GetTableSQL and GetIndexSQL + function ExecuteSQLArray($sql, $continueOnError = true) + { + $rez = 2; + $conn = &$this->connection; + $saved = $conn->debug; + foreach($sql as $line) { + if ($this->debug) $conn->debug = true; + $ok = $conn->Execute($line); + $conn->debug = $saved; + if (!$ok) { + if ($this->debug) $this->outp($conn->ErrorMsg()); + if (!$continueOnError) return 0; + $rez = 1; + } + } + return $rez; + } + + function CreateDatabase($dbname,$options=false) + { + $options = $this->_Options($options); + $sql = array(); + + $s = 'CREATE DATABASE ' . $this->NameQuote($dbname); + if (isset($options[$this->upperName])) + $s .= ' '.$options[$this->upperName]; + + $sql[] = $s; + return $sql; + } + + /* + Generates the SQL to create index. Returns an array of sql strings. + */ + + function CreateIndexSQL($idxname, $tabname, $flds, $idxoptions = false) + { + if (!is_array($flds)) { + $flds = explode(',',$flds); + } + foreach($flds as $key => $fld) { + # some indexes can use partial fields, eg. index first 32 chars of "name" with NAME(32) + $flds[$key] = $this->NameQuote($fld,$allowBrackets=true); + } + return $this->_IndexSQL($this->NameQuote($idxname), $this->TableName($tabname), $flds, $this->_Options($idxoptions)); + } + + function DropIndexSQL ($idxname, $tabname = NULL) + { + return array(sprintf($this->dropIndex, $this->NameQuote($idxname), $this->TableName($tabname))); + } + + function SetSchema($schema) + { + $this->schema = $schema; + } + + function AddColumnSQL($tabname, $flds) + { + $tabname = $this->TableName ($tabname); + $sql = array(); + list($lines,$pkey) = $this->_GenFields($flds); + $alter = 'ALTER TABLE ' . $tabname . $this->addCol . ' '; + foreach($lines as $v) { + $sql[] = $alter . $v; + } + return $sql; + } + + /** + * Change the definition of one column + * + * As some DBM's can't do that on there own, you need to supply the complete defintion of the new table, + * to allow, recreating the table and copying the content over to the new table + * @param string $tabname table-name + * @param string $flds column-name and type for the changed column + * @param string $tableflds='' complete defintion of the new table, eg. for postgres, default '' + * @param array/string $tableoptions='' options for the new table see CreateTableSQL, default '' + * @return array with SQL strings + */ + + function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + { + $tabname = $this->TableName ($tabname); + $sql = array(); + list($lines,$pkey) = $this->_GenFields($flds); + $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; + foreach($lines as $v) { + $sql[] = $alter . $v; + } + return $sql; + } + + /** + * Rename one column + * + * Some DBM's can only do this together with changeing the type of the column (even if that stays the same, eg. mysql) + * @param string $tabname table-name + * @param string $oldcolumn column-name to be renamed + * @param string $newcolumn new column-name + * @param string $flds='' complete column-defintion-string like for AddColumnSQL, only used by mysql atm., default='' + * @return array with SQL strings + */ + + function RenameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='') + { + $tabname = $this->TableName ($tabname); + if ($flds) { + list($lines,$pkey) = $this->_GenFields($flds); + list(,$first) = each($lines); + list(,$column_def) = split("[\t ]+",$first,2); + } + return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def)); + } + + /** + * Drop one column + * + * Some DBM's can't do that on there own, you need to supply the complete defintion of the new table, + * to allow, recreating the table and copying the content over to the new table + * @param string $tabname table-name + * @param string $flds column-name and type for the changed column + * @param string $tableflds='' complete defintion of the new table, eg. for postgres, default '' + * @param array/string $tableoptions='' options for the new table see CreateTableSQL, default '' + * @return array with SQL strings + */ + + function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') + { + $tabname = $this->TableName ($tabname); + if (!is_array($flds)) $flds = explode(',',$flds); + $sql = array(); + $alter = 'ALTER TABLE ' . $tabname . $this->dropCol . ' '; + foreach($flds as $v) { + $sql[] = $alter . $this->NameQuote($v); + } + return $sql; + } + + function DropTableSQL($tabname) + { + return array (sprintf($this->dropTable, $this->TableName($tabname))); + } + + function RenameTableSQL($tabname,$newname) + { + return array (sprintf($this->renameTable, $this->TableName($tabname),$this->TableName($newname))); + } + + /* + Generate the SQL to create table. Returns an array of sql strings. + */ + + function CreateTableSQL($tabname, $flds, $tableoptions=false) + { + if (!$tableoptions) $tableoptions = array(); + + list($lines,$pkey) = $this->_GenFields($flds, true); + + $taboptions = $this->_Options($tableoptions); + $tabname = $this->TableName ($tabname); + $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions); + $tsql = $this->_Triggers($tabname,$taboptions); + foreach($tsql as $s) $sql[] = $s; + + return $sql; + } + + function _GenFields($flds,$widespacing=false) + { + if (is_string($flds)) { + $padding = ' '; + $txt = $flds.$padding; + $flds = array(); + $flds0 = Lens_ParseArgs($txt,','); + $hasparam = false; + foreach($flds0 as $f0) { + $f1 = array(); + foreach($f0 as $token) { + switch (strtoupper($token)) { + case 'CONSTRAINT': + case 'DEFAULT': + $hasparam = $token; + break; + default: + if ($hasparam) $f1[$hasparam] = $token; + else $f1[] = $token; + $hasparam = false; + break; + } + } + $flds[] = $f1; + + } + } + $this->autoIncrement = false; + $lines = array(); + $pkey = array(); + foreach($flds as $fld) { + $fld = _array_change_key_case($fld); + $fname = false; + $fdefault = false; + $fautoinc = false; + $ftype = false; + $fsize = false; + $fprec = false; + $fprimary = false; + $fnoquote = false; + $fdefts = false; + $fdefdate = false; + $fconstraint = false; + $fnotnull = false; + $funsigned = false; + + //----------------- + // Parse attributes + foreach($fld as $attr => $v) { + if ($attr == 2 && is_numeric($v)) $attr = 'SIZE'; + else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v); + switch($attr) { + case '0': + case 'NAME': + $fname = $v; + break; + case '1': + case 'TYPE': + $ty = $v; $ftype = $this->ActualType(strtoupper($v)); + break; + case 'SIZE': + $dotat = strpos($v,'.'); + if ($dotat === false) $dotat = strpos($v,','); + if ($dotat === false) $fsize = $v; + else { + $fsize = substr($v,0,$dotat); + $fprec = substr($v,$dotat+1); + } + break; + case 'UNSIGNED': + $funsigned = true; + break; + case 'AUTOINCREMENT': + case 'AUTO': + $fautoinc = true; + $fnotnull = true; + break; + case 'KEY': + case 'PRIMARY': + $fprimary = $v; + $fnotnull = true; + break; + case 'DEF': + case 'DEFAULT': + $fdefault = $v; + break; + case 'NOTNULL': + $fnotnull = $v; + break; + case 'NOQUOTE': + $fnoquote = $v; + break; + case 'DEFDATE': + $fdefdate = $v; + break; + case 'DEFTIMESTAMP': + $fdefts = $v; + break; + case 'CONSTRAINT': + $fconstraint = $v; + break; + } + } + + //-------------------- + // VALIDATE FIELD INFO + if (!strlen($fname)) { + if ($this->debug) $this->outp("Undefined NAME"); + return false; + } + + $fid = strtoupper(preg_replace('/^`(.+)`$/', '$1', $fname)); + $fname = $this->NameQuote($fname); + + if (!strlen($ftype)) { + if ($this->debug) $this->outp("Undefined TYPE for field '$fname'"); + return false; + } else { + $ftype = strtoupper($ftype); + } + + $ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec); + + if ($ty == 'X' || $ty == 'X2' || $ty == 'B') $fnotnull = false; // some blob types do not accept nulls + + if ($fprimary) $pkey[] = $fname; + + // some databases do not allow blobs to have defaults + if ($ty == 'X') $fdefault = false; + + //-------------------- + // CONSTRUCT FIELD SQL + if ($fdefts) { + if (substr($this->dbtype,0,5) == 'mysql') { + $ftype = 'TIMESTAMP'; + } else { + $fdefault = $this->connection->sysTimeStamp; + } + } else if ($fdefdate) { + if (substr($this->dbtype,0,5) == 'mysql') { + $ftype = 'TIMESTAMP'; + } else { + $fdefault = $this->connection->sysDate; + } + } else if ($fdefault !== false && !$fnoquote) + if ($ty == 'C' or $ty == 'X' or + ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault))) + if (strlen($fdefault) != 1 && substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ') + $fdefault = trim($fdefault); + else if (strtolower($fdefault) != 'null') + $fdefault = $this->connection->qstr($fdefault); + $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned); + + if ($widespacing) $fname = str_pad($fname,24); + $lines[$fid] = $fname.' '.$ftype.$suffix; + + if ($fautoinc) $this->autoIncrement = true; + } // foreach $flds + return array($lines,$pkey); + } + + /* + GENERATE THE SIZE PART OF THE DATATYPE + $ftype is the actual type + $ty is the type defined originally in the DDL + */ + + function _GetSize($ftype, $ty, $fsize, $fprec) + { + if (strlen($fsize) && $ty != 'X' && $ty != 'B' && strpos($ftype,'(') === false) { + $ftype .= "(".$fsize; + if (strlen($fprec)) $ftype .= ",".$fprec; + $ftype .= ')'; + } + return $ftype; + } + + // return string must begin with space + function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint) + { + $suffix = ''; + if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; + if ($fnotnull) $suffix .= ' NOT NULL'; + if ($fconstraint) $suffix .= ' '.$fconstraint; + return $suffix; + } + + function _IndexSQL($idxname, $tabname, $flds, $idxoptions) + { + $sql = array(); + + if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) { + $sql[] = sprintf ($this->dropIndex, $idxname); + if ( isset($idxoptions['DROP']) ) + return $sql; + } + + if ( empty ($flds) ) { + return $sql; + } + + $unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : ''; + + $s = 'CREATE' . $unique . ' INDEX ' . $idxname . ' ON ' . $tabname . ' '; + + if ( isset($idxoptions[$this->upperName]) ) + $s .= $idxoptions[$this->upperName]; + + if ( is_array($flds) ) + $flds = implode(', ',$flds); + $s .= '(' . $flds . ')'; + $sql[] = $s; + + return $sql; + } + + function _DropAutoIncrement($tabname) + { + return false; + } + + function _TableSQL($tabname,$lines,$pkey,$tableoptions) + { + $sql = array(); + + if (isset($tableoptions['REPLACE']) || isset ($tableoptions['DROP'])) { + $sql[] = sprintf($this->dropTable,$tabname); + if ($this->autoIncrement) { + $sInc = $this->_DropAutoIncrement($tabname); + if ($sInc) $sql[] = $sInc; + } + if ( isset ($tableoptions['DROP']) ) { + return $sql; + } + } + $s = "CREATE TABLE $tabname (\n"; + $s .= implode(",\n", $lines); + if (sizeof($pkey)>0) { + $s .= ",\n PRIMARY KEY ("; + $s .= implode(", ",$pkey).")"; + } + if (isset($tableoptions['CONSTRAINTS'])) + $s .= "\n".$tableoptions['CONSTRAINTS']; + + if (isset($tableoptions[$this->upperName.'_CONSTRAINTS'])) + $s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS']; + + $s .= "\n)"; + if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName]; + $sql[] = $s; + + return $sql; + } + + /* + GENERATE TRIGGERS IF NEEDED + used when table has auto-incrementing field that is emulated using triggers + */ + + function _Triggers($tabname,$taboptions) + { + return array(); + } + + /* + Sanitize options, so that array elements with no keys are promoted to keys + */ + + function _Options($opts) + { + if (!is_array($opts)) return array(); + $newopts = array(); + foreach($opts as $k => $v) { + if (is_numeric($k)) $newopts[strtoupper($v)] = $v; + else $newopts[strtoupper($k)] = $v; + } + return $newopts; + } + + /* + "Florian Buzin [ easywe ]" <florian.buzin#easywe.de> + + This function changes/adds new fields to your table. You don't + have to know if the col is new or not. It will check on its own. + */ + + function ChangeTableSQL($tablename, $flds, $tableoptions = false) + { + global $ADODB_FETCH_MODE; + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; + if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false); + + // check table exists + $save_handler = $this->raiseErrorFn; + $this->raiseErrorFn = ''; + $cols = $this->MetaColumns($tablename); + $this->raiseErrorFn = $save_handler; + + if (isset($savem)) $this->SetFetchMode($savem); + $ADODB_FETCH_MODE = $save; + + if ( empty($cols)) { + return $this->CreateTableSQL($tablename, $flds, $tableoptions); + } + + if (is_array($flds)) { + // Cycle through the update fields, comparing + // existing fields to fields to update. + // if the Metatype and size is exactly the + // same, ignore - by Mark Newham + $holdflds = array(); + foreach($flds as $k=>$v) { + if ( isset($cols[$k]) && is_object($cols[$k]) ) { + $c = $cols[$k]; + $ml = $c->max_length; + $mt = &$this->MetaType($c->type,$ml); + if ($ml == -1) $ml = ''; + if ($mt == 'X') $ml = $v['SIZE']; + if (($mt != $v['TYPE']) || $ml != $v['SIZE']) { + $holdflds[$k] = $v; + } + } else { + $holdflds[$k] = $v; + } + } + $flds = $holdflds; + } + + // already exists, alter table instead + list($lines,$pkey) = $this->_GenFields($flds); + $alter = 'ALTER TABLE ' . $this->TableName($tablename); + $sql = array(); + + foreach ( $lines as $id => $v ) { + if ( isset($cols[$id]) && is_object($cols[$id]) ) { + $flds = Lens_ParseArgs($v,','); + // We are trying to change the size of the field, if not allowed, simply ignore the request. + if ($flds && in_array(strtoupper(substr($flds[0][1],0,4)),$this->invalidResizeTypes4)) continue; + + $sql[] = $alter . $this->alterCol . ' ' . $v; + } else { + $sql[] = $alter . $this->addCol . ' ' . $v; + } + } + return $sql; + } +} + +?> \ No newline at end of file Added: trunk/functions/adodb-error.inc.php =================================================================== --- trunk/functions/adodb-error.inc.php (rev 0) +++ trunk/functions/adodb-error.inc.php 2007-07-30 04:57:52 UTC (rev 38) @@ -0,0 +1,277 @@ +<?php +/** + * @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. + * Released under both BSD license and Lesser GPL library license. + * Whenever there is any discrepancy between the two licenses, + * the BSD license will take precedence. + * + * Set tabs to 4 for best viewing. + * + * The following code is adapted from the PEAR DB error handling code. + * Portions (c)1997-2002 The PHP Group. + */ + + +if (!defined("DB_ERROR")) define("DB_ERROR",-1); + +if (!defined("DB_ERROR_SYNTAX")) { + 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_NOSUCHDB", -25); + define("DB_ERROR_ACCESS_VIOLATION", -26); +} + +function adodb_errormsg($value) +{ + global $ADODB_LANG,$ADODB_LANG_ARRAY; + + if (empty($ADODB_LANG)) + $ADODB_LANG = 'en'; + if (isset($ADODB_LANG_ARRAY['LANG']) && $ADODB_LANG_ARRAY['LANG'] == $ADODB_LANG) ; + else + { + include_once(ADODB_DIR."/lang/adodb-$ADODB_LANG.inc.php"); + } + return isset($ADODB_LANG_ARRAY[$value]) ? $ADODB_LANG_ARRAY[$value] : $ADODB_LANG_ARRAY[DB_ERROR]; +} + +function adodb_error($provider,$dbType,$errno) +{ + //var_dump($errno); + if (is_numeric($errno) && $errno == 0) + return 0; + + switch($provider) { + case 'mysql': + $map = adodb_error_mysql(); + break; + + case 'oracle': + case 'oci8': + $map = adodb_error_oci8(); + break; + + case 'ibase': + $map = adodb_error_ibase(); + break; + + case 'odbc': + $map = adodb_error_odbc(); + break; + + case 'mssql': + case 'sybase': + $map = adodb_error_mssql(); + break; + + case 'informix': + $map = adodb_error_ifx(); + break; + + case 'postgres': + return adodb_error_pg($errno); + break; + + case 'sqlite': + return $map = adodb_error_sqlite(); + break; + default: + return DB_ERROR; + } + //print_r($map); + //var_dump($errno); + if (isset($map[$errno])) + return $map[$errno]; + return DB_ERROR; +} + +//************************************************************************************** + +function adodb_error_pg($errormsg) +{ + if (is_numeric($errormsg)) + return (integer) $errormsg; + + static $error_regexps = array( + '/(Table does not exist\.|Relation [\"\'].*[\"\'] does not exist|sequence does not exist|class ".+" not found)$/' => DB_ERROR_NOSUCHTABLE, + '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*/' => DB_ERROR_ALREADY_EXISTS, + '/divide by zero$/' => DB_ERROR_DIVZERO, + '/pg_atoi: error in .*: can\'t parse /' => DB_ERROR_INVALID_NUMBER, + '/ttribute [\"\'].*[\"\'] not found|Relation [\"\'].*[\"\'] does not have attribute [\"\'].*[\"\']/' => DB_ERROR_NOSUCHFIELD, + '/parser: parse error at or near \"/' => DB_ERROR_SYNTAX, + '/referential integrity violation/' => DB_ERROR_CONSTRAINT, + '/Relation [\"\'].*[\"\'] already exists|Cannot insert a duplicate key into (a )?unique index.*|duplicate key violates unique constraint/' + => DB_ERROR_ALREADY_EXISTS + ); + reset($error_regexps); + while (list($regexp,$code) = each($error_regexps)) + { + if (preg_match($regexp, $errormsg)) + { + return $code; + } + } + // Fall back to DB_ERROR if there was no mapping. + return DB_ERROR; +} + +function adodb_error_odbc() +{ + static $MAP = array( + '01004' => DB_ERROR_TRUNCATED, + '07001' => DB_ERROR_MISMATCH, + '21S01' => DB_ERROR_MISMATCH, + '21S02' => DB_ERROR_MISMATCH, + '22003' => DB_ERROR_INVALID_NUMBER, + '22008' => DB_ERROR_INVALID_DATE, + '22012' => DB_ERROR_DIVZERO, + '23000' => DB_ERROR_CONSTRAINT, + '24000' => DB_ERROR_INVALID, + '34000' => DB_ERROR_INVALID, + '37000' => DB_ERROR_SYNTAX, + '42000' => DB_ERROR_SYNTAX, + 'IM001' => DB_ERROR_UNSUPPORTED, + 'S0000' => DB_ERROR_NOSUCHTABLE, + 'S0001' => DB_ERROR_NOT_FOUND, + 'S0002' => DB_ERROR_NOSUCHTABLE, + 'S0011' => DB_ERROR_ALREADY_EXISTS, + 'S0012' => DB_ERROR_NOT_FOUND, + 'S0021' => DB_ERROR_ALREADY_EXISTS, + 'S0022' => DB_ERROR_NOT_FOUND, + 'S1000' => DB_ERROR_NOSUCHTABLE, + 'S1009' => DB_ERROR_INVALID, + 'S1090' => DB_ERROR_INVALID, + 'S1C00' => DB_ERROR_NOT_CAPABLE + ); + return $MAP; +} + +function adodb_error_ibase() +{ + static $MAP = array( + -104 => DB_ERROR_SYNTAX, + -150 => DB_ERROR_ACCESS_VIOLATION, + -151 => DB_ERROR_ACCESS_VIOLATION, + -155 => 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, + -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 + ); + return $MAP; +} + +function adodb_error_ifx() +{ + static $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 + ); + return $MAP; +} + +function adodb_error_oci8() +{ + static $MAP = array( + 1 => DB_ERROR_ALREADY_EXISTS, + 900 => DB_ERROR_SYNTAX, + 904 => DB_ERROR_NOSUCHFIELD, + 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 + ); + return $MAP; +} + +function adodb_error_mssql() +{ + static $MAP = array( + 208 => DB_ERROR_NOSUCHTABLE, + 2601 => DB_ERROR_ALREADY_EXISTS + ); + return $MAP; +} + +function adodb_error_sqlite() +{ + static $MAP = array( + 1 => DB_ERROR_SYNTAX + ); + return $MAP; +} + +function adodb_error_mysql() +{ + static $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, + 1045 => DB_ERROR_ACCESS_VIOLATION, + 1046 => DB_ERROR_NODBSELECTED, + 1049 => DB_ERROR_NOSUCHDB, + 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, + 2002 => DB_ERROR_CONNECT_FAILED, + 2005 => DB_ERROR_CONNECT_FAILED + ); + return $MAP; +} +?> \ No newline at end of file Added: trunk/functions/adodb-errorhandler.inc.php =================================================================== --- trunk/functions/adodb-errorhandler.inc.php (rev 0) +++ trunk/functions/adodb-errorhandler.inc.php 2007-07-30 04:57:52 UTC (rev 38) @@ -0,0 +1,79 @@ +<?php +/** + * @version V4.66 28 Sept 2005 (c) 2000-2005 John Lim (jl...@na...). All rights reserved. + * Released under both BSD license and Lesser GPL library license. + * Whenever there is any discrepancy between the two licenses, + * the BSD license will take precedence. + * + * Set tabs to 4 for best viewing. + * + * Latest version is available at http://php.weblogs.com + * +*/ + +// added Claudio Bustos clbustos#entelchile.net +if (!defined('ADODB_ERROR_HANDLER_TYPE')) define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR); + +if (!defined('ADODB_ERROR_HANDLER')) define('ADODB_ERROR_HANDLER','ADODB_Error_Handler'); + +/** +* Default Error Handler. This will be called with the following params +* +* @param $dbms the RDBMS you are connecting to +* @param $fn the name of the calling function (in uppercase) +* @param $errno the native error number from the database +* @param $errmsg the native error msg from the database +* @param $p1 $fn specific parameter - see below +* @param $p2 $fn specific parameter - see below +* @param $thisConn $current connection object - can be false if no connection object created +*/ + +function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) +{ + if (error_reporting() == 0) + return; // obey @ protocol + + switch($fn) { + case 'EXECUTE': + $sql = $p1; + $inputparams = $p2; + $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")\n"; + break; + + case 'PCONNECT': + case 'CONNECT': + $host = $p1; + $database = $p2; + $s = "$dbms error: [$errno: $errmsg] in $fn($host, '****', '****', $database)\n"; + break; + + default: + $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n"; + break; + } + /* + * Log connection error somewhere + * 0 message is sent to PHP's system logger, using the Operating System's system + * logging mechanism or a file, depending on what the error_log configuration + * directive is set to. + * 1 message is sent by email to the address in the destination parameter. + * This is the only message type where the fourth parameter, extra_headers is used. + * This message type uses the same internal function as mail() does. + * 2 message is sent through the PHP debugging connection. + * This option is only available if remote debugging has been enabled. + * In this case, the destination parameter specifies the host name or IP address + * and optionally, port number, of the socket receiving the debug information. + * 3 message is appended to the file destination + */ + if (defined('ADODB_ERROR_LOG_TYPE')) { + $t = date('Y-m-d H:i:s'); + if (defined('ADODB_ERROR_LOG_DEST')) + error_log("($t) $s", ADODB_ERROR_LOG_TYPE, ADODB_ERROR_LOG_DEST); + else + error_log("($t) $s", ADODB_ERROR_LOG_TYPE); + } + + //print "<p>$s</p>"; + trigger_error($s, ADODB_ERROR_HANDLER_TYPE); +} +?> Added: trunk/functions/adodb-errorpear.inc.php =================================================================== --- trunk/functions/adodb-errorpear.inc.php (rev 0) +++ trunk/functions/adodb-errorpear.inc.php 2007-07-30 04:57:52 UTC (rev 38) @@ -0,0 +1,87 @@ +<?php +/** + * @version V4.66 28 Sept 2005 (c) 2000-2005 John Lim (jl...@na...). All rights reserved. + * Released under both BSD license and Lesser GPL library license. + * Whenever there is any discrepancy between the two licenses, + * the BSD license will take precedence. + * + * Set tabs to 4 for best viewing. + * + * Latest version is available at http://php.weblogs.com + * +*/ +include_once('PEAR.php'); + +if (!defined('ADODB_ERROR_HANDLER')) + define('ADODB_ERROR_HANDLER','ADODB_Error_PEAR'); + +/* +* Enabled the following if you want to terminate scripts when an error occurs +*/ +//PEAR::setErrorHandling (PEAR_ERROR_DIE); + +/* +* Name of the PEAR_Error derived class to call. +*/ +if (!defined('ADODB_PEAR_ERROR_CLASS')) + define('ADODB_PEAR_ERROR_CLASS','PEAR_Error'); + +/* +* Store the last PEAR_Error object here +*/ +global $ADODB_Last_PEAR_Error; + +$ADODB_Last_PEAR_Error = false; + + /** +* Error Handler with PEAR support. This will be called with the following params +* +* @param $dbms the RDBMS you are connecting to +* @param $fn the name of the calling function (in uppercase) +* @param $errno the native error number from the database +* @param $errmsg the native error msg from the database +* @param $p1 $fn specific parameter - see below +* @param $P2 $fn specific parameter - see below + */ +function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1=false, $p2=false) +{ + global $ADODB_Last_PEAR_Error; + + if (error_reporting() == 0) + return; // obey @ protocol + + switch($fn) { + case 'EXECUTE': + $sql = $p1; + $inputparams = $p2; + $s = "$dbms error: [$errno: $errmsg] in $fn(\"$sql\")"; + break; + + case 'PCONNECT': + case 'CONNECT': + $host = $p1; + $database = $p2; + $s = "$dbms error: [$errno: $errmsg] in $fn('$host', ?, ?, '$database')"; + break; + + default: + $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)"; + break; + } + + $class = ADODB_PEAR_ERROR_CLASS; + $ADODB_Last_PEAR_Error = new $class($s, $errno, $GLOBALS['_PEAR_default_error_mode'], $GLOBALS['_PEAR_default_error_options'], $errmsg); + //print "<p>!$s</p>"; +} + +/** +* Returns last PEAR_Error object. This error might be for an error that +* occured several sql statements ago. +*/ +function &ADODB_PEAR_Error() +{ + global $ADODB_Last_PEAR_Error; + + return $ADODB_Last_PEAR_Error; +} +?> \ No newline at end of file Added: trunk/functions/adodb-exceptions.inc.php =================================================================== --- trunk/functions/adodb-exceptions.inc.php (rev 0) +++ trunk/functions/adodb-exceptions.inc.php 2007-07-30 04:57:52 UTC (rev 38) @@ -0,0 +1,86 @@ +<?php + +/** + * @version V4.66 28 Sept 2005 (c) 2000-2005 John Lim (jl...@na...). All rights reserved. + * Released under both BSD license and Lesser GPL library license. + * Whenever there is any discrepancy between the two licenses, + * the BSD license will take precedence. + * + * Set tabs to 4 for best viewing. + * + * Latest version is available at http://php.weblogs.com + * + * Exception-handling code using PHP5 exceptions (try-catch-throw). + */ + +if (!defined('ADODB_ERROR_HANDLER_TYPE')) + define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR); + +define('ADODB_ERROR_HANDLER','adodb_throw'); + +class ADODB_Exception extends Exception { + var $dbms; + var $fn; + var $sql = ''; + var $params = ''; + var $host = ''; + var $database = ''; + + function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) + { + switch($fn) { + case 'EXECUTE': + $this->sql = $p1; + $this->params = $p2; + $s = "$dbms error: [$errno: $errmsg] in $fn(\"$p1\")\n"; + break; + + case 'PCONNECT': + case 'CONNECT': + $user = $thisConnection->username; + $s = "$dbms error: [$errno: $errmsg] in $fn($p1, '$user', '****', $p2)\n"; + break; + + default: + $s = "$dbms error: [$errno: $errmsg] in $fn($p1, $p2)\n"; + break; + } + + $this->dbms = $dbms; + $this->host = $thisConnection->host; + $this->database = $thisConnection->database; + $this->fn = $fn; + $this->msg = $errmsg; + + if (!is_numeric($errno)) + $errno = -1; + + parent::__construct($s,$errno); + } +} + +/** +* Default Error Handler. This will be called with the following params +* +* @param $dbms the RDBMS you are connecting to +* @param $fn the name of the calling function (in uppercase) +* @param $errno the native error number from the database +* @param $errmsg the native error msg from the database +* @param $p1 $fn specific parameter - see below +* @param $P2 $fn specific parameter - see below +*/ + +function adodb_throw($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) +{ + global $ADODB_EXCEPTION; + + if (error_reporting() == 0) + return; // obey @ protocol + + if (is_string($ADODB_EXCEPTION)) + $errfn = $ADODB_EXCEPTION; + else $errfn = 'ADODB_EXCEPTION'; + + throw new $errfn($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection); +} +?> \ No newline at end of file Added: trunk/functions/adodb-perf-module.inc.php =================================================================== --- trunk/functions/adodb-perf-module.inc.php (rev 0) +++ trunk/functions/adodb-perf-module.inc.php 2007-07-30 04:57:52 UTC (rev 38) @@ -0,0 +1,974 @@ +<?php +/* +V4.65 22 July 2005 (c) 2000-2005 John Lim (jl...@na...). All rights reserved. + Released under both BSD license and Lesser GPL library license. + Whenever there is any discrepancy between the two licenses, + the BSD license will take precedence. See License.txt. + + Library for basic performance monitoring and tuning. + + Modified 23 April 2006 for use with ADOdb Lite by Pádraic Brady + Such modifications as listed (c) 2006 Pádraic Brady (mau...@ho...) + + Modifications: + - Moved below methods from adodb_perf class to create a common parent from which all driver + specific perfmon modules will extend to prevent duplicate code. + - See specific driver module files for other changes + +*/ + +eval('class perfmon_parent_EXTENDER extends ' . $last_module . '_ADOConnection { }'); + +class perfmon_parent_ADOConnection extends perfmon_parent_EXTENDER +{ + + var $color = '#F0F0F0'; + var $table = '<table style="border: 2px groove #000000; background-color: #FFFFFF;">'; + var $titles = '<tr><td><strong>Parameter</strong></td><td><strong>Value</strong></td><td><strong>Description</strong></td></tr>'; + var $warnRatio = 90; + var $tablesSQL = false; + var $cliFormat = "%32s => %s \r\n"; + var $sql1 = 'sql1'; // used for casting sql1 to text for mssql + var $explain = true; + var $helpurl = '<a href="javascript:void();">LogSQL help</a>'; + var $createTableSQL = false; + var $maxLength = 2000; + var $settings = false; + var $_logsql = false; + var $_lastload; + + /** + * Sets the table name to use for SQL logging. Returns value of current table when called. + * Usage: perfmon_parent_ADOConnection::table('custom_log_sql'); + * $currentTable = perfmon_parent_ADOConnection::table(); + * + * @access public + * @param string $newtable The name for the table to use; optional. + * @return string + */ + function table($newtable = false) + { + static $_table; + if (!empty($newtable)) $_table = $newtable; + if (empty($_table)) $_table = 'adodb_logsql'; + return $_table; + } + + /** + * Enables SQL logging to database for Performance Monitor use. + * Usage: $oldValue = $db->LogSQL( $enable ); + * $enable is optional; defaults to TRUE enabling logging. FALSE disables logging. + * + * @access public + * @param bool $enable + * @return bool + */ + function LogSQL($enable=true) + { + $old = $this->_logsql; + $this->_logsql = $enable; + return $old; + } + + /** + * Returns an array with information to calculate CPU Load + * + * @access private + * @return mixed + */ + function _CPULoad() { + // Algorithm is taken from + // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp + if (strncmp(PHP_OS,'WIN',3)==0) + { + if (PHP_VERSION == '5.0.0') return false; + if (PHP_VERSION == '5.0.1') return false; + if (PHP_VERSION == '5.0.2') return false; + if (PHP_VERSION == '5.0.3') return false; + if (PHP_VERSION == '4.3.10') return false; # see http://bugs.php.net/bug.php?id=31737 + + @$c = new COM("WinMgmts:{impersonationLevel=impersonate}!Win32_PerfRawData_PerfOS_Processor.Name='_Total'"); + if (!$c) return false; + + $info[0] = $c->PercentProcessorTime; + $info[1] = 0; + $info[2] = 0; + $info[3] = $c->TimeStamp_Sys100NS; + return $info; + } + + // Algorithm - Steve Blinch (BlitzAffe Online, http://www.blitzaffe.com) + $statfile = '/proc/stat'; + if (!file_exists($statfile)) return false; + + $fd = fopen($statfile,"r"); + if (!$fd) return false; + + $statinfo = explode("\n",fgets($fd, 1024)); + fclose($fd); + foreach($statinfo as $line) + { + $info = explode(" ",$line); + if($info[0]=="cpu") + { + array_shift($info); // pop off "cpu" + if(!$info[0]) array_shift($info); // pop off blank space (if any) + return $info; + } + } + + return false; + } + + /* NOT IMPLEMENTED */ + function MemInfo() + { + + } + + + /** + * Returns CPU Load + * + * @access public + * @return mixed + */ + function CPULoad() + { + $info = $this->_CPULoad(); + if (!$info) return false; + + if (empty($this->_lastLoad)) + { + sleep(1); + $this->_lastLoad = $info; + $info = $this->_CPULoad(); + } + + $last = $this->_lastLoad; + $this->_lastLoad = $info; + + $d_user = $info[0] - $last[0]; + $d_nice = $info[1] - $last[1]; + $d_system = $info[2] - $last[2]; + $d_idle = $info[3] - $last[3]; + + if (strncmp(PHP_OS,'WIN',3)==0) + { + if ($d_idle < 1) $d_idle = 1; + return 100*(1-$d_user/$d_idle); + } + else + { + $total=$d_user+$d_nice+$d_system+$d_idle; + if ($total<1) $total=1; + return 100*($d_user+$d_nice+$d_system)/$total; + } + } + + function Tracer($sql) + { + $perf_table = perfmon_parent_ADOConnection::table(); + $saveE = $this->LogSQL(false); + + global $ADODB_FETCH_MODE; + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + $sqlq = $this->qstr($sql); + $arr = $this->GetArray( + "select count(*),tracer + from $perf_table where sql1=$sqlq + group by tracer + order by 1 desc" + ); + $s = ''; + if ($arr) + { + $s .= '\n<h3>Scripts Affected</h3>\n'; + foreach($arr as $k) + { + $s .= sprintf("%4d",$k[0]).' '.strip_tags($k[1]).'<br />'; + } + } + $this->LogSQL($saveE); + return $s; + } + + /* + Explain Plan for $sql. + If only a snippet of the $sql is passed in, then $partial will hold the crc32 of the + actual sql. + */ + function Explain($sql, $partial=false) + { + return false; + } + + function InvalidSQL($numsql = 10) + { + + if (isset($_GET['sql'])) return; + $s = '<h3>Invalid SQL</h3>'; + $saveE = $this->LogSQL(false); + $perf_table = perfmon_parent_ADOConnection::table(); + $rs =& $this->SelectLimit( + "select distinct count(*), sql1, tracer as error_msg + from $perf_table + where tracer like 'ERROR:%' + group by sql1, tracer + order by 1 desc" + ,$numsql + ); + $this->LogSQL($saveE); + if ($rs) + { + $s .= rs2html($rs,false,false,false,false); + } + else + { + return "\n<p>$this->helpurl. ".$this->ErrorMsg()."</p>\n"; + } + return $s; + } + + + /* + This script identifies the longest running SQL + */ + function _SuspiciousSQL($numsql = 10) + { + global $ADODB_FETCH_MODE; + + $perf_table = perfmon_parent_ADOConnection::table(); + $saveE = $this->LogSQL(false); + + if (isset($_GET['exps']) && isset($_GET['sql'])) + { + $partial = !empty($_GET['part']); + echo '<a name="explain"></a>' . $this->Explain($_GET['sql'], $partial) . "\n"; + } + + if (isset($_GET['sql'])) return; + $sql1 = $this->sql1; + + $save = $ADODB_FETCH_MODE; + $ADODB_FETCH_MODE = ADODB_FETCH_NUM; + + $rs =& $this->SelectLimit( + "select avg(timer) as avg_timer, $sql1, count(*), max(timer) as max_timer, min(timer) as min_timer + from $perf_table + where {$this->upperCase}({$this->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT') + and (tracer is null or tracer not l... [truncated message content] |