[Linpha-cvs] SF.net SVN: linpha: [4558] trunk/linpha2
Status: Inactive
Brought to you by:
bzrudi
From: <bz...@us...> - 2006-08-26 12:30:08
|
Revision: 4558 Author: bzrudi Date: 2006-08-26 05:28:52 -0700 (Sat, 26 Aug 2006) ViewCVS: http://svn.sourceforge.net/linpha/?rev=4558&view=rev Log Message: ----------- * fixed broken installation for postgres * replaced all PO_Inserted_ID (does not work with postgres) * update to latest adodb Modified Paths: -------------- trunk/linpha2/ChangeLog trunk/linpha2/install/step11_finish.php trunk/linpha2/install/step8_testing.php trunk/linpha2/lib/adodb/adodb-active-record.inc.php trunk/linpha2/lib/adodb/adodb-csvlib.inc.php trunk/linpha2/lib/adodb/adodb-datadict.inc.php trunk/linpha2/lib/adodb/adodb-error.inc.php trunk/linpha2/lib/adodb/adodb-errorhandler.inc.php trunk/linpha2/lib/adodb/adodb-errorpear.inc.php trunk/linpha2/lib/adodb/adodb-exceptions.inc.php trunk/linpha2/lib/adodb/adodb-iterator.inc.php trunk/linpha2/lib/adodb/adodb-lib.inc.php trunk/linpha2/lib/adodb/adodb-pager.inc.php trunk/linpha2/lib/adodb/adodb-pear.inc.php trunk/linpha2/lib/adodb/adodb-perf.inc.php trunk/linpha2/lib/adodb/adodb-php4.inc.php trunk/linpha2/lib/adodb/adodb-time.inc.php trunk/linpha2/lib/adodb/adodb-xmlschema03.inc.php trunk/linpha2/lib/adodb/adodb.inc.php trunk/linpha2/lib/adodb/drivers/adodb-access.inc.php trunk/linpha2/lib/adodb/drivers/adodb-ado.inc.php trunk/linpha2/lib/adodb/drivers/adodb-ado5.inc.php trunk/linpha2/lib/adodb/drivers/adodb-ado_access.inc.php trunk/linpha2/lib/adodb/drivers/adodb-ado_mssql.inc.php trunk/linpha2/lib/adodb/drivers/adodb-borland_ibase.inc.php trunk/linpha2/lib/adodb/drivers/adodb-csv.inc.php trunk/linpha2/lib/adodb/drivers/adodb-db2.inc.php trunk/linpha2/lib/adodb/drivers/adodb-fbsql.inc.php trunk/linpha2/lib/adodb/drivers/adodb-firebird.inc.php trunk/linpha2/lib/adodb/drivers/adodb-ibase.inc.php trunk/linpha2/lib/adodb/drivers/adodb-informix.inc.php trunk/linpha2/lib/adodb/drivers/adodb-informix72.inc.php trunk/linpha2/lib/adodb/drivers/adodb-ldap.inc.php trunk/linpha2/lib/adodb/drivers/adodb-mssql.inc.php trunk/linpha2/lib/adodb/drivers/adodb-mssqlpo.inc.php trunk/linpha2/lib/adodb/drivers/adodb-mysql.inc.php trunk/linpha2/lib/adodb/drivers/adodb-mysqli.inc.php trunk/linpha2/lib/adodb/drivers/adodb-mysqlt.inc.php trunk/linpha2/lib/adodb/drivers/adodb-netezza.inc.php trunk/linpha2/lib/adodb/drivers/adodb-oci8.inc.php trunk/linpha2/lib/adodb/drivers/adodb-oci805.inc.php trunk/linpha2/lib/adodb/drivers/adodb-oci8po.inc.php trunk/linpha2/lib/adodb/drivers/adodb-odbc.inc.php trunk/linpha2/lib/adodb/drivers/adodb-odbc_db2.inc.php trunk/linpha2/lib/adodb/drivers/adodb-odbc_mssql.inc.php trunk/linpha2/lib/adodb/drivers/adodb-odbc_oracle.inc.php trunk/linpha2/lib/adodb/drivers/adodb-odbtp.inc.php trunk/linpha2/lib/adodb/drivers/adodb-odbtp_unicode.inc.php trunk/linpha2/lib/adodb/drivers/adodb-oracle.inc.php trunk/linpha2/lib/adodb/drivers/adodb-pdo.inc.php trunk/linpha2/lib/adodb/drivers/adodb-pdo_mssql.inc.php trunk/linpha2/lib/adodb/drivers/adodb-pdo_mysql.inc.php trunk/linpha2/lib/adodb/drivers/adodb-pdo_oci.inc.php trunk/linpha2/lib/adodb/drivers/adodb-pdo_pgsql.inc.php trunk/linpha2/lib/adodb/drivers/adodb-postgres.inc.php trunk/linpha2/lib/adodb/drivers/adodb-postgres64.inc.php trunk/linpha2/lib/adodb/drivers/adodb-postgres7.inc.php trunk/linpha2/lib/adodb/drivers/adodb-postgres8.inc.php trunk/linpha2/lib/adodb/drivers/adodb-proxy.inc.php trunk/linpha2/lib/adodb/drivers/adodb-sapdb.inc.php trunk/linpha2/lib/adodb/drivers/adodb-sqlanywhere.inc.php trunk/linpha2/lib/adodb/drivers/adodb-sqlite.inc.php trunk/linpha2/lib/adodb/drivers/adodb-sqlitepo.inc.php trunk/linpha2/lib/adodb/drivers/adodb-sybase.inc.php trunk/linpha2/lib/adodb/drivers/adodb-sybase_ase.inc.php trunk/linpha2/lib/adodb/drivers/adodb-vfp.inc.php trunk/linpha2/lib/adodb/lang/adodb-ar.inc.php trunk/linpha2/lib/adodb/pivottable.inc.php trunk/linpha2/lib/adodb/rsfilter.inc.php trunk/linpha2/lib/adodb/server.php trunk/linpha2/lib/adodb/toexport.inc.php trunk/linpha2/lib/adodb/tohtml.inc.php trunk/linpha2/lib/classes/linpha.image.class.php trunk/linpha2/lib/classes/linpha.import.class.php Modified: trunk/linpha2/ChangeLog =================================================================== --- trunk/linpha2/ChangeLog 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/ChangeLog 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,3 +1,8 @@ +2006-08-26 bzrudi + * fixed broken installation for postgres + * replaced all PO_Inserted_ID (does not work with postgres) + * update to latest adodb + 2006-08-25 flo * add exif autorotate support - db fields time_exif and rotate are saved during import Modified: trunk/linpha2/install/step11_finish.php =================================================================== --- trunk/linpha2/install/step11_finish.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/install/step11_finish.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -63,13 +63,18 @@ { echo failed_msg(); } else { - $userid = $GLOBALS['linpha']->db->PO_Insert_ID(PREFIX."users", "id"); + $userid = $GLOBALS['linpha']->db->GetOne("SELECT MAX(id) FROM ".PREFIX."users "); /** + * fails for pg + */ + //$userid = $GLOBALS['linpha']->db->PO_Insert_ID(PREFIX."users", "id"); + + /** * adding user to group 'admin' */ $data = $GLOBALS['linpha']->db->GetRow("SELECT id FROM ".PREFIX."groups WHERE group_name = 'admin'"); - $GLOBALS['linpha']->db->Execute("INSERT into ".PREFIX."user_group (user_id, group_id) VALUES ('".$userid."','".$data['id']."')"); + $GLOBALS['linpha']->db->Execute("INSERT into ".PREFIX."user_group (user_id, group_id) VALUES ('".$userid['id']."','".$data['id']."')"); echo success_msg(); } Modified: trunk/linpha2/install/step8_testing.php =================================================================== --- trunk/linpha2/install/step8_testing.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/install/step8_testing.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -30,7 +30,7 @@ /** * prevent php notices, as sqlite doesn't know about ports' */ -if(false == isset($_SESSION['sql_port'])) +if(!isset($_SESSION['sql_dbport'])) { $_SESSION['sql_dbport'] = "0"; } Modified: trunk/linpha2/lib/adodb/adodb-active-record.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-active-record.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-active-record.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,7 +1,7 @@ <?php /* -@version V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. +@version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Latest version is available at http://adodb.sourceforge.net Released under both BSD license and Lesser GPL library license. @@ -10,10 +10,14 @@ Active Record implementation. Superset of Zend Framework's. - Version 0.02 + Version 0.04 + + See http://www-128.ibm.com/developerworks/java/library/j-cb03076/?ca=dgr-lnxw01ActiveRecord + for info on Ruby on Rails Active Record implementation */ global $_ADODB_ACTIVE_DBS; +global $ADODB_ACTIVE_CACHESECS; // set to true to enable caching of metadata such as field info // array of ADODB_Active_DB's, indexed by ADODB_Active_Record->_dbat $_ADODB_ACTIVE_DBS = array(); @@ -28,6 +32,7 @@ var $name; // table name var $flds; // assoc array of adofieldobjs, indexed by fieldname var $keys; // assoc array of primary keys, indexed by fieldname + var $_created; // only used when stored as a cached file } // returns index into $_ADODB_ACTIVE_DBS @@ -48,13 +53,15 @@ return sizeof($_ADODB_ACTIVE_DBS)-1; } + class ADODB_Active_Record { var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat] - var $_table; // tablename + 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] var $_where; // where clause set in Load() var $_saved = false; // indicates whether data is already inserted. var $_lasterr = false; // last error message + var $_original = false; // the original values loaded or inserted, refreshed on update // should be static function SetDatabaseAdapter(&$db) @@ -78,8 +85,10 @@ $pkeyarr = false; } - if (!$table) $table = $this->_pluralize(get_class($this)); - + if (!$table) { + if (!empty($this->_table)) $table = $this->_table; + else $table = $this->_pluralize(get_class($this)); + } if ($db) { $this->_dbat = ADODB_Active_Record::SetDatabaseAdapter($db); } else @@ -119,7 +128,7 @@ // update metadata function UpdateActiveTable($pkeys=false,$forceUpdate=false) { - global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS; + global $ADODB_ASSOC_CASE,$_ADODB_ACTIVE_DBS , $ADODB_CACHE_DIR, $ADODB_ACTIVE_CACHESECS; $activedb =& $_ADODB_ACTIVE_DBS[$this->_dbat]; @@ -133,10 +142,27 @@ 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)) { + $fp = fopen($fname,'r'); + @flock($fp, LOCK_SH); + $acttab = unserialize(fread($fp,100000)); + fclose($fp); + 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) { + ADOConnection::outp("Refreshing cached active record file: $fname"); + } + } $activetab = new ADODB_Active_Table(); $activetab->name = $table; - $db =& $activedb->db; $cols = $db->MetaColumns($table); if (!$cols) { @@ -198,6 +224,13 @@ $activetab->keys = $keys; $activetab->flds = $attr; + + if ($ADODB_ACTIVE_CACHESECS && $ADODB_CACHE_DIR) { + $activetab->_created = time(); + $s = serialize($activetab); + if (!function_exists('adodb_write_file')) include(ADODB_DIR.'/adodb-csvlib.inc.php'); + adodb_write_file($fname,$s); + } $activedb->tables[$table] = $activetab; } @@ -289,7 +322,7 @@ $this->$name = $row[$cnt]; $cnt += 1; } - #$this->_original =& $row; + $this->_original = $row; return true; } @@ -375,23 +408,29 @@ $db =& $this->DB(); if (!$db) return false; $cnt = 0; $table =& $this->TableInfo(); + + $valarr = array(); + $names = array(); + $valstr = array(); foreach($table->flds as $name=>$fld) { $val = $this->$name; - /* - if (is_null($val)) { - if (isset($fld->not_null) && $fld->not_null) { - if (isset($fld->default_value) && strlen($fld->default_value)) continue; - else $this->Error("Cannot insert null into $name","Insert"); - } - }*/ - - $valarr[] = $val; - $names[] = $name; - $valstr[] = $db->Param($cnt); - $cnt += 1; + if(!is_null($val) || !array_key_exists($name, $table->keys)) { + $valarr[] = $val; + $names[] = $name; + $valstr[] = $db->Param($cnt); + $cnt += 1; + } } + if (empty($names)){ + foreach($table->flds as $name=>$fld) { + $valarr[] = null; + $names[] = $name; + $valstr[] = $db->Param($cnt); + $cnt += 1; + } + } $sql = 'INSERT INTO '.$this->_table."(".implode(',',$names).') VALUES ('.implode(',',$valstr).')'; $ok = $db->Execute($sql,$valarr); @@ -410,7 +449,7 @@ } } - #$this->_original =& $valarr; + $this->_original = $valarr; return !empty($ok); } @@ -421,9 +460,18 @@ $where = $this->GenWhere($db,$table); $sql = 'DELETE FROM '.$this->_table.' WHERE '.$where; - $db->Execute($sql); + $ok = $db->Execute($sql); + + return $ok ? true : false; } + // returns an array of active record objects + function &Find($whereOrderBy,$bindarr=false,$pkeysArr=false) + { + $db =& $this->DB(); if (!$db || empty($this->_table)) return false; + $arr =& $db->GetActiveRecordsClass(get_class($this),$this->_table, $whereOrderBy,$bindarr,$pkeysArr); + return $arr; + } // returns 0 on error, 1 on update, 2 on insert function Replace() @@ -447,6 +495,9 @@ } } }*/ + if (is_null($val) && !empty($fld->auto_increment)) { + continue; + } $t = $db->MetaType($fld->type); $arr[$name] = $this->doquote($db,$val,$t); $valarr[] = $val; @@ -479,12 +530,12 @@ } } - #$this->_original =& $valarr; + $this->_original =& $valarr; } return $ok; } - // returns false on error + // returns 0 on error, 1 on update, -1 if no change in data (no update) function Update() { $db =& $this->DB(); if (!$db) return false; @@ -496,12 +547,20 @@ $this->error("Where missing for table $table", "Update"); return false; } + $valarr = array(); + $neworig = array(); + $pairs = array(); + $i = -1; $cnt = 0; foreach($table->flds as $name=>$fld) { - if (isset($table->keys[$name])) continue; - + $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; @@ -511,17 +570,24 @@ } } } + + if (isset($this->_original[$i]) && $val == $this->_original[$i]) { + continue; + } $valarr[] = $val; $pairs[] = $name.'='.$db->Param($cnt); $cnt += 1; } - #$this->_original =& $valarr; + if (!$cnt) return -1; $sql = 'UPDATE '.$this->_table." SET ".implode(",",$pairs)." WHERE ".$where; $ok = $db->Execute($sql,$valarr); - - return !empty($ok); + if ($ok) { + $this->_original =& $neworig; + return 1; + } + return 0; } function GetAttributeNames() Modified: trunk/linpha2/lib/adodb/adodb-csvlib.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-csvlib.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-csvlib.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -8,7 +8,7 @@ /* - V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + V4.91 2 Aug 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. See License.txt. Modified: trunk/linpha2/lib/adodb/adodb-datadict.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-datadict.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-datadict.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,7 +1,7 @@ <?php /** - V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-error.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-error.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-error.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /** - * @version V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + * @version V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-errorhandler.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-errorhandler.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-errorhandler.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /** - * @version V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + * @version V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-errorpear.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-errorpear.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-errorpear.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /** - * @version V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + * @version V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-exceptions.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-exceptions.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-exceptions.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,7 +1,7 @@ <?php /** - * @version V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + * @version V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-iterator.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-iterator.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-iterator.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,7 +1,7 @@ <?php /* - V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-lib.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-lib.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-lib.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -7,7 +7,7 @@ $ADODB_INCLUDED_LIB = 1; /* - @version V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim\@natsoft.com.my). All rights reserved. + @version V4.91 2 Aug 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. See License.txt. @@ -156,7 +156,7 @@ if ($fieldsize > 2) { $group = rtrim($zthis->fields[2]); } - +/* if ($optgroup != $group) { $optgroup = $group; if ($firstgroup) { @@ -167,7 +167,7 @@ $s .="\n<optgroup label='". htmlspecialchars($group) ."'>"; } } - +*/ if ($hasvalue) $value = " value='".htmlspecialchars($zval2)."'"; @@ -325,6 +325,8 @@ $rewritesql = preg_replace( '/^\s*SELECT\s.*\s+FROM\s/Uis','SELECT COUNT(*) FROM ',$sql); + + // fix by alexander zhukov, alex#unipack.ru, because count(*) and 'order by' fails // with mssql, access and postgresql. Also a good speedup optimization - skips sorting! // also see http://phplens.com/lens/lensforum/msgs.php?id=12752 @@ -332,10 +334,13 @@ $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$rewritesql); else $rewritesql = preg_replace('/(\sORDER\s+BY\s[^)]*)/is','',$rewritesql); - } + + if (isset($rewritesql) && $rewritesql != $sql) { + if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[1]; + if ($secs2cache) { // we only use half the time of secs2cache because the count can quickly // become inaccurate if new records are added @@ -354,6 +359,8 @@ if (preg_match('/\s*UNION\s*/is', $sql)) $rewritesql = $sql; else $rewritesql = preg_replace('/(\sORDER\s+BY\s.*)/is','',$sql); + if (preg_match('/\sLIMIT\s+[0-9]+/i',$sql,$limitarr)) $rewritesql .= $limitarr[0]; + $rstest = &$zthis->Execute($rewritesql,$inputarr); if (!$rstest) $rstest = $zthis->Execute($sql,$inputarr); @@ -1017,5 +1024,47 @@ return $s; } +/* +function _adodb_find_from($sql) +{ + $sql = str_replace(array("\n","\r"), ' ', $sql); + $charCount = strlen($sql); + + $inString = false; + $quote = ''; + $parentheseCount = 0; + $prevChars = ''; + $nextChars = ''; + + + for($i = 0; $i < $charCount; $i++) { + + $char = substr($sql,$i,1); + $prevChars = substr($sql,0,$i); + $nextChars = substr($sql,$i+1); + + if((($char == "'" || $char == '"' || $char == '`') && substr($prevChars,-1,1) != '\\') && $inString === false) { + $quote = $char; + $inString = true; + } + + elseif((($char == "'" || $char == '"' || $char == '`') && substr($prevChars,-1,1) != '\\') && $inString === true && $quote == $char) { + $quote = ""; + $inString = false; + } + + elseif($char == "(" && $inString === false) + $parentheseCount++; + + elseif($char == ")" && $inString === false && $parentheseCount > 0) + $parentheseCount--; + + elseif($parentheseCount <= 0 && $inString === false && $char == " " && strtoupper(substr($prevChars,-5,5)) == " FROM") + return $i; + + } +} +*/ + ?> \ No newline at end of file Modified: trunk/linpha2/lib/adodb/adodb-pager.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-pager.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-pager.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,7 +1,7 @@ <?php /* - V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-pear.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-pear.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-pear.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /** - * @version V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + * @version V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-perf.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-perf.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-perf.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /* -V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. +V4.91 2 Aug 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. See License.txt. @@ -71,7 +71,7 @@ $rs =& $conn->Execute($sql,$inputarr); $t1 = microtime(); - if (!empty($conn->_logsql)) { + if (!empty($conn->_logsql) && (empty($conn->_logsqlErrors) || !$rs)) { $conn->_logsql = false; // disable logsql error simulation $dbT = $conn->databaseType; @@ -149,6 +149,7 @@ if ($dbT == 'informix') $isql = str_replace(chr(10),' ',$isql); $arr = false; } else { + if ($dbT == 'db2') $arr['f'] = (float) $arr['f']; $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)"; } @@ -860,8 +861,10 @@ { if (!$this->createTableSQL) return false; + $table = $this->table(); + $sql = str_replace('adodb_logsql',$table,$this->createTableSQL); $savelog = $this->conn->LogSQL(false); - $ok = $this->conn->Execute($this->createTableSQL); + $ok = $this->conn->Execute($sql); $this->conn->LogSQL($savelog); return ($ok) ? true : false; } Modified: trunk/linpha2/lib/adodb/adodb-php4.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-php4.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-php4.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,7 +1,7 @@ <?php /* - V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. + V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/adodb-time.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-time.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-time.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -241,6 +241,9 @@ CHANGELOG +- 19 March 2006 0.24 +Changed strftime() locale detection, because some locales prepend the day of week to the date when %c is used. + - 10 Feb 2006 0.23 PHP5 compat: when we detect PHP5, the RFC2822 format for gmt 0000hrs is changed from -0000 to +0000. In PHP4, we will still use -0000 for 100% compat with PHP4. @@ -365,7 +368,7 @@ /* Version Number */ -define('ADODB_DATE_VERSION',0.23); +define('ADODB_DATE_VERSION',0.24); /* This code was originally for windows. But apparently this problem happens @@ -1239,9 +1242,16 @@ } if (empty($ADODB_DATE_LOCALE)) { + /* $tstr = strtoupper(gmstrftime('%c',31366800)); // 30 Dec 1970, 1 am $sep = substr($tstr,2,1); $hasAM = strrpos($tstr,'M') !== false; + */ + # see http://phplens.com/lens/lensforum/msgs.php?id=14865 for reasoning, and changelog for version 0.24 + $dstr = gmstrftime('%x',31366800); // 30 Dec 1970, 1 am + $sep = substr($dstr,2,1); + $tstr = strtoupper(gmstrftime('%X',31366800)); // 30 Dec 1970, 1 am + $hasAM = strrpos($tstr,'M') !== false; $ADODB_DATE_LOCALE = array(); $ADODB_DATE_LOCALE[] = strncmp($tstr,'30',2) == 0 ? 'd'.$sep.'m'.$sep.'y' : 'm'.$sep.'d'.$sep.'y'; Modified: trunk/linpha2/lib/adodb/adodb-xmlschema03.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb-xmlschema03.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb-xmlschema03.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -2092,16 +2092,20 @@ * in the schema. * * @param boolean $data Include data in schema dump + * @indent string indentation to use + * @prefix string extract only tables with given prefix + * @stripprefix strip prefix string when storing in XML schema * @return string Generated XML schema */ - function ExtractSchema( $data = FALSE, $indent = ' ' ) { + function ExtractSchema( $data = FALSE, $indent = ' ', $prefix = '' , $stripprefix=false) { $old_mode = $this->db->SetFetchMode( ADODB_FETCH_NUM ); $schema = '<?xml version="1.0"?>' . "\n" . '<schema version="' . $this->schemaVersion . '">' . "\n"; - if( is_array( $tables = $this->db->MetaTables( 'TABLES' ) ) ) { + if( is_array( $tables = $this->db->MetaTables( 'TABLES' , ($prefix) ? $prefix.'%' : '') ) ) { foreach( $tables as $table ) { + if ($stripprefix) $table = str_replace(str_replace('\\_', '_', $pfx ), '', $table); $schema .= $indent . '<table name="' . htmlentities( $table ) . '">' . "\n"; // grab details from database Modified: trunk/linpha2/lib/adodb/adodb.inc.php =================================================================== --- trunk/linpha2/lib/adodb/adodb.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/adodb.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -14,7 +14,7 @@ /** \mainpage - @version V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. + @version V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Released under both BSD license and Lesser GPL library license. You can choose which license you prefer. @@ -171,7 +171,7 @@ /** * ADODB version as a string. */ - $ADODB_vers = 'V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.'; + $ADODB_vers = 'V4.91 2 Aug 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.'; /** * Determines whether recordset->RecordCount() is used. @@ -314,6 +314,7 @@ var $_evalAll = false; var $_affected = false; var $_logsql = false; + var $_transmode = ''; // transaction mode /** * Constructor @@ -553,6 +554,7 @@ function q(&$s) { + #if (!empty($this->qNull)) if ($s == 'null') return $s; $s = $this->qstr($s,false); } @@ -822,7 +824,10 @@ $sql .= str_replace(',','.',$v); // locales fix so 1.1 does not get converted to 1,1 else if ($typ == 'boolean') $sql .= $v ? $this->true : $this->false; - else if ($v === null) + else if ($typ == 'object') { + if (method_exists($v, '__toString')) $sql .= $this->qstr($v->__toString()); + else $sql .= $this->qstr((string) $v); + } else if ($v === null) $sql .= 'NULL'; else $sql .= $v; @@ -864,7 +869,7 @@ { if ($this->debug) { global $ADODB_INCLUDED_LIB; - if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); + if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); $this->_queryID = _adodb_debug_execute($this, $sql,$inputarr); } else { $this->_queryID = @$this->_query($sql,$inputarr); @@ -1110,7 +1115,7 @@ $sql = preg_replace( '/(^\s*select\s+(distinctrow|distinct)?)/i','\\1 '.$this->hasTop.' '.((integer)$nrows).' ',$sql); - if ($secs2cache>0) { + if ($secs2cache >= 0) { $ret =& $this->CacheExecute($secs2cache, $sql,$inputarr); } else { $ret =& $this->Execute($sql,$inputarr); @@ -1143,10 +1148,10 @@ $ADODB_COUNTRECS = false; if ($offset>0){ - if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); + if ($secs2cache >= 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); else $rs = &$this->Execute($sql,$inputarr); } else { - if ($secs2cache>0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); + if ($secs2cache >= 0) $rs = &$this->CacheExecute($secs2cache,$sql,$inputarr); else $rs = &$this->Execute($sql,$inputarr); } $ADODB_COUNTRECS = $savec; @@ -1343,7 +1348,6 @@ return '('.$date.'+'.$dayFraction.')'; } - /** * * @param sql SQL statement @@ -1461,7 +1465,7 @@ function Replace($table, $fieldArray, $keyCol, $autoQuote=false, $has_autoinc=false) { global $ADODB_INCLUDED_LIB; - if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); + if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); return _adodb_replace($this, $table, $fieldArray, $keyCol, $autoQuote, $has_autoinc); } @@ -1528,7 +1532,7 @@ } global $ADODB_INCLUDED_CSV; - if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); + if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php'); $f = $this->_gencachename($sql.serialize($inputarr),false); adodb_write_file($f,''); // is adodb_write_file needed? @@ -1580,7 +1584,7 @@ } global $ADODB_INCLUDED_CSV; - if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); + if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php'); $f = $this->_gencachename($sql.serialize($inputarr),false); adodb_write_file($f,''); // is adodb_write_file needed? @@ -1655,7 +1659,7 @@ $sqlparam = $sql; global $ADODB_INCLUDED_CSV; - if (empty($ADODB_INCLUDED_CSV)) include_once(ADODB_DIR.'/adodb-csvlib.inc.php'); + if (empty($ADODB_INCLUDED_CSV)) include(ADODB_DIR.'/adodb-csvlib.inc.php'); $md5file = $this->_gencachename($sql.serialize($inputarr),true); $err = ''; @@ -1731,15 +1735,16 @@ */ function& AutoExecute($table, $fields_values, $mode = 'INSERT', $where = FALSE, $forceUpdate=true, $magicq=false) { + $false = false; $sql = 'SELECT * FROM '.$table; if ($where!==FALSE) $sql .= ' WHERE '.$where; else if ($mode == 'UPDATE' || $mode == 2 /* DB_AUTOQUERY_UPDATE */) { ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause'); - return false; + return $false; } $rs =& $this->SelectLimit($sql,1); - if (!$rs) return false; // table does not exist + if (!$rs) return $false; // table does not exist $rs->tableName = $table; switch((string) $mode) { @@ -1753,7 +1758,7 @@ break; default: ADOConnection::outp("AutoExecute: Unknown mode=$mode"); - return false; + return $false; } $ret = false; if ($sql) $ret = $this->Execute($sql); @@ -1786,7 +1791,7 @@ } //********************************************************// - if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); + if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); return _adodb_getupdatesql($this,$rs,$arrFields,$forceUpdate,$magicq,$force); } @@ -1806,7 +1811,7 @@ $force = $ADODB_FORCE_TYPE; } - if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); + if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); return _adodb_getinsertsql($this,$rs,$arrFields,$magicq,$force); } @@ -1973,7 +1978,7 @@ if (!isset($_ADODB_ACTIVE_DBS)) { - include_once(ADODB_DIR.'/adodb-active-record.inc.php'); + include(ADODB_DIR.'/adodb-active-record.inc.php'); } if (!class_exists($class)) { ADOConnection::outp("Unknown class $class in GetActiveRcordsClass()"); @@ -2016,6 +2021,57 @@ */ function BeginTrans() {return false;} + /* set transaction mode */ + function SetTransactionMode( $transaction_mode ) + { + $transaction_mode = $this->MetaTransaction($transaction_mode, $this->dataProvider); + $this->_transmode = $transaction_mode; + } +/* +http://msdn2.microsoft.com/en-US/ms173763.aspx +http://dev.mysql.com/doc/refman/5.0/en/innodb-transaction-isolation.html +http://www.postgresql.org/docs/8.1/interactive/sql-set-transaction.html +http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10759/statements_10005.htm +*/ + function MetaTransaction($mode,$db) + { + $mode = strtoupper($mode); + $mode = str_replace('ISOLATION LEVEL ','',$mode); + + switch($mode) { + + case 'READ UNCOMMITTED': + switch($db) { + case 'oci8': + case 'oracle': + return 'ISOLATION LEVEL READ COMMITTED'; + default: + return 'ISOLATION LEVEL READ UNCOMMITTED'; + } + break; + + case 'READ COMMITTED': + return 'ISOLATION LEVEL READ COMMITTED'; + break; + + case 'REPEATABLE READ': + switch($db) { + case 'oci8': + case 'oracle': + return 'ISOLATION LEVEL SERIALIZABLE'; + default: + return 'ISOLATION LEVEL REPEATABLE READ'; + } + break; + + case 'SERIALIZABLE': + return 'ISOLATION LEVEL SERIALIZABLE'; + break; + + default: + return $mode; + } + } /** * If database does not support transactions, always return true as data always commited @@ -2207,7 +2263,7 @@ * * @return array of column names for current table. */ - function &MetaColumnNames($table, $numIndexes=false) + function &MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */) { $objarr =& $this->MetaColumns($table); if (!is_array($objarr)) { @@ -2217,7 +2273,12 @@ $arr = array(); if ($numIndexes) { $i = 0; - foreach($objarr as $v) $arr[$i++] = $v->name; + if ($useattnum) { + foreach($objarr as $v) + $arr[$v->attnum] = $v->name; + + } else + foreach($objarr as $v) $arr[$i++] = $v->name; } else foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name; @@ -2261,7 +2322,23 @@ return adodb_date($this->fmtDate,$d); } + function BindDate($d) + { + $d = $this->DBDate($d); + if (strncmp($d,"'",1)) return $d; + + return substr($d,1,strlen($d)-2); + } + function BindTimeStamp($d) + { + $d = $this->DBTimeStamp($d); + if (strncmp($d,"'",1)) return $d; + + return substr($d,1,strlen($d)-2); + } + + /** * Converts a timestamp "ts" to a string that the database can understand. * @@ -2446,7 +2523,7 @@ /** * Will select the supplied $page number from a recordset, given that it is paginated in pages of * $nrows rows per page. It also saves two boolean values saying if the given page is the first - * and/or last one of the recordset. Added by Iv\xE1n Oliva to provide recordset pagination. + * and/or last one of the recordset. Added by Iv�n Oliva to provide recordset pagination. * * See readme.htm#ex8 for an example of usage. * @@ -2463,7 +2540,7 @@ function &PageExecute($sql, $nrows, $page, $inputarr=false, $secs2cache=0) { global $ADODB_INCLUDED_LIB; - if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); + if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); if ($this->pageExecuteCountRows) $rs =& _adodb_pageexecute_all_rows($this, $sql, $nrows, $page, $inputarr, $secs2cache); else $rs =& _adodb_pageexecute_no_last_page($this, $sql, $nrows, $page, $inputarr, $secs2cache); return $rs; @@ -2473,7 +2550,7 @@ /** * Will select the supplied $page number from a recordset, given that it is paginated in pages of * $nrows rows per page. It also saves two boolean values saying if the given page is the first - * and/or last one of the recordset. Added by Iv\xE1n Oliva to provide recordset pagination. + * and/or last one of the recordset. Added by Iv�n Oliva to provide recordset pagination. * * @param secs2cache seconds to cache data, set to 0 to force query * @param sql @@ -2535,7 +2612,7 @@ //============================================================================================== // DATE AND TIME FUNCTIONS //============================================================================================== - include_once(ADODB_DIR.'/adodb-time.inc.php'); + if (!defined('ADODB_DATE_VERSION')) include(ADODB_DIR.'/adodb-time.inc.php'); //============================================================================================== // CLASS ADORecordSet @@ -2581,9 +2658,9 @@ var $_obj; /** Used by FetchObj */ var $_names; /** Used by FetchObj */ - var $_currentPage = -1; /** Added by Iv\xE1n Oliva to implement recordset pagination */ - var $_atFirstPage = false; /** Added by Iv\xE1n Oliva to implement recordset pagination */ - var $_atLastPage = false; /** Added by Iv\xE1n Oliva to implement recordset pagination */ + var $_currentPage = -1; /** Added by Iv�n Oliva to implement recordset pagination */ + var $_atFirstPage = false; /** Added by Iv�n Oliva to implement recordset pagination */ + var $_atLastPage = false; /** Added by Iv�n Oliva to implement recordset pagination */ var $_lastPageNo = -1; var $_maxRecordCount = 0; var $datetime = false; @@ -2646,7 +2723,7 @@ $size=0, $selectAttr='',$compareFields0=true) { global $ADODB_INCLUDED_LIB; - if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); + if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); return _adodb_getmenu($this, $name,$defstr,$blank1stItem,$multiple, $size, $selectAttr,$compareFields0); } @@ -2673,7 +2750,7 @@ $size=0, $selectAttr='') { global $ADODB_INCLUDED_LIB; - if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); + if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); return _adodb_getmenu_gp($this, $name,$defstr,$blank1stItem,$multiple, $size, $selectAttr,false); } @@ -2790,7 +2867,17 @@ if ($ADODB_EXTENSION) { if ($numIndex) { while (!$this->EOF) { - $results[trim($this->fields[0])] = array_slice($this->fields, 1); + // $results[trim($this->fields[0])] = array_slice($this->fields, 1); + // Fix for array_slice re-numbering numeric associative keys in PHP5 + $keys = array_slice(array_keys($this->fields), 1); + $sliced_array = array(); + + foreach($keys as $key) { + $sliced_array[$key] = $this->fields[$key]; + } + + $results[trim(reset($this->fields))] = $sliced_array; + adodb_movenext($this); } } else { @@ -2802,7 +2889,16 @@ } else { if ($numIndex) { while (!$this->EOF) { - $results[trim($this->fields[0])] = array_slice($this->fields, 1); + //$results[trim($this->fields[0])] = array_slice($this->fields, 1); + // Fix for array_slice re-numbering numeric associative keys in PHP5 + $keys = array_slice(array_keys($this->fields), 1); + $sliced_array = array(); + + foreach($keys as $key) { + $sliced_array[$key] = $this->fields[$key]; + } + + $results[trim(reset($this->fields))] = $sliced_array; $this->MoveNext(); } } else { @@ -3360,6 +3456,7 @@ 'BPCHAR' => 'C', 'CHARACTER' => 'C', 'INTERVAL' => 'C', # Postgres + 'MACADDR' => 'C', # postgres ## 'LONGCHAR' => 'X', 'TEXT' => 'X', @@ -3386,6 +3483,7 @@ 'DATETIME' => 'T', 'TIMESTAMPTZ' => 'T', 'T' => 'T', + 'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql ## 'BOOL' => 'L', 'BOOLEAN' => 'L', @@ -3952,7 +4050,7 @@ $path = ADODB_DIR."/datadict/datadict-$drivername.inc.php"; if (!file_exists($path)) { - ADOConnection::outp("Database driver '$path' not available"); + ADOConnection::outp("Dictionary driver '$path' not available"); return $false; } include_once($path); @@ -3998,7 +4096,7 @@ function adodb_backtrace($printOrArr=true,$levels=9999) { global $ADODB_INCLUDED_LIB; - if (empty($ADODB_INCLUDED_LIB)) include_once(ADODB_DIR.'/adodb-lib.inc.php'); + if (empty($ADODB_INCLUDED_LIB)) include(ADODB_DIR.'/adodb-lib.inc.php'); return _adodb_backtrace($printOrArr,$levels); } Modified: trunk/linpha2/lib/adodb/drivers/adodb-access.inc.php =================================================================== --- trunk/linpha2/lib/adodb/drivers/adodb-access.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/drivers/adodb-access.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /* -V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. +V4.91 2 Aug 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. See License.txt. Modified: trunk/linpha2/lib/adodb/drivers/adodb-ado.inc.php =================================================================== --- trunk/linpha2/lib/adodb/drivers/adodb-ado.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/drivers/adodb-ado.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /* -V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. +V4.91 2 Aug 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. @@ -263,6 +263,7 @@ $this->transCnt += 1; return true; } + function CommitTrans($ok=true) { if (!$ok) return $this->RollbackTrans(); @@ -283,7 +284,9 @@ function ErrorMsg() { + if (!$this->_connectionID) return "No connection established"; $errc = $this->_connectionID->Errors; + if (!$errc) return "No Errors object found"; if ($errc->Count == 0) return ''; $err = $errc->Item($errc->Count-1); return $err->Description; Modified: trunk/linpha2/lib/adodb/drivers/adodb-ado5.inc.php =================================================================== --- trunk/linpha2/lib/adodb/drivers/adodb-ado5.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/drivers/adodb-ado5.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /* -V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. +V4.91 2 Aug 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. @@ -58,8 +58,22 @@ // you can also pass a connection string like this: // // $DB->Connect('USER ID=sa;PASSWORD=pwd;SERVER=mangrove;DATABASE=ai',false,false,'SQLOLEDB'); - function _connect($argHostname, $argUsername, $argPassword, $argProvider= 'MSDASQL') + function _connect($argHostname, $argUsername, $argPassword,$argDBorProvider, $argProvider= '') { + // two modes + // - if $argProvider is empty, we assume that $argDBorProvider holds provider -- this is for backward compat + // - if $argProvider is not empty, then $argDBorProvider holds db + + + if ($argProvider) { + $argDatabasename = $argDBorProvider; + } else { + $argDatabasename = ''; + if ($argDBorProvider) $argProvider = $argDBorProvider; + else $argProvider = 'MSDASQL'; + } + + try { $u = 'UID'; $p = 'PWD'; @@ -86,7 +100,11 @@ $argProvider = "Microsoft.Jet.OLEDB.4.0"; // Microsoft Jet Provider if ($argProvider) $dbc->Provider = $argProvider; + + if ($argProvider) $argHostname = "PROVIDER=$argProvider;DRIVER={SQL Server};SERVER=$argHostname"; + + if ($argDatabasename) $argHostname .= ";DATABASE=$argDatabasename"; if ($argUsername) $argHostname .= ";$u=$argUsername"; if ($argPassword)$argHostname .= ";$p=$argPassword"; @@ -205,9 +223,6 @@ return $arr; } - - - /* returns queryID or false */ function &_query($sql,$inputarr=false) { @@ -216,6 +231,9 @@ $dbc = $this->_connectionID; // return rs + + $false = false; + if ($inputarr) { if (!empty($this->charPage)) @@ -236,22 +254,25 @@ $p = false; $rs = $oCmd->Execute(); $e = $dbc->Errors; - if ($dbc->Errors->Count > 0) return false; + if ($dbc->Errors->Count > 0) return $false; return $rs; } $rs = @$dbc->Execute($sql,$this->_affectedRows, $this->_execute_option); - if ($dbc->Errors->Count > 0) return false; - if (! $rs) return false; + if ($dbc->Errors->Count > 0) return $false; + if (! $rs) return $false; - if ($rs->State == 0) return true; // 0 = adStateClosed means no records returned + if ($rs->State == 0) { + $true = true; + return $true; // 0 = adStateClosed means no records returned + } return $rs; } catch (exception $e) { } - return false; + return $false; } @@ -290,10 +311,18 @@ function ErrorMsg() { - $errc = $this->_connectionID->Errors; - if ($errc->Count == 0) return ''; - $err = $errc->Item($errc->Count-1); - return $err->Description; + if (!$this->_connectionID) return "No connection established"; + $errmsg = ''; + + try { + $errc = $this->_connectionID->Errors; + if (!$errc) return "No Errors object found"; + if ($errc->Count == 0) return ''; + $err = $errc->Item($errc->Count-1); + $errmsg = $err->Description; + }catch(exception $e) { + } + return $errmsg; } function ErrorNo() Modified: trunk/linpha2/lib/adodb/drivers/adodb-ado_access.inc.php =================================================================== --- trunk/linpha2/lib/adodb/drivers/adodb-ado_access.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/drivers/adodb-ado_access.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /* -V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. +V4.91 2 Aug 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. See License.txt. Modified: trunk/linpha2/lib/adodb/drivers/adodb-ado_mssql.inc.php =================================================================== --- trunk/linpha2/lib/adodb/drivers/adodb-ado_mssql.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/drivers/adodb-ado_mssql.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /* -V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. +V4.91 2 Aug 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. @@ -11,8 +11,8 @@ Microsoft SQL Server ADO data driver. Requires ADO and MSSQL client. Works only on MS Windows. - It is normally better to use the mssql driver directly because it is much faster. - This file is only a technology demonstration and for test purposes. + Warning: Some versions of PHP (esp PHP4) leak memory when ADO/COM is used. + Please check http://bugs.php.net/ for more info. */ // security - hide paths @@ -53,6 +53,17 @@ return $this->GetOne('select @@rowcount'); } + function SetTransactionMode( $transaction_mode ) + { + $this->_transmode = $transaction_mode; + if (empty($transaction_mode)) { + $this->Execute('SET TRANSACTION ISOLATION LEVEL READ COMMITTED'); + return; + } + if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode; + $this->Execute("SET TRANSACTION ".$transaction_mode); + } + function MetaColumns($table) { $table = strtoupper($table); @@ -84,6 +95,44 @@ return empty($arr) ? $false : $arr; } + function CreateSequence($seq='adodbseq',$start=1) + { + + $this->Execute('BEGIN TRANSACTION adodbseq'); + $start -= 1; + $this->Execute("create table $seq (id float(53))"); + $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); + if (!$ok) { + $this->Execute('ROLLBACK TRANSACTION adodbseq'); + return false; + } + $this->Execute('COMMIT TRANSACTION adodbseq'); + return true; + } + + function GenID($seq='adodbseq',$start=1) + { + //$this->debug=1; + $this->Execute('BEGIN TRANSACTION adodbseq'); + $ok = $this->Execute("update $seq with (tablock,holdlock) set id = id + 1"); + if (!$ok) { + $this->Execute("create table $seq (id float(53))"); + $ok = $this->Execute("insert into $seq with (tablock,holdlock) values($start)"); + if (!$ok) { + $this->Execute('ROLLBACK TRANSACTION adodbseq'); + return false; + } + $this->Execute('COMMIT TRANSACTION adodbseq'); + return $start; + } + $num = $this->GetOne("select id from $seq"); + $this->Execute('COMMIT TRANSACTION adodbseq'); + return $num; + + // in old implementation, pre 1.90, we returned GUID... + //return $this->GetOne("SELECT CONVERT(varchar(255), NEWID()) AS 'Char'"); + } + } // end class class ADORecordSet_ado_mssql extends ADORecordSet_ado { Modified: trunk/linpha2/lib/adodb/drivers/adodb-borland_ibase.inc.php =================================================================== --- trunk/linpha2/lib/adodb/drivers/adodb-borland_ibase.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/drivers/adodb-borland_ibase.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /* -V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. +V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/drivers/adodb-csv.inc.php =================================================================== --- trunk/linpha2/lib/adodb/drivers/adodb-csv.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/drivers/adodb-csv.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,6 +1,6 @@ <?php /* -V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jl...@na...). All rights reserved. +V4.91 2 Aug 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. Modified: trunk/linpha2/lib/adodb/drivers/adodb-db2.inc.php =================================================================== --- trunk/linpha2/lib/adodb/drivers/adodb-db2.inc.php 2006-08-25 21:29:33 UTC (rev 4557) +++ trunk/linpha2/lib/adodb/drivers/adodb-db2.inc.php 2006-08-26 12:28:52 UTC (rev 4558) @@ -1,13 +1,15 @@ <?php /* - V4.80 8 Mar 2006 (c) 2006 John Lim (jl...@na...). All rights reserved. + V4.91 2 Aug 2006 (c) 2006 John Lim (jlim#natsoft.com.my). All rights reserved. -This is a version of the ADODB driver for DB2. It uses the 'ibm_db2' PECL extension for PHP - (http://pecl.php.net/package/ibm_db2), which in turn requires DB2 V8.2.2. + This is a version of the ADODB driver for DB2. It uses the 'ibm_db2' PECL extension + for PHP (http://pecl.php.net/package/ibm_db2), which in turn requires DB2 V8.2.2 or + higher. - Tested with PHP 5.1.1 and Apache 2.0.55 on Windows XP SP2. + Originally tested with PHP 5.1.1 and Apache 2.0.55 on Windows XP SP2. + More recently tested with PHP 5.1.2 and Apache 2.0.55 on Windows XP SP2. - This file was ported from "adodb-odbc.inc.php" by Larry Menard, "lar...@ro...". + This file was ported from "adodb-odbc.inc.php" by Larry Menard, "larry.menard#rogers.com". I ripped out what I believed to be a lot of redundant or obsolete code, but there are probably still some remnants of the ODBC support in this file; I'm relying on reviewers of this code to point out any other things that can be removed. @@ -25,7 +27,13 @@ class ADODB_db2 extends ADOConnection { var $databaseType = "db2"; var $fmtDate = "'Y-m-d'"; - var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; + var $concat_operator = '||'; + + var $sysTime = 'CURRENT TIME'; + var $sysDate = 'CURRENT DATE'; + var $sysTimeStamp = 'CURRENT TIMESTAMP'; + + var $fmtTimeStamp = "'Y-m-d-H.i.s'"; var $replaceQuote = "''"; // string to use to replace quotes var $dataProvider = "db2"; var $hasAffectedRows = true; @@ -35,12 +43,20 @@ var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive // breaking backward-compat var $_bindInputArray = false; - var $_genSeqSQL = "create table %s (id integer)"; + var $_genIDSQL = "VALUES NEXTVAL FOR %s"; + var $_genSeqSQL = "CREATE SEQUENCE %s START WITH 1 NO MAXVALUE NO CYCLE"; + var $_dropSeqSQL = "DROP SEQUENCE %s"; var $_autocommit = true; var $_haserrorfunctions = true; var $_lastAffectedRows = 0; var $uCaseTables = true; // for meta* functions, uppercase table names + var $hasInsertID = true; + function _insertid() + { + return ADOConnection::GetOne('VALUES IDENTITY_VAL_LOCAL()'); + } + function ADODB_db2() { $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050; @@ -69,7 +85,8 @@ // For db2_connect(), there is an optional 4th arg. If present, it must be // an array of valid options. So far, we don't use them. - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $this->_errorMsg = @db2_conn_errormsg(); + if (isset($this->connectStmt)) $this->Execute($this->connectStmt); return $this->_connectionID != false; @@ -96,7 +113,7 @@ } if (isset($php_errormsg)) $php_errormsg = ''; - $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : ''; + $this->_errorMsg = @db2_conn_errormsg(); if ($this->_connectionID && $this->autoRollback) @db2_rollback($this->_connectionID); if (isset($this->connectStmt)) $this->Execute($this->connectStmt); @@ -104,6 +121,61 @@ } + // Format date column in sql string given an input format that understands Y M D + function SQLDate($fmt, $col=false) + { + // use right() and replace() ? + if (!$col) $col = $this->sysDate; + $s = ''; + + $len = strlen($fmt); + for ($i=0; $i < $len; $i++) { + if ($s) $s .= $this->concat_operator; + $ch = $fmt[$i]; + switch($ch) { + case 'Y': + case 'y': + $s .= "char(year($col))"; + break; + case 'M': + $s .= "substr(monthname($col),1,3)"; + break; + case 'm': + $s .= "right(digits(month($col)),2)"; + break; + case 'D': + case 'd': + $s .= "right(digits(day($col)),2)"; + break; + case 'H': + case 'h': + if ($col != $this->sysDate) $s .= "right(digits(hour($col)),2)"; + else $s .= "''"; + break; + case 'i': + case 'I': + if ($col != $this->sysDate) + $s .= "right(digits(minute($col)),2)"; + else $s .= "''"; + break; + case 'S': + case 's': + if ($col != $this->sysDate) + $s .= "right(digits(second($col)),2)"; + else $s .= "''"; + break; + default: + if ($ch == '\\') { + $i++; + $ch = substr($fmt,$i,1); + } + $s .= $this->qstr($ch); + } + } + return $s; + } + + function ServerInfo() { @@ -139,11 +211,9 @@ if (empty($this->_genSeqSQL)) return false; $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname)); if (!$ok) return false; - $start -= 1; - return $this->Execute("insert into $seqname values($start)"); + return true; } - var $_dropSeqSQL = 'drop table %s'; function DropSequence($seqname) { if (empty($this->_dropSeqSQL)) return false; @@ -160,37 +230,17 @@ { // if you have to modify the parameter below, your database is overloaded, // or you need to implement generation of id's yourself! - $MAXLOOPS = 100; - while (--$MAXLOOPS>=0) { - $num = $this->GetOne("select id from $seq"); - if ($num === false) { - $this->Execute(sprintf($this->_genSeqSQL ,$seq)); - $start -= 1; - $num = '0'; - $ok = $this->Execute("insert into $seq values($start)"); - if (!$ok) return false; - } - $this->Execute("update $seq set id=id+1 where id=$num"); - - if ($this->affected_rows() > 0) { - $num += 1; - $this->genID = $num; + $num = $this->GetOne("VALUES NEXTVAL FOR $seq"); return $num; } - } - if ($fn = $this->raiseErrorFn) { - $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); - } - return false; - } function ErrorMsg() { if ($this->_haserrorfunctions) { if ($this->_errorMsg !== false) return $this->_errorMsg; - if (empty($this->_connectionID)) return @db2_errormsg(); - return @db2_errormsg($this->_connectionID); + if (empty($this->_connectionID)) return @db2_co... [truncated message content] |