From: <var...@us...> - 2014-07-21 12:04:16
|
Revision: 8996 http://sourceforge.net/p/phpwiki/code/8996 Author: vargenau Date: 2014-07-21 12:04:00 +0000 (Mon, 21 Jul 2014) Log Message: ----------- Update adodb to adodb519 Modified Paths: -------------- trunk/lib/WikiDB/adodb/adodb-active-record.inc.php trunk/lib/WikiDB/adodb/adodb-active-recordx.inc.php trunk/lib/WikiDB/adodb/adodb-csvlib.inc.php trunk/lib/WikiDB/adodb/adodb-datadict.inc.php trunk/lib/WikiDB/adodb/adodb-error.inc.php trunk/lib/WikiDB/adodb/adodb-errorhandler.inc.php trunk/lib/WikiDB/adodb/adodb-errorpear.inc.php trunk/lib/WikiDB/adodb/adodb-exceptions.inc.php trunk/lib/WikiDB/adodb/adodb-iterator.inc.php trunk/lib/WikiDB/adodb/adodb-lib.inc.php trunk/lib/WikiDB/adodb/adodb-memcache.lib.inc.php trunk/lib/WikiDB/adodb/adodb-pager.inc.php trunk/lib/WikiDB/adodb/adodb-pear.inc.php trunk/lib/WikiDB/adodb/adodb-perf.inc.php trunk/lib/WikiDB/adodb/adodb-php4.inc.php trunk/lib/WikiDB/adodb/adodb-time.inc.php trunk/lib/WikiDB/adodb/adodb-xmlschema.inc.php trunk/lib/WikiDB/adodb/adodb-xmlschema03.inc.php trunk/lib/WikiDB/adodb/adodb.inc.php trunk/lib/WikiDB/adodb/contrib/toxmlrpc.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-access.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-db2.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-firebird.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-generic.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-ibase.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-informix.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-mssql.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-mssqlnative.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-mysql.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-oci8.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-postgres.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-sapdb.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-sqlite.inc.php trunk/lib/WikiDB/adodb/datadict/datadict-sybase.inc.php trunk/lib/WikiDB/adodb/docs/docs-active-record.htm trunk/lib/WikiDB/adodb/docs/docs-adodb.htm trunk/lib/WikiDB/adodb/docs/docs-datadict.htm trunk/lib/WikiDB/adodb/docs/docs-oracle.htm trunk/lib/WikiDB/adodb/docs/docs-perf.htm trunk/lib/WikiDB/adodb/docs/docs-session.htm trunk/lib/WikiDB/adodb/docs/docs-session.old.htm trunk/lib/WikiDB/adodb/docs/old-changelog.htm trunk/lib/WikiDB/adodb/docs/tips_portable_sql.htm trunk/lib/WikiDB/adodb/docs/tute.htm trunk/lib/WikiDB/adodb/drivers/adodb-access.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-ado.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-ado5.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-ado_access.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-ado_mssql.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-ads.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-borland_ibase.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-csv.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-db2.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-db2oci.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-db2ora.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-fbsql.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-firebird.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-ibase.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-informix.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-informix72.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-ldap.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-mssql.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-mssql_n.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-mssqlnative.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-mssqlpo.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-mysql.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-mysqli.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-mysqlpo.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-mysqlt.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-netezza.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-oci8.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-oci805.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-oci8po.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-odbc.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-odbc_db2.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-odbc_mssql.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-odbc_oracle.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-odbtp.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-odbtp_unicode.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-oracle.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-pdo.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-pdo_mssql.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-pdo_mysql.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-pdo_oci.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-pdo_pgsql.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-pdo_sqlite.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-postgres.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-postgres64.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-postgres7.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-postgres8.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-postgres9.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-proxy.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-sapdb.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-sqlanywhere.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-sqlite.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-sqlite3.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-sqlitepo.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-sybase.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-sybase_ase.inc.php trunk/lib/WikiDB/adodb/drivers/adodb-vfp.inc.php trunk/lib/WikiDB/adodb/lang/adodb-da.inc.php trunk/lib/WikiDB/adodb/lang/adodb-de.inc.php trunk/lib/WikiDB/adodb/lang/adodb-en.inc.php trunk/lib/WikiDB/adodb/lang/adodb-es.inc.php trunk/lib/WikiDB/adodb/lang/adodb-esperanto.inc.php trunk/lib/WikiDB/adodb/lang/adodb-fa.inc.php trunk/lib/WikiDB/adodb/lang/adodb-fr.inc.php trunk/lib/WikiDB/adodb/lang/adodb-it.inc.php trunk/lib/WikiDB/adodb/lang/adodb-nl.inc.php trunk/lib/WikiDB/adodb/lang/adodb-ro.inc.php trunk/lib/WikiDB/adodb/license.txt trunk/lib/WikiDB/adodb/pear/Auth/Container/ADOdb.php trunk/lib/WikiDB/adodb/pear/readme.Auth.txt trunk/lib/WikiDB/adodb/perf/perf-db2.inc.php trunk/lib/WikiDB/adodb/perf/perf-informix.inc.php trunk/lib/WikiDB/adodb/perf/perf-mssql.inc.php trunk/lib/WikiDB/adodb/perf/perf-mssqlnative.inc.php trunk/lib/WikiDB/adodb/perf/perf-mysql.inc.php trunk/lib/WikiDB/adodb/perf/perf-oci8.inc.php trunk/lib/WikiDB/adodb/perf/perf-postgres.inc.php trunk/lib/WikiDB/adodb/pivottable.inc.php trunk/lib/WikiDB/adodb/rsfilter.inc.php trunk/lib/WikiDB/adodb/server.php trunk/lib/WikiDB/adodb/session/adodb-compress-bzip2.php trunk/lib/WikiDB/adodb/session/adodb-compress-gzip.php trunk/lib/WikiDB/adodb/session/adodb-cryptsession.php trunk/lib/WikiDB/adodb/session/adodb-cryptsession2.php trunk/lib/WikiDB/adodb/session/adodb-encrypt-mcrypt.php trunk/lib/WikiDB/adodb/session/adodb-encrypt-md5.php trunk/lib/WikiDB/adodb/session/adodb-encrypt-secret.php trunk/lib/WikiDB/adodb/session/adodb-encrypt-sha1.php trunk/lib/WikiDB/adodb/session/adodb-sess.txt trunk/lib/WikiDB/adodb/session/adodb-session-clob.php trunk/lib/WikiDB/adodb/session/adodb-session-clob2.php trunk/lib/WikiDB/adodb/session/adodb-session.php trunk/lib/WikiDB/adodb/session/adodb-session2.php trunk/lib/WikiDB/adodb/session/crypt.inc.php trunk/lib/WikiDB/adodb/session/old/adodb-cryptsession.php trunk/lib/WikiDB/adodb/session/old/adodb-session-clob.php trunk/lib/WikiDB/adodb/session/old/adodb-session.php trunk/lib/WikiDB/adodb/session/old/crypt.inc.php trunk/lib/WikiDB/adodb/session/session_schema.xml trunk/lib/WikiDB/adodb/session/session_schema2.xml trunk/lib/WikiDB/adodb/tests/benchmark.php trunk/lib/WikiDB/adodb/tests/client.php trunk/lib/WikiDB/adodb/tests/pdo.php trunk/lib/WikiDB/adodb/tests/test-active-record.php trunk/lib/WikiDB/adodb/tests/test-active-recs2.php trunk/lib/WikiDB/adodb/tests/test-active-relations.php trunk/lib/WikiDB/adodb/tests/test-active-relationsx.php trunk/lib/WikiDB/adodb/tests/test-datadict.php trunk/lib/WikiDB/adodb/tests/test-perf.php trunk/lib/WikiDB/adodb/tests/test-pgblob.php trunk/lib/WikiDB/adodb/tests/test-php5.php trunk/lib/WikiDB/adodb/tests/test-xmlschema.php trunk/lib/WikiDB/adodb/tests/test.php trunk/lib/WikiDB/adodb/tests/test2.php trunk/lib/WikiDB/adodb/tests/test3.php trunk/lib/WikiDB/adodb/tests/test4.php trunk/lib/WikiDB/adodb/tests/test5.php trunk/lib/WikiDB/adodb/tests/test_rs_array.php trunk/lib/WikiDB/adodb/tests/testcache.php trunk/lib/WikiDB/adodb/tests/testdatabases.inc.php trunk/lib/WikiDB/adodb/tests/testgenid.php trunk/lib/WikiDB/adodb/tests/testmssql.php trunk/lib/WikiDB/adodb/tests/testoci8.php trunk/lib/WikiDB/adodb/tests/testoci8cursor.php trunk/lib/WikiDB/adodb/tests/testpaging.php trunk/lib/WikiDB/adodb/tests/testpear.php trunk/lib/WikiDB/adodb/tests/testsessions.php trunk/lib/WikiDB/adodb/tests/time.php trunk/lib/WikiDB/adodb/tests/tmssql.php trunk/lib/WikiDB/adodb/toexport.inc.php trunk/lib/WikiDB/adodb/tohtml.inc.php trunk/lib/WikiDB/adodb/xmlschema.dtd trunk/lib/WikiDB/adodb/xmlschema03.dtd trunk/lib/WikiDB/adodb/xsl/convert-0.1-0.2.xsl trunk/lib/WikiDB/adodb/xsl/convert-0.1-0.3.xsl trunk/lib/WikiDB/adodb/xsl/convert-0.2-0.1.xsl trunk/lib/WikiDB/adodb/xsl/convert-0.2-0.3.xsl trunk/lib/WikiDB/adodb/xsl/remove-0.2.xsl trunk/lib/WikiDB/adodb/xsl/remove-0.3.xsl Added Paths: ----------- trunk/lib/WikiDB/adodb/README.md trunk/lib/WikiDB/adodb/composer.json trunk/lib/WikiDB/adodb/docs/adodb-faq.html trunk/lib/WikiDB/adodb/docs/adodb.gif trunk/lib/WikiDB/adodb/docs/adodb2.gif trunk/lib/WikiDB/adodb/docs/index.html trunk/lib/WikiDB/adodb/drivers/adodb-oci8quercus.inc.php trunk/lib/WikiDB/adodb/lang/adodb-ar.inc.php trunk/lib/WikiDB/adodb/lang/adodb-bg.inc.php trunk/lib/WikiDB/adodb/lang/adodb-bgutf8.inc.php trunk/lib/WikiDB/adodb/lang/adodb-ca.inc.php trunk/lib/WikiDB/adodb/lang/adodb-cn.inc.php trunk/lib/WikiDB/adodb/lang/adodb-cz.inc.php trunk/lib/WikiDB/adodb/lang/adodb-hu.inc.php trunk/lib/WikiDB/adodb/lang/adodb-pl.inc.php trunk/lib/WikiDB/adodb/lang/adodb-pt-br.inc.php trunk/lib/WikiDB/adodb/lang/adodb-ru1251.inc.php trunk/lib/WikiDB/adodb/lang/adodb-sv.inc.php trunk/lib/WikiDB/adodb/lang/adodb-uk1251.inc.php trunk/lib/WikiDB/adodb/lang/adodb_th.inc.php trunk/lib/WikiDB/adodb/pear/auth_adodb_example.php Removed Paths: ------------- trunk/lib/WikiDB/adodb/docs/readme.htm trunk/lib/WikiDB/adodb/readme.txt Added: trunk/lib/WikiDB/adodb/README.md =================================================================== --- trunk/lib/WikiDB/adodb/README.md (rev 0) +++ trunk/lib/WikiDB/adodb/README.md 2014-07-21 12:04:00 UTC (rev 8996) @@ -0,0 +1,94 @@ +ADODB Library for PHP5 +====================== + +(c) 2000-2014 John Lim (jl...@na...) + +Released under both BSD and GNU Lesser GPL library license. +This means you can use it in proprietary products. + +Home page: http://adodb.sourceforge.net/ + + +Introduction +============ + +PHP's database access functions are not standardized. This creates a +need for a database class library to hide the differences between the +different databases (encapsulate the differences) so we can easily +switch databases. + +The library currently supports MySQL, Interbase, Sybase, PostgreSQL, Oracle, +Microsoft SQL server, Foxpro ODBC, Access ODBC, Informix, DB2, +Sybase SQL Anywhere, generic ODBC and Microsoft's ADO. + +We hope more people will contribute drivers to support other databases. + + +Installation +============ + +Unpack all the files into a directory accessible by your web server. + +To test, try modifying some of the tutorial examples. +Make sure you customize the connection settings correctly. + +You can debug using: + +``` php +<?php +include('adodb/adodb.inc.php'); + +$db = ADONewConnection($driver); # eg. 'mysql' or 'oci8' +$db->debug = true; +$db->Connect($server, $user, $password, $database); +$rs = $db->Execute('select * from some_small_table'); +print "<pre>"; +print_r($rs->GetRows()); +print "</pre>"; +``` + + +Documentation and Examples +========================== + +Refer to the `docs` directory for library documentation and examples. + +- Main documentation: `docs-adodb.htm`. + Query, update and insert records using a portable API. +- Data dictionary docs: `docs-datadict.htm`. + Describes how to create database tables and indexes in a portable manner. +- Database performance monitoring docs: `docs-perf.htm`. + Allows you to perform health checks, tune and monitor your database. +- Database-backed session docs: `docs-session.htm`. + +There is also a tutorial `tute.htm` that contrasts ADOdb code with +mysql code. + + +Files +===== + +- `adodb.inc.php` is the library's main file. You only need to include this file. +- `adodb-*.inc.php` are the database specific driver code. +- `adodb-session.php` is the PHP4 session handling code. +- `test.php` contains a list of test commands to exercise the class library. +- `testdatabases.inc.php` contains the list of databases to apply the tests on. +- `Benchmark.php` is a simple benchmark to test the throughput of a SELECT +statement for databases described in testdatabases.inc.php. The benchmark +tables are created in test.php. + + +Feature Requests and Bug Reports +================================ + +Please report bugs, issues and feature requests on Github: + +https://github.com/ADOdb/ADOdb/issues + +You may also find legacy issues in + +- the old [ADOdb forums](http://phplens.com/lens/lensforum/topics.php?id=4) on phplens.com +- the [SourceForge tickets section](http://sourceforge.net/p/adodb/_list/tickets) + +However, please note that they are not actively monitored and should +only be used as reference. Modified: trunk/lib/WikiDB/adodb/adodb-active-record.inc.php =================================================================== --- trunk/lib/WikiDB/adodb/adodb-active-record.inc.php 2014-07-21 09:44:17 UTC (rev 8995) +++ trunk/lib/WikiDB/adodb/adodb-active-record.inc.php 2014-07-21 12:04:00 UTC (rev 8996) @@ -1,18 +1,18 @@ <?php /* -@version V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. +@version V5.19 23-Apr-2014 (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved. Latest version is available at http://adodb.sourceforge.net - - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, + + 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. - + Active Record implementation. Superset of Zend Framework's. - + Version 0.92 - - See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord + + See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord for info on Ruby on Rails Active Record implementation */ @@ -44,30 +44,30 @@ // $db = database connection // $index = name of index - can be associative, for an example see -// http://phplens.com/lens/lensforum/msgs.php?id=17790 +// http://phplens.com/lens/lensforum/msgs.php?id=17790 // returns index into $_ADODB_ACTIVE_DBS function ADODB_SetDatabaseAdapter(&$db, $index=false) { global $_ADODB_ACTIVE_DBS; - + foreach($_ADODB_ACTIVE_DBS as $k => $d) { if (PHP_VERSION >= 5) { if ($d->db === $db) return $k; } else { - if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) + if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) return $k; } } - + $obj = new ADODB_Active_DB(); $obj->db = $db; $obj->tables = array(); - + if ($index == false) $index = sizeof($_ADODB_ACTIVE_DBS); - + $_ADODB_ACTIVE_DBS[$index] = $obj; - + return sizeof($_ADODB_ACTIVE_DBS)-1; } @@ -75,8 +75,8 @@ class ADODB_Active_Record { static $_changeNames = true; // dynamically pluralize table names static $_quoteNames = false; - - static $_foreignSuffix = '_id'; // + + static $_foreignSuffix = '_id'; // var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat] var $_table; // tablename, if set in class definition then use it as table name var $_tableat; // associative index pointing to ADODB_Active_Table, eg $ADODB_Active_DBS[_dbat]->tables[$this->_tableat] @@ -87,8 +87,8 @@ var $foreignName; // CFR: class name when in a relationship - var $lockMode = ' for update '; // you might want to change to - + var $lockMode = ' for update '; // you might want to change to + static function UseDefaultValues($bool=null) { global $ADODB_ACTIVE_DEFVALS; @@ -97,29 +97,29 @@ } // should be static - static function SetDatabaseAdapter(&$db, $index=false) + static function SetDatabaseAdapter(&$db, $index=false) { return ADODB_SetDatabaseAdapter($db, $index); } - - + + public function __set($name, $value) { $name = str_replace(' ', '_', $name); $this->$name = $value; } - + // php5 constructor function __construct($table = false, $pkeyarr=false, $db=false) { global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS; - + if ($db == false && is_object($pkeyarr)) { $db = $pkeyarr; $pkeyarr = false; } - - if (!$table) { + + if (!$table) { if (!empty($this->_table)) $table = $this->_table; else $table = $this->_pluralize(get_class($this)); } @@ -137,13 +137,13 @@ $this->UpdateActiveTable($pkeyarr); } - + function __wakeup() { $class = get_class($this); new $class; } - + function _pluralize($table) { if (!ADODB_Active_Record::$_changeNames) return $table; @@ -154,26 +154,26 @@ $lastc2 = substr($ut,$len-2); switch ($lastc) { case 'S': - return $table.'es'; + return $table.'es'; case 'Y': return substr($table,0,$len-1).'ies'; - case 'X': + case 'X': return $table.'es'; - case 'H': + case 'H': if ($lastc2 == 'CH' || $lastc2 == 'SH') return $table.'es'; default: return $table.'s'; } } - + // CFR Lamest singular inflector ever - @todo Make it real! // Note: There is an assumption here...and it is that the argument's length >= 4 function _singularize($tables) { - + if (!ADODB_Active_Record::$_changeNames) return $table; - + $ut = strtoupper($tables); $len = strlen($tables); if($ut[$len-1] != 'S') @@ -205,14 +205,14 @@ $table->_hasMany[$foreignRef] = $ar; # $this->$foreignRef = $this->_hasMany[$foreignRef]; // WATCHME Removed assignment by ref. to please __get() } - + // use when you don't want ADOdb to auto-pluralize tablename static function TableHasMany($table, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record') { $ar = new ADODB_Active_Record($table); $ar->hasMany($foreignRef, $foreignKey, $foreignClass); } - + // use when you don't want ADOdb to auto-pluralize tablename static function TableKeyHasMany($table, $tablePKey, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record') { @@ -220,8 +220,8 @@ $ar = new ADODB_Active_Record($table,$tablePKey); $ar->hasMany($foreignRef, $foreignKey, $foreignClass); } - - + + // use when you want ADOdb to auto-pluralize tablename for you. Note that the class must already be defined. // e.g. class Person will generate relationship for table Persons static function ClassHasMany($parentclass, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record') @@ -229,8 +229,8 @@ $ar = new $parentclass(); $ar->hasMany($foreignRef, $foreignKey, $foreignClass); } - + function belongsTo($foreignRef,$foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record') { global $inflector; @@ -240,24 +240,24 @@ $ar->parentKey = $parentKey; $ar->UpdateActiveTable(); $ar->foreignKey = ($foreignKey) ? $foreignKey : $foreignRef.ADODB_Active_Record::$_foreignSuffix; - + $table =& $this->TableInfo(); $table->_belongsTo[$foreignRef] = $ar; # $this->$foreignRef = $this->_belongsTo[$foreignRef]; } - + static function ClassBelongsTo($class, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record') { $ar = new $class(); $ar->belongsTo($foreignRef, $foreignKey, $parentKey, $parentClass); } - + static function TableBelongsTo($table, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record') { $ar = new ADOdb_Active_Record($table); $ar->belongsTo($foreignRef, $foreignKey, $parentKey, $parentClass); } - + static function TableKeyBelongsTo($table, $tablePKey, $foreignRef, $foreignKey=false, $parentKey='', $parentClass = 'ADODB_Active_Record') { if (!is_array($tablePKey)) $tablePKey = array($tablePKey); @@ -268,8 +268,8 @@ /** * __get Access properties - used for lazy loading - * - * @param mixed $name + * + * @param mixed $name * @access protected * @return mixed */ @@ -277,9 +277,9 @@ { return $this->LoadRelations($name, '', -1, -1); } - + /** - * @param string $name + * @param string $name * @param string $whereOrderBy : eg. ' AND field1 = value ORDER BY field2' * @param offset * @param limit @@ -291,12 +291,12 @@ $table = $this->TableInfo(); if ($limit >= 0) $extras['limit'] = $limit; if ($offset >= 0) $extras['offset'] = $offset; - - if (strlen($whereOrderBy)) + + if (strlen($whereOrderBy)) if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy)) if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy)) $whereOrderBy = 'AND '.$whereOrderBy; - + if(!empty($table->_belongsTo[$name])) { $obj = $table->_belongsTo[$name]; @@ -307,7 +307,7 @@ { if ($obj->parentKey) $key = $obj->parentKey; else $key = reset($table->keys); - + $arrayOfOne = $obj->Find($key.'='.$this->$columnName.' '.$whereOrderBy,false,false,$extras); if ($arrayOfOne) { $this->$name = $arrayOfOne[0]; @@ -316,7 +316,7 @@ } } if(!empty($table->_hasMany[$name])) - { + { $obj = $table->_hasMany[$name]; $key = reset($table->keys); $id = @$this->$key; @@ -329,11 +329,11 @@ $this->$name = $objs; return $objs; } - + return array(); } ////////////////////////////////// - + // update metadata function UpdateActiveTable($pkeys=false,$forceUpdate=false) { @@ -349,7 +349,7 @@ $acttab = $tables[$tableat]; foreach($acttab->flds as $name => $fld) { - if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) + if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) $this->$name = $fld->default_value; else $this->$name = null; @@ -363,19 +363,19 @@ @flock($fp, LOCK_SH); $acttab = unserialize(fread($fp,100000)); fclose($fp); - if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) { + if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) { // abs(rand()) randomizes deletion, reducing contention to delete/refresh file // ideally, you should cache at least 32 secs - + foreach($acttab->flds as $name => $fld) { - if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) + if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) $this->$name = $fld->default_value; else $this->$name = null; } - + $activedb->tables[$table] = $acttab; - + //if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname"); return; } else if ($db->debug) { @@ -384,18 +384,18 @@ } $activetab = new ADODB_Active_Table(); $activetab->name = $table; - + $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false); - + $cols = $db->MetaColumns($table); - + if (isset($savem)) $db->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; - + if (!$cols) { - $this->Error("Invalid table name: $table",'UpdateActiveTable'); + $this->Error("Invalid table name: $table",'UpdateActiveTable'); return false; } $fld = reset($cols); @@ -405,17 +405,17 @@ foreach($cols as $name => $fld) { if (!empty($fld->primary_key)) $pkeys[] = $name; } - } else + } else $pkeys = $this->GetPrimaryKeys($db, $table); } if (empty($pkeys)) { $this->Error("No primary key found for table $table",'UpdateActiveTable'); return false; } - + $attr = array(); $keys = array(); - + switch($ADODB_ASSOC_CASE) { case 0: foreach($cols as $name => $fldobj) { @@ -430,18 +430,18 @@ $keys[strtolower($name)] = strtolower($name); } break; - - case 1: + + case 1: foreach($cols as $name => $fldobj) { $name = strtoupper($name); - + if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) $this->$name = $fldobj->default_value; else $this->$name = null; $attr[$name] = $fldobj; } - + foreach($pkeys as $k => $name) { $keys[strtoupper($name)] = strtoupper($name); } @@ -449,7 +449,7 @@ default: foreach($cols as $name => $fldobj) { $name = ($fldobj->name); - + if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) $this->$name = $fldobj->default_value; else @@ -461,7 +461,7 @@ } break; } - + $activetab->keys = $keys; $activetab->flds = $attr; @@ -473,58 +473,58 @@ } if (isset($activedb->tables[$table])) { $oldtab = $activedb->tables[$table]; - + if ($oldtab) $activetab->_belongsTo = $oldtab->_belongsTo; if ($oldtab) $activetab->_hasMany = $oldtab->_hasMany; } $activedb->tables[$table] = $activetab; } - + function GetPrimaryKeys(&$db, $table) { return $db->MetaPrimaryKeys($table); } - - // error handler for both PHP4+5. + + // error handler for both PHP4+5. function Error($err,$fn) { global $_ADODB_ACTIVE_DBS; - + $fn = get_class($this).'::'.$fn; $this->_lasterr = $fn.': '.$err; - + if ($this->_dbat < 0) $db = false; else { $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; $db = $activedb->db; } - - if (function_exists('adodb_throw')) { + + if (function_exists('adodb_throw')) { if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false); else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db); } else if (!$db || $db->debug) ADOConnection::outp($this->_lasterr); - + } - + // return last error message function ErrorMsg() { if (!function_exists('adodb_throw')) { if ($this->_dbat < 0) $db = false; else $db = $this->DB(); - + // last error could be database error too if ($db && $db->ErrorMsg()) return $db->ErrorMsg(); } return $this->_lasterr; } - - function ErrorNo() + + function ErrorNo() { if ($this->_dbat < 0) return -9999; // no database connection... $db = $this->DB(); - + return (int) $db->ErrorNo(); } @@ -533,7 +533,7 @@ function DB() { global $_ADODB_ACTIVE_DBS; - + if ($this->_dbat < 0) { $false = false; $this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB"); @@ -543,7 +543,7 @@ $db = $activedb->db; return $db; } - + // retrieve ADODB_Active_Table function &TableInfo() { @@ -552,8 +552,8 @@ $table = $activedb->tables[$this->_tableat]; return $table; } - - + + // I have an ON INSERT trigger on a table that sets other columns in the table. // So, I find that for myTable, I want to reload an active record after saving it. -- Malcolm Cook function Reload() @@ -564,21 +564,21 @@ return($this->Load($where)); } - + // set a numeric array (using natural table field ordering) as object properties function Set(&$row) { global $ACTIVE_RECORD_SAFETY; - + $db = $this->DB(); - + if (!$row) { - $this->_saved = false; + $this->_saved = false; return false; } - + $this->_saved = true; - + $table = $this->TableInfo(); if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) { # <AP> @@ -597,7 +597,7 @@ } else $keys = array_keys($row); - + # <AP> reset($keys); $this->_original = array(); @@ -611,7 +611,7 @@ # </AP> return true; } - + // get last inserted id for INSERT function LastInsertID(&$db,$fieldname) { @@ -619,32 +619,32 @@ $val = $db->Insert_ID($this->_table,$fieldname); else $val = false; - + if (is_null($val) || $val === false) { // this might not work reliably in multi-user environment return $db->GetOne("select max(".$fieldname.") from ".$this->_table); } return $val; } - + // quote data in where clause function doquote(&$db, $val,$t) { switch($t) { case 'L': if (strpos($db->databaseType,'postgres') !== false) return $db->qstr($val); - case 'D': + case 'D': case 'T': if (empty($val)) return 'null'; - - case 'B': + + case 'B': case 'N': case 'C': case 'X': if (is_null($val)) return 'null'; - - if (strlen($val)>0 && - (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) { + + if (strlen($val)>0 && + (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) { return $db->qstr($val); break; } @@ -653,13 +653,13 @@ break; } } - + // generate where clause for an UPDATE/SELECT function GenWhere(&$db, &$table) { $keys = $table->keys; $parr = array(); - + foreach($keys as $k) { $f = $table->flds[$k]; if ($f) { @@ -668,55 +668,55 @@ } return implode(' and ', $parr); } - - + + function _QName($n,$db=false) { if (!ADODB_Active_Record::$_quoteNames) return $n; if (!$db) $db = $this->DB(); if (!$db) return false; return $db->nameQuote.$n.$db->nameQuote; } - + //------------------------------------------------------------ Public functions below - + function Load($where=null,$bindarr=false, $lock = false) { global $ADODB_FETCH_MODE; - + $db = $this->DB(); if (!$db) return false; $this->_where = $where; - + $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false); - + $qry = "select * from ".$this->_table; - + if($where) { $qry .= ' WHERE '.$where; } if ($lock) $qry .= $this->lockMode; - + $row = $db->GetRow($qry,$bindarr); - + if (isset($savem)) $db->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; - + return $this->Set($row); } - + function LoadLocked($where=null, $bindarr=false) { $this->Load($where,$bindarr,true); } - + # useful for multiple record inserts # see http://phplens.com/lens/lensforum/msgs.php?id=17795 function Reset() { $this->_where=null; - $this->_saved = false; - $this->_lasterr = false; + $this->_saved = false; + $this->_lasterr = false; $this->_original = false; $vars=get_object_vars($this); foreach($vars as $k=>$v){ @@ -727,24 +727,24 @@ $this->foreignName=strtolower(get_class($this)); return true; } - + // false on error function Save() { if ($this->_saved) $ok = $this->Update(); else $ok = $this->Insert(); - + return $ok; } - - + + // false on error function Insert() { $db = $this->DB(); if (!$db) return false; $cnt = 0; $table = $this->TableInfo(); - + $valarr = array(); $names = array(); $valstr = array(); @@ -758,7 +758,7 @@ $cnt += 1; } } - + if (empty($names)){ foreach($table->flds as $name=>$fld) { $valarr[] = null; @@ -769,7 +769,7 @@ } $sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')'; $ok = $db->Execute($sql,$valarr); - + if ($ok) { $this->_saved = true; $autoinc = false; @@ -784,23 +784,23 @@ $this->$k = $this->LastInsertID($db,$k); } } - + $this->_original = $valarr; return !empty($ok); } - + function Delete() { $db = $this->DB(); if (!$db) return false; $table = $this->TableInfo(); - + $where = $this->GenWhere($db,$table); $sql = 'DELETE FROM '.$this->_table.' WHERE '.$where; $ok = $db->Execute($sql); - + return $ok ? true : false; } - + // returns an array of active record objects function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array()) { @@ -808,17 +808,17 @@ $arr = $db->GetActiveRecordsClass(get_class($this),$this->_table, $whereOrderBy,$bindarr,$pkeysArr,$extra); return $arr; } - + // returns 0 on error, 1 on update, 2 on insert function Replace() { global $ADODB_ASSOC_CASE; - + $db = $this->DB(); if (!$db) return false; $table = $this->TableInfo(); - + $pkey = $table->keys; - + foreach($table->flds as $name=>$fld) { $val = $this->$name; /* @@ -834,24 +834,24 @@ if (is_null($val) && !empty($fld->auto_increment)) { continue; } - + if (is_array($val)) continue; - + $t = $db->MetaType($fld->type); $arr[$name] = $this->doquote($db,$val,$t); $valarr[] = $val; } - + if (!is_array($pkey)) $pkey = array($pkey); - - - if ($ADODB_ASSOC_CASE == 0) + + + if ($ADODB_ASSOC_CASE == 0) foreach($pkey as $k => $v) $pkey[$k] = strtolower($v); - elseif ($ADODB_ASSOC_CASE == 1) + elseif ($ADODB_ASSOC_CASE == 1) foreach($pkey as $k => $v) $pkey[$k] = strtoupper($v); - + $ok = $db->Replace($this->_table,$arr,$pkey); if ($ok) { $this->_saved = true; // 1= update 2=insert @@ -868,9 +868,9 @@ $this->$k = $this->LastInsertID($db,$k); } } - + $this->_original = $valarr; - } + } return $ok; } @@ -879,14 +879,14 @@ { $db = $this->DB(); if (!$db) return false; $table = $this->TableInfo(); - + $where = $this->GenWhere($db, $table); - + if (!$where) { $this->error("Where missing for table $table", "Update"); return false; } - $valarr = array(); + $valarr = array(); $neworig = array(); $pairs = array(); $i = -1; @@ -895,10 +895,10 @@ $i += 1; $val = $this->$name; $neworig[] = $val; - - if (isset($table->keys[$name]) || is_array($val)) + + if (isset($table->keys[$name]) || is_array($val)) continue; - + if (is_null($val)) { if (isset($fld->not_null) && $fld->not_null) { if (isset($fld->default_value) && strlen($fld->default_value)) continue; @@ -910,15 +910,15 @@ } if (isset($this->_original[$i]) && strcmp($val,$this->_original[$i]) == 0) continue; - + if (is_null($this->_original[$i]) && is_null($val)) continue; - + $valarr[] = $val; $pairs[] = $this->_QName($name,$db).'='.$db->Param($cnt); $cnt += 1; } - - + + if (!$cnt) return -1; $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where; $ok = $db->Execute($sql,$valarr); @@ -928,14 +928,14 @@ } return 0; } - + function GetAttributeNames() { $table = $this->TableInfo(); if (!$table) return false; return array_keys($table->flds); } - + }; function adodb_GetActiveRecordsClass(&$db, $class, $table,$whereOrderBy,$bindarr, $primkeyArr, @@ -943,10 +943,10 @@ { global $_ADODB_ACTIVE_DBS; - + $save = $db->SetFetchMode(ADODB_FETCH_NUM); $qry = "select * from ".$table; - + if (!empty($whereOrderBy)) $qry .= ' WHERE '.$whereOrderBy; if(isset($extra['limit'])) @@ -967,14 +967,14 @@ $rows = $db->GetAll($qry,$bindarr); $db->SetFetchMode($save); - + $false = false; - - if ($rows === false) { + + if ($rows === false) { return $false; } - + if (!class_exists($class)) { $db->outp_throw("Unknown class $class in GetActiveRecordsClass()",'GetActiveRecordsClass'); return $false; @@ -987,7 +987,7 @@ $arrRef = array(); $bTos = array(); // Will store belongTo's indices if any foreach($rows as $row) { - + $obj = new $class($table,$primkeyArr,$db); if ($obj->ErrorNo()){ $db->_errorMsg = $obj->ErrorMsg(); @@ -995,8 +995,7 @@ } $obj->Set($row); $arr[] = $obj; - } // foreach($rows as $row) + } // foreach($rows as $row) return $arr; } -?> \ No newline at end of file Modified: trunk/lib/WikiDB/adodb/adodb-active-recordx.inc.php =================================================================== --- trunk/lib/WikiDB/adodb/adodb-active-recordx.inc.php 2014-07-21 09:44:17 UTC (rev 8995) +++ trunk/lib/WikiDB/adodb/adodb-active-recordx.inc.php 2014-07-21 12:04:00 UTC (rev 8996) @@ -1,20 +1,20 @@ <?php /* -@version V5.06 29 Sept 2008 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. +@version V5.19 23-Apr-2014 (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved. Latest version is available at http://adodb.sourceforge.net - - Released under both BSD license and Lesser GPL library license. - Whenever there is any discrepancy between the two licenses, + + 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. - + Active Record implementation. Superset of Zend Framework's. - - This is "Active Record eXtended" to support JOIN, WORK and LAZY mode by Chris Ravenscroft chris#voilaweb.com - + + This is "Active Record eXtended" to support JOIN, WORK and LAZY mode by Chris Ravenscroft chris#voilaweb.com + Version 0.9 - - See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord + + See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord for info on Ruby on Rails Active Record implementation */ @@ -63,29 +63,29 @@ function ADODB_SetDatabaseAdapter(&$db) { global $_ADODB_ACTIVE_DBS; - + foreach($_ADODB_ACTIVE_DBS as $k => $d) { if (PHP_VERSION >= 5) { if ($d->db === $db) return $k; } else { - if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) + if ($d->db->_connectionID === $db->_connectionID && $db->database == $d->db->database) return $k; } } - + $obj = new ADODB_Active_DB(); $obj->db = $db; $obj->tables = array(); - + $_ADODB_ACTIVE_DBS[] = $obj; - + return sizeof($_ADODB_ACTIVE_DBS)-1; } class ADODB_Active_Record { static $_changeNames = true; // dynamically pluralize table names - static $_foreignSuffix = '_id'; // + static $_foreignSuffix = '_id'; // var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat] var $_table; // tablename, if set in class definition then use it as table name var $_sTable; // singularized table name @@ -106,18 +106,18 @@ } // should be static - static function SetDatabaseAdapter(&$db) + static function SetDatabaseAdapter(&$db) { return ADODB_SetDatabaseAdapter($db); } - - + + public function __set($name, $value) { $name = str_replace(' ', '_', $name); $this->$name = $value; } - + // php5 constructor // Note: if $table is defined, then we will use it as our table name // Otherwise we will use our classname... @@ -131,12 +131,12 @@ function __construct($table = false, $pkeyarr=false, $db=false, $options=array()) { global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS; - + if ($db == false && is_object($pkeyarr)) { $db = $pkeyarr; $pkeyarr = false; } - + if($table) { // table argument exists. It is expected to be @@ -159,10 +159,10 @@ $this->_dbat = ADODB_Active_Record::SetDatabaseAdapter($db); } else $this->_dbat = sizeof($_ADODB_ACTIVE_DBS)-1; - - + + if ($this->_dbat < 0) $this->Error("No database connection set; use ADOdb_Active_Record::SetDatabaseAdapter(\$db)",'ADODB_Active_Record::__constructor'); - + $this->_tableat = $this->_table; # reserved for setting the assoc value to a non-table name, eg. the sql string in future // CFR: Just added this option because UpdateActiveTable() can refresh its information @@ -178,13 +178,13 @@ $table->_belongsTo = array(); } } - + function __wakeup() { $class = get_class($this); new $class; } - + // CFR: Constants found in Rails static $IrregularP = array( 'PERSON' => 'people', @@ -231,26 +231,26 @@ $lastc2 = substr($ut,$len-2); switch ($lastc) { case 'S': - return $table.'es'; + return $table.'es'; case 'Y': return substr($table,0,$len-1).'ies'; - case 'X': + case 'X': return $table.'es'; - case 'H': + case 'H': if ($lastc2 == 'CH' || $lastc2 == 'SH') return $table.'es'; default: return $table.'s'; } } - + // CFR Lamest singular inflector ever - @todo Make it real! // Note: There is an assumption here...and it is that the argument's length >= 4 function _singularize($table) { - + if (!ADODB_Active_Record::$_changeNames) return $table; - + $ut = strtoupper($table); if(isset(self::$WeIsI[$ut])) { @@ -320,7 +320,7 @@ $ar->foreignName = $foreignRef; $ar->UpdateActiveTable(); $ar->foreignKey = ($foreignKey) ? $foreignKey : $ar->foreignName . self::$_foreignSuffix; - + $table =& $this->TableInfo(); if(!isset($table->_belongsTo[$foreignRef])) { @@ -332,8 +332,8 @@ /** * __get Access properties - used for lazy loading - * - * @param mixed $name + * + * @param mixed $name * @access protected * @return void */ @@ -348,12 +348,12 @@ if($offset >= 0) $extras['offset'] = $offset; if($limit >= 0) $extras['limit'] = $limit; $table =& $this->TableInfo(); - - if (strlen($whereOrderBy)) + + if (strlen($whereOrderBy)) if (!preg_match('/^[ \n\r]*AND/i',$whereOrderBy)) if (!preg_match('/^[ \n\r]*ORDER[ \n\r]/i',$whereOrderBy)) $whereOrderBy = 'AND '.$whereOrderBy; - + if(!empty($table->_belongsTo[$name])) { $obj = $table->_belongsTo[$name]; @@ -366,7 +366,7 @@ $belongsToId = $k; else $belongsToId = 'id'; - + $arrayOfOne = $obj->Find( $belongsToId.'='.$this->$columnName.' '.$whereOrderBy, false, false, $extras); @@ -380,7 +380,7 @@ if(($k = reset($table->keys))) $hasManyId = $k; else - $hasManyId = 'id'; + $hasManyId = 'id'; $this->$name = $obj->Find( @@ -389,7 +389,7 @@ } } ////////////////////////////////// - + // update metadata function UpdateActiveTable($pkeys=false,$forceUpdate=false) { @@ -405,14 +405,14 @@ $tobj = $tables[$tableat]; foreach($tobj->flds as $name => $fld) { - if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) + if ($ADODB_ACTIVE_DEFVALS && isset($fld->default_value)) $this->$name = $fld->default_value; else $this->$name = null; } return; } - + $db = $activedb->db; $fname = $ADODB_CACHE_DIR . '/adodb_' . $db->databaseType . '_active_'. $table . '.cache'; if (!$forceUpdate && $ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR && file_exists($fname)) { @@ -420,11 +420,11 @@ @flock($fp, LOCK_SH); $acttab = unserialize(fread($fp,100000)); fclose($fp); - if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) { + if ($acttab->_created + $ADODB_ACTIVE_CACHESECS - (abs(rand()) % 16) > time()) { // abs(rand()) randomizes deletion, reducing contention to delete/refresh file // ideally, you should cache at least 32 secs $activedb->tables[$table] = $acttab; - + //if ($db->debug) ADOConnection::outp("Reading cached active record file: $fname"); return; } else if ($db->debug) { @@ -433,18 +433,18 @@ } $activetab = new ADODB_Active_Table(); $activetab->name = $table; - + $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; if ($db->fetchMode !== false) $savem = $db->SetFetchMode(false); - + $cols = $db->MetaColumns($table); - + if (isset($savem)) $db->SetFetchMode($savem); $ADODB_FETCH_MODE = $save; - + if (!$cols) { - $this->Error("Invalid table name: $table",'UpdateActiveTable'); + $this->Error("Invalid table name: $table",'UpdateActiveTable'); return false; } $fld = reset($cols); @@ -454,17 +454,17 @@ foreach($cols as $name => $fld) { if (!empty($fld->primary_key)) $pkeys[] = $name; } - } else + } else $pkeys = $this->GetPrimaryKeys($db, $table); } if (empty($pkeys)) { $this->Error("No primary key found for table $table",'UpdateActiveTable'); return false; } - + $attr = array(); $keys = array(); - + switch($ADODB_ASSOC_CASE) { case 0: foreach($cols as $name => $fldobj) { @@ -479,18 +479,18 @@ $keys[strtolower($name)] = strtolower($name); } break; - - case 1: + + case 1: foreach($cols as $name => $fldobj) { $name = strtoupper($name); - + if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) $this->$name = $fldobj->default_value; else $this->$name = null; $attr[$name] = $fldobj; } - + foreach($pkeys as $k => $name) { $keys[strtoupper($name)] = strtoupper($name); } @@ -498,7 +498,7 @@ default: foreach($cols as $name => $fldobj) { $name = ($fldobj->name); - + if ($ADODB_ACTIVE_DEFVALS && isset($fldobj->default_value)) $this->$name = $fldobj->default_value; else @@ -510,7 +510,7 @@ } break; } - + $activetab->keys = $keys; $activetab->flds = $attr; $activetab->updateColsCount(); @@ -523,58 +523,58 @@ } if (isset($activedb->tables[$table])) { $oldtab = $activedb->tables[$table]; - + if ($oldtab) $activetab->_belongsTo = $oldtab->_belongsTo; if ($oldtab) $activetab->_hasMany = $oldtab->_hasMany; } $activedb->tables[$table] = $activetab; } - + function GetPrimaryKeys(&$db, $table) { return $db->MetaPrimaryKeys($table); } - - // error handler for both PHP4+5. + + // error handler for both PHP4+5. function Error($err,$fn) { global $_ADODB_ACTIVE_DBS; - + $fn = get_class($this).'::'.$fn; $this->_lasterr = $fn.': '.$err; - + if ($this->_dbat < 0) $db = false; else { $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; $db = $activedb->db; } - - if (function_exists('adodb_throw')) { + + if (function_exists('adodb_throw')) { if (!$db) adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false); else adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db); } else if (!$db || $db->debug) ADOConnection::outp($this->_lasterr); - + } - + // return last error message function ErrorMsg() { if (!function_exists('adodb_throw')) { if ($this->_dbat < 0) $db = false; else $db = $this->DB(); - + // last error could be database error too if ($db && $db->ErrorMsg()) return $db->ErrorMsg(); } return $this->_lasterr; } - - function ErrorNo() + + function ErrorNo() { if ($this->_dbat < 0) return -9999; // no database connection... $db = $this->DB(); - + return (int) $db->ErrorNo(); } @@ -583,7 +583,7 @@ function DB() { global $_ADODB_ACTIVE_DBS; - + if ($this->_dbat < 0) { $false = false; $this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB"); @@ -593,18 +593,18 @@ $db = $activedb->db; return $db; } - + // retrieve ADODB_Active_Table function &TableInfo() { global $_ADODB_ACTIVE_DBS; - + $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; $table = $activedb->tables[$this->_tableat]; return $table; } - - + + // I have an ON INSERT trigger on a table that sets other columns in the table. // So, I find that for myTable, I want to reload an active record after saving it. -- Malcolm Cook function Reload() @@ -615,21 +615,21 @@ return($this->Load($where)); } - + // set a numeric array (using natural table field ordering) as object properties function Set(&$row) { global $ACTIVE_RECORD_SAFETY; - + $db = $this->DB(); - + if (!$row) { - $this->_saved = false; + $this->_saved = false; return false; } - + $this->_saved = true; - + $table = $this->TableInfo(); $sizeofFlds = sizeof($table->flds); $sizeofRow = sizeof($row); @@ -687,7 +687,7 @@ # </AP> return true; } - + // get last inserted id for INSERT function LastInsertID(&$db,$fieldname) { @@ -695,14 +695,14 @@ $val = $db->Insert_ID($this->_table,$fieldname); else $val = false; - + if (is_null($val) || $val === false) { // this might not work reliably in multi-user environment return $db->GetOne("select max(".$fieldname.") from ".$this->_table); } return $val; } - + // quote data in where clause function doquote(&$db, $val,$t) { @@ -710,13 +710,13 @@ case 'D': case 'T': if (empty($val)) return 'null'; - + case 'C': case 'X': if (is_null($val)) return 'null'; - - if (strlen($val)>0 && - (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) { + + if (strlen($val)>0 && + (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) { return $db->qstr($val); break; } @@ -725,13 +725,13 @@ break; } } - + // generate where clause for an UPDATE/SELECT function GenWhere(&$db, &$table) { $keys = $table->keys; $parr = array(); - + foreach($keys as $k) { $f = $table->flds[$k]; if ($f) { @@ -740,15 +740,15 @@ } return implode(' and ', $parr); } - - + + //------------------------------------------------------------ Public functions below - + function Load($where=null,$bindarr=false) { $db = $this->DB(); if (!$db) return false; $this->_where = $where; - + $save = $db->SetFetchMode(ADODB_FETCH_NUM); $qry = "select * from ".$this->_table; $table =& $this->TableInfo(); @@ -757,7 +757,7 @@ $hasManyId = $k; else $hasManyId = 'id'; - + foreach($table->_belongsTo as $foreignTable) { if(($k = reset($foreignTable->TableInfo()->keys))) @@ -780,7 +780,7 @@ } if($where) $qry .= ' WHERE '.$where; - + // Simple case: no relations. Load row and return. if((count($table->_hasMany) + count($table->_belongsTo)) < 1) { @@ -790,7 +790,7 @@ $db->SetFetchMode($save); return $this->Set($row); } - + // More complex case when relations have to be collated $rows = $db->GetAll($qry,$bindarr); if(!$rows) @@ -800,7 +800,7 @@ return false; $class = get_class($this); $isFirstRow = true; - + if(($k = reset($this->TableInfo()->keys))) $myId = $k; else @@ -819,7 +819,7 @@ } if(!$found) $this->outp_throw("Unable to locate key $myId for $class in Load()",'Load'); - + foreach($rows as $row) { $rowId = intval($row[$index]); @@ -873,21 +873,21 @@ } } } - } + } } } return true; } - + // false on error function Save() { if ($this->_saved) $ok = $this->Update(); else $ok = $this->Insert(); - + return $ok; } - + // CFR: Sometimes we may wish to consider that an object is not to be replaced but inserted. // Sample use case: an 'undo' command object (after a delete()) function Dirty() @@ -901,7 +901,7 @@ $db = $this->DB(); if (!$db) return false; $cnt = 0; $table = $this->TableInfo(); - + $valarr = array(); $names = array(); $valstr = array(); @@ -915,7 +915,7 @@ $cnt += 1; } } - + if (empty($names)){ foreach($table->flds as $name=>$fld) { $valarr[] = null; @@ -926,7 +926,7 @@ } $sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')'; $ok = $db->Execute($sql,$valarr); - + if ($ok) { $this->_saved = true; $autoinc = false; @@ -941,23 +941,23 @@ $this->$k = $this->LastInsertID($db,$k); } } - + $this->_original = $valarr; return !empty($ok); } - + function Delete() { $db = $this->DB(); if (!$db) return false; $table = $this->TableInfo(); - + $where = $this->GenWhere($db,$table); $sql = 'DELETE FROM '.$this->_table.' WHERE '.$where; $ok = $db->Execute($sql); - + return $ok ? true : false; } - + // returns an array of active record objects function Find($whereOrderBy,$bindarr=false,$pkeysArr=false,$extra=array()) { @@ -967,7 +967,7 @@ array('foreignName'=>$this->foreignName, 'belongsTo'=>$table->_belongsTo, 'hasMany'=>$table->_hasMany)); return $arr; } - + // CFR: In introduced this method to ensure that inner workings are not disturbed by // subclasses...for instance when GetActiveRecordsClass invokes Find() // Why am I not invoking parent::Find? @@ -985,12 +985,12 @@ function Replace() { global $ADODB_ASSOC_CASE; - + $db = $this->DB(); if (!$db) return false; $table = $this->TableInfo(); - + $pkey = $table->keys; - + foreach($table->flds as $name=>$fld) { $val = $this->$name; /* @@ -1010,17 +1010,17 @@ $arr[$name] = $this->doquote($db,$val,$t); $valarr[] = $val; } - + if (!is_array($pkey)) $pkey = array($pkey); - - - if ($ADODB_ASSOC_CASE == 0) + + + if ($ADODB_ASSOC_CASE == 0) foreach($pkey as $k => $v) $pkey[$k] = strtolower($v); - elseif ($ADODB_ASSOC_CASE == 1) + elseif ($ADODB_ASSOC_CASE == 1) foreach($pkey as $k => $v) $pkey[$k] = strtoupper($v); - + $ok = $db->Replace($this->_table,$arr,$pkey); if ($ok) { $this->_saved = true; // 1= update 2=insert @@ -1037,9 +1037,9 @@ $this->$k = $this->LastInsertID($db,$k); } } - + $this->_original = $valarr; - } + } return $ok; } @@ -1048,14 +1048,14 @@ { $db = $this->DB(); if (!$db) return false; $table = $this->TableInfo(); - + $where = $this->GenWhere($db, $table); - + if (!$where) { $this->error("Where missing for table $table", "Update"); return false; } - $valarr = array(); + $valarr = array(); $neworig = array(); $pairs = array(); $i = -1; @@ -1064,11 +1064,11 @@ $i += 1; $val = $this->$name; $neworig[] = $val; - + if (isset($table->keys[$name])) { continue; } - + if (is_null($val)) { if (isset($fld->not_null) && $fld->not_null) { if (isset($fld->default_value) && strlen($fld->default_value)) continue; @@ -1078,16 +1078,16 @@ } } } - + if (isset($this->_original[$i]) && $val == $this->_original[$i]) { continue; - } + } $valarr[] = $val; $pairs[] = $name.'='.$db->Param($cnt); $cnt += 1; } - - + + if (!$cnt) return -1; $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where; $ok = $db->Execute($sql,$valarr); @@ -1097,23 +1097,23 @@ } return 0; } - + function GetAttributeNames() { $table = $this->TableInfo(); if (!$table) return false; return array_keys($table->flds); } - + }; function adodb_GetActiveRecordsClass(&$db, $class, $tableObj,$whereOrderBy,$bindarr, $primkeyArr, $extra, $relations) { global $_ADODB_ACTIVE_DBS; - + if (empty($extra['loading'])) $extra['loading'] = ADODB_LAZY_AR; - + $save = $db->SetFetchMode(ADODB_FETCH_NUM); $table = &$tableObj->_table; $tableInfo =& $tableObj->TableInfo(); @@ -1135,7 +1135,7 @@ } if(!$found) $db->outp_throw("Unable to locate key $myId for $class in GetActiveRecordsClass()",'GetActiveRecordsClass'); - + $qry = "select * from ".$table; if(ADODB_JOIN_AR == $extra['loading']) { @@ -1192,19 +1192,19 @@ } } else $rows = $db->GetAll($qry,$bindarr); - + $db->SetFetchMode($save); - + $false = false; - - if ($rows === false) { + + if ($rows === false) { return $false; } - - + + if (!isset($_ADODB_ACTIVE_DBS)) { include(ADODB_DIR.'/adodb-active-record.inc.php'); - } + } if (!class_exists($class)) { $db->outp_throw("Unknown class $class in GetActiveRecordsClass()",'GetActiveRecordsClass'); return $false; @@ -1218,7 +1218,7 @@ $arrRef = array(); $bTos = array(); // Will store belongTo's indices if any foreach($rows as $row) { - + $obj = new $class($table,$primkeyArr,$db); if ($obj->ErrorNo()){ $db->_errorMsg = $obj->ErrorMsg(); @@ -1268,7 +1268,7 @@ { if(ADODB_JOIN_AR == $extra['loading']) { - $isNewObj = !isset($uniqArr['_'.$row[0]]); + $isNewObj = !isset($uniqArr['_'.$row[0]]); if($isNewObj) $uniqArr['_'.$row[0]] = $obj; @@ -1322,7 +1322,7 @@ } } if(!$isNewObj) - unset($obj); // We do not need this object itself anymore and do not want it re-added to the main array + unset($obj); // We do not need this object itself anymore and do not want it re-added to the main array } else if(ADODB_LAZY_AR == $extra['loading']) { @@ -1382,7 +1382,7 @@ array_push($arrRef[$obj->$dbClassRef]->$foreignName, $obj); } } - + } if(!empty($relations['belongsTo'])) { @@ -1398,7 +1398,7 @@ else { $belongsToId = 'id'; - } + } $origObjsArr = $bTos[$foreignTableRef]; $bTosString = implode(',', array_keys($bTos[$foreignTableRef])); $foreignName = $foreignTable->foreignName; @@ -1418,4 +1418,3 @@ return $arr; } -?> Modified: trunk/lib/WikiDB/adodb/adodb-csvlib.inc.php =================================================================== --- trunk/lib/WikiDB/adodb/adodb-csvlib.inc.php 2014-07-21 09:44:17 UTC (rev 8995) +++ trunk/lib/WikiDB/adodb/adodb-csvlib.inc.php 2014-07-21 12:04:00 UTC (rev 8996) @@ -6,19 +6,19 @@ global $ADODB_INCLUDED_CSV; $ADODB_INCLUDED_CSV = 1; -/* +/* - V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). 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. + V5.19 23-Apr-2014 (c) 2000-2014 John Lim (jlim#natsoft.com). 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. Set tabs to 4 for best viewing. - + Latest version is available at http://adodb.sourceforge.net - - Library for CSV serialization. This is used by the csv/proxy driver and is the - CacheExecute() serialization format. - + + Library for CSV serialization. This is used by the csv/proxy driver and is the + CacheExecute() serialization format. + ==== NOTE ==== Format documented at http://php.weblogs.com/ADODB_CSV ============== @@ -34,61 +34,61 @@ function _rs2serialize(&$rs,$conn=false,$sql='') { $max = ($rs) ? $rs->FieldCount() : 0; - + if ($sql) $sql = urlencode($sql); // metadata setup - + if ($max <= 0 || $rs->dataProvider == 'empty') { // is insert/update/delete if (is_object($conn)) { $sql .= ','.$conn->Affected_Rows(); $sql .= ','.$conn->Insert_ID(); } else $sql .= ',,'; - + $text = "====-1,0,$sql\n"; return $text; } $tt = ($rs->timeCreated) ? $rs->timeCreated : time(); - + ## changed format from ====0 to ====1 $line = "====1,$tt,$sql\n"; - + if ($rs->databaseType == 'array') { $rows = $rs->_array; } else { $rows = array(); - while (!$rs->EOF) { + while (!$rs->EOF) { $rows[] = $rs->fields; $rs->MoveNext(); - } + } } - + for($i=0; $i < $max; $i++) { $o = $rs->FetchField($i); $flds[] = $o; } - + $savefetch = isset($rs->adodbFetchMode) ? $rs->adodbFetchMode : $rs->fetchMode; $class = $rs->connection->a... [truncated message content] |