From: <var...@us...> - 2024-01-17 09:19:49
|
Revision: 11073 http://sourceforge.net/p/phpwiki/code/11073 Author: vargenau Date: 2024-01-17 09:19:45 +0000 (Wed, 17 Jan 2024) Log Message: ----------- Upgrade PEAR to relase 1.10.14, PEAR DB to release 1.12.1 Modified Paths: -------------- trunk/lib/pear/DB/common.php trunk/lib/pear/DB/dbase.php trunk/lib/pear/DB/fbsql.php trunk/lib/pear/DB/ibase.php trunk/lib/pear/DB/ifx.php trunk/lib/pear/DB/msql.php trunk/lib/pear/DB/mssql.php trunk/lib/pear/DB/mysql.php trunk/lib/pear/DB/mysqli.php trunk/lib/pear/DB/oci8.php trunk/lib/pear/DB/odbc.php trunk/lib/pear/DB/pgsql.php trunk/lib/pear/DB/sqlite.php trunk/lib/pear/DB/storage.php trunk/lib/pear/DB/sybase.php trunk/lib/pear/DB.php trunk/lib/pear/PEAR.php trunk/locale/it/pgsrc/NoteDiRilascio trunk/pgsrc/ReleaseNotes Added Paths: ----------- trunk/lib/pear/DB/sqlite3.php Modified: trunk/lib/pear/DB/common.php =================================================================== --- trunk/lib/pear/DB/common.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/common.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -42,7 +42,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB */ class DB_common extends PEAR @@ -315,6 +315,7 @@ * + odbc(db2) * + pgsql * + sqlite + * + sqlite3 * + sybase (must execute <kbd>set quoted_identifier on</kbd> sometime * prior to use) * @@ -417,6 +418,10 @@ * (<kbd>INTEGER</kbd>) * </li> * <li> + * <kbd>sqlite3</kbd> -> <samp>1/0</samp> + * (<kbd>INTEGER</kbd>) + * </li> + * <li> * <kbd>sybase</kbd> -> <samp>1/0</samp> * (<kbd>TINYINT(1)</kbd>) * </li> @@ -641,6 +646,7 @@ * + mysql * + mysqli * + sqlite + * + sqlite3 * * * <samp>DB_PORTABILITY_NUMROWS</samp> @@ -720,6 +726,7 @@ case 'mysql': case 'mysqli': case 'sqlite': + case 'sqlite3': $this->options['portability'] = DB_PORTABILITY_DELETE_COUNT; break; @@ -1809,6 +1816,23 @@ } // }}} + // {{{ lastId() + + /** + * Returns the row ID of the most recent INSERT into the database + * + * @param string $link_identifier DBMS link identifier + * + * @return int the row ID of the most recent INSERT into the database. + * If no successful INSERTs into rowid tables have ever + * occurred on this database connection then returns 0. + */ + function lastId($link_identifier = null) + { + return $this->raiseError(DB_ERROR_NOT_CAPABLE); + } + + // }}} // {{{ createSequence() /** Modified: trunk/lib/pear/DB/dbase.php =================================================================== --- trunk/lib/pear/DB/dbase.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/dbase.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -41,7 +41,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB */ class DB_dbase extends DB_common @@ -269,7 +269,7 @@ // }}} // {{{ &query() - function &query($query, $params = array()) + function &query($query = null, $params = array()) { // emulate result resources $this->res_row[(int)$this->result] = 0; Modified: trunk/lib/pear/DB/fbsql.php =================================================================== --- trunk/lib/pear/DB/fbsql.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/fbsql.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -41,7 +41,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB * @since Class functional since Release 1.7.0 */ Modified: trunk/lib/pear/DB/ibase.php =================================================================== --- trunk/lib/pear/DB/ibase.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/ibase.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -49,7 +49,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB * @since Class became stable in Release 1.7.0 */ @@ -707,9 +707,9 @@ $repeat = 0; do { $this->pushErrorHandling(PEAR_ERROR_RETURN); - $result = $this->query("SELECT GEN_ID(${sqn}, 1) " + $result = $this->query("SELECT GEN_ID({$sqn}, 1) " . 'FROM RDB$GENERATORS ' - . "WHERE RDB\$GENERATOR_NAME='${sqn}'"); + . "WHERE RDB\$GENERATOR_NAME='{$sqn}'"); $this->popErrorHandling(); if ($ondemand && DB::isError($result)) { $repeat = 1; @@ -746,7 +746,7 @@ { $sqn = strtoupper($this->getSequenceName($seq_name)); $this->pushErrorHandling(PEAR_ERROR_RETURN); - $result = $this->query("CREATE GENERATOR ${sqn}"); + $result = $this->query("CREATE GENERATOR {$sqn}"); $this->popErrorHandling(); return $result; Modified: trunk/lib/pear/DB/ifx.php =================================================================== --- trunk/lib/pear/DB/ifx.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/ifx.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -48,7 +48,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB */ class DB_ifx extends DB_common Modified: trunk/lib/pear/DB/msql.php =================================================================== --- trunk/lib/pear/DB/msql.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/msql.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -47,7 +47,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB * @since Class not functional until Release 1.7.0 */ @@ -443,7 +443,7 @@ $repeat = false; do { $this->pushErrorHandling(PEAR_ERROR_RETURN); - $result = $this->query("SELECT _seq FROM ${seqname}"); + $result = $this->query("SELECT _seq FROM {$seqname}"); $this->popErrorHandling(); if ($ondemand && DB::isError($result) && $result->getCode() == DB_ERROR_NOSUCHTABLE) { @@ -490,7 +490,7 @@ if (DB::isError($res)) { return $res; } - $res = $this->query("CREATE SEQUENCE ON ${seqname}"); + $res = $this->query("CREATE SEQUENCE ON {$seqname}"); return $res; } Modified: trunk/lib/pear/DB/mssql.php =================================================================== --- trunk/lib/pear/DB/mssql.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/mssql.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -22,6 +22,7 @@ * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id$ * @link http://pear.php.net/package/DB + * @deprecated since 1.12.0 */ /** @@ -49,8 +50,9 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB + * @deprecated since 1.12.0 */ class DB_mssql extends DB_common { Modified: trunk/lib/pear/DB/mysql.php =================================================================== --- trunk/lib/pear/DB/mysql.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/mysql.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -22,6 +22,7 @@ * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id$ * @link http://pear.php.net/package/DB + * @deprecated since 1.12.0 */ /** @@ -41,8 +42,9 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB + * @deprecated since 1.12.0 */ class DB_mysql extends DB_common { @@ -109,9 +111,12 @@ 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, 1142 => DB_ERROR_ACCESS_VIOLATION, 1146 => DB_ERROR_NOSUCHTABLE, + 1205 => DB_ERROR_LOCK_TIMEOUT, + 1213 => DB_ERROR_DEADLOCK, 1216 => DB_ERROR_CONSTRAINT, 1217 => DB_ERROR_CONSTRAINT, - 1356 => DB_ERROR_DIVZERO, + 1356 => DB_ERROR_INVALID_VIEW, + 1365 => DB_ERROR_DIVZERO, 1451 => DB_ERROR_CONSTRAINT, 1452 => DB_ERROR_CONSTRAINT, ); @@ -587,7 +592,7 @@ do { $repeat = 0; $this->pushErrorHandling(PEAR_ERROR_RETURN); - $result = $this->query("UPDATE ${seqname} ". + $result = $this->query("UPDATE {$seqname} ". 'SET id=LAST_INSERT_ID(id+1)'); $this->popErrorHandling(); if ($result === DB_OK) { @@ -599,7 +604,7 @@ // EMPTY SEQ TABLE // Sequence table must be empty for some reason, so fill // it and return 1 and obtain a user-level lock - $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); + $result = $this->getOne("SELECT GET_LOCK('{$seqname}_lock',10)"); if (DB::isError($result)) { return $this->raiseError($result); } @@ -609,7 +614,7 @@ } // add the default value - $result = $this->query("REPLACE INTO ${seqname} (id) VALUES (0)"); + $result = $this->query("REPLACE INTO {$seqname} (id) VALUES (0)"); if (DB::isError($result)) { return $this->raiseError($result); } @@ -616,7 +621,7 @@ // Release the lock $result = $this->getOne('SELECT RELEASE_LOCK(' - . "'${seqname}_lock')"); + . "'{$seqname}_lock')"); if (DB::isError($result)) { return $this->raiseError($result); } @@ -651,6 +656,29 @@ } // }}} + // {{{ lastId() + + /** + * Returns the row ID of the most recent INSERT into the database + * + * @param string $link_identifier mysql link identifier + * + * @return int the row ID of the most recent INSERT into the database. + * If no successful INSERTs into rowid tables have ever + * occurred on this database connection then returns 0. + * + * @see DB_common::lastID() + */ + function lastId($link_identifier = null) + { + $id = mysql_insert_id($link_identifier); + if(empty($id) || !is_int($id)) { + return 0; + } + return $id; + } + + // }}} // {{{ createSequence() /** @@ -673,12 +701,12 @@ return $res; } // insert yields value 1, nextId call will generate ID 2 - $res = $this->query("INSERT INTO ${seqname} (id) VALUES (0)"); + $res = $this->query("INSERT INTO {$seqname} (id) VALUES (0)"); if (DB::isError($res)) { return $res; } // so reset to zero - return $this->query("UPDATE ${seqname} SET id = 0"); + return $this->query("UPDATE {$seqname} SET id = 0"); } // }}} @@ -717,7 +745,7 @@ // Obtain a user-level lock... this will release any previous // application locks, but unlike LOCK TABLES, it does not abort // the current transaction and is much less frequently used. - $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); + $result = $this->getOne("SELECT GET_LOCK('{$seqname}_lock',10)"); if (DB::isError($result)) { return $result; } @@ -727,7 +755,7 @@ return $this->mysqlRaiseError(DB_ERROR_NOT_LOCKED); } - $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}"); + $highest_id = $this->getOne("SELECT MAX(id) FROM {$seqname}"); if (DB::isError($highest_id)) { return $highest_id; } @@ -743,7 +771,7 @@ // If another thread has been waiting for this lock, // it will go thru the above procedure, but will have no // real effect - $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')"); + $result = $this->getOne("SELECT RELEASE_LOCK('{$seqname}_lock')"); if (DB::isError($result)) { return $result; } Modified: trunk/lib/pear/DB/mysqli.php =================================================================== --- trunk/lib/pear/DB/mysqli.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/mysqli.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -43,7 +43,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB * @since Class functional since Release 1.6.3 */ @@ -112,9 +112,12 @@ 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, 1142 => DB_ERROR_ACCESS_VIOLATION, 1146 => DB_ERROR_NOSUCHTABLE, + 1205 => DB_ERROR_LOCK_TIMEOUT, + 1213 => DB_ERROR_DEADLOCK, 1216 => DB_ERROR_CONSTRAINT, 1217 => DB_ERROR_CONSTRAINT, - 1356 => DB_ERROR_DIVZERO, + 1356 => DB_ERROR_INVALID_VIEW, + 1365 => DB_ERROR_DIVZERO, 1451 => DB_ERROR_CONSTRAINT, 1452 => DB_ERROR_CONSTRAINT, ); @@ -296,7 +299,10 @@ $ini = ini_get('track_errors'); @ini_set('track_errors', 1); $php_errormsg = ''; - + if (version_compare(PHP_VERSION, '8.1', '>=')) + { + mysqli_report(MYSQLI_REPORT_OFF); + } if (((int) $this->getOption('ssl')) === 1) { $init = mysqli_init(); mysqli_ssl_set( @@ -362,6 +368,10 @@ { $ret = @mysqli_close($this->connection); $this->connection = null; + if (version_compare(PHP_VERSION, '8.1', '>=')) + { + mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); + } return $ret; } @@ -681,7 +691,7 @@ // so fill it and return 1 // Obtain a user-level lock $result = $this->getOne('SELECT GET_LOCK(' - . "'${seqname}_lock', 10)"); + . "'{$seqname}_lock', 10)"); if (DB::isError($result)) { return $this->raiseError($result); } @@ -698,7 +708,7 @@ // Release the lock $result = $this->getOne('SELECT RELEASE_LOCK(' - . "'${seqname}_lock')"); + . "'{$seqname}_lock')"); if (DB::isError($result)) { return $this->raiseError($result); } @@ -736,7 +746,30 @@ return $this->raiseError($result); } + // }}} + // {{{ lastId() + /** + * Returns the row ID of the most recent INSERT into the database + * + * @param string $link_identifier mysqli link identifier + * + * @return int the row ID of the most recent INSERT into the database. + * If no successful INSERTs into rowid tables have ever + * occurred on this database connection then returns 0. + * + * @see DB_common::lastID() + */ + function lastId($link_identifier = null) + { + $id = $this->connection->insert_id(); + if (empty($id) || !is_int($id)) { + return 0; + } + return $id; + } + + /** * Creates a new sequence * * @param string $seq_name name of the new sequence @@ -756,7 +789,7 @@ return $res; } // insert yields value 1, nextId call will generate ID 2 - return $this->query("INSERT INTO ${seqname} (id) VALUES (0)"); + return $this->query("INSERT INTO {$seqname} (id) VALUES (0)"); } // }}} @@ -795,7 +828,7 @@ // Obtain a user-level lock... this will release any previous // application locks, but unlike LOCK TABLES, it does not abort // the current transaction and is much less frequently used. - $result = $this->getOne("SELECT GET_LOCK('${seqname}_lock',10)"); + $result = $this->getOne("SELECT GET_LOCK('{$seqname}_lock',10)"); if (DB::isError($result)) { return $result; } @@ -805,7 +838,7 @@ return $this->mysqliRaiseError(DB_ERROR_NOT_LOCKED); } - $highest_id = $this->getOne("SELECT MAX(id) FROM ${seqname}"); + $highest_id = $this->getOne("SELECT MAX(id) FROM {$seqname}"); if (DB::isError($highest_id)) { return $highest_id; } @@ -822,7 +855,7 @@ // If another thread has been waiting for this lock, // it will go thru the above procedure, but will have no // real effect - $result = $this->getOne("SELECT RELEASE_LOCK('${seqname}_lock')"); + $result = $this->getOne("SELECT RELEASE_LOCK('{$seqname}_lock')"); if (DB::isError($result)) { return $result; } Modified: trunk/lib/pear/DB/oci8.php =================================================================== --- trunk/lib/pear/DB/oci8.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/oci8.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -47,7 +47,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB */ class DB_oci8 extends DB_common @@ -249,7 +249,7 @@ $dsn['password'], $db, $char); - $error = OCIError(); + $error = oci_error(); if (!empty($error) && $error['code'] == 12541) { // Couldn't find TNS listener. Try direct connection. $this->connection = @$connect_function($dsn['username'], @@ -270,7 +270,7 @@ } if (!$this->connection) { - $error = OCIError(); + $error = oci_error(); $error = (is_array($error)) ? $error['message'] : null; return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, @@ -289,11 +289,7 @@ */ function disconnect() { - if (function_exists('oci_close')) { - $ret = @oci_close($this->connection); - } else { - $ret = @OCILogOff($this->connection); - } + $ret = @oci_close($this->connection); $this->connection = null; return $ret; } @@ -320,14 +316,14 @@ $this->last_parameters = array(); $this->last_query = $query; $query = $this->modifyQuery($query); - $result = @OCIParse($this->connection, $query); + $result = @oci_parse($this->connection, $query); if (!$result) { return $this->oci8RaiseError(); } if ($this->autocommit) { - $success = @OCIExecute($result,OCI_COMMIT_ON_SUCCESS); + $success = @oci_execute($result,OCI_COMMIT_ON_SUCCESS); } else { - $success = @OCIExecute($result,OCI_DEFAULT); + $success = @oci_execute($result,OCI_DEFAULT); } if (!$success) { return $this->oci8RaiseError($result); @@ -336,7 +332,7 @@ if ($this->_checkManip($query)) { return DB_OK; } else { - @ocisetprefetch($result, $this->options['result_buffering']); + @oci_set_prefetch($result, $this->options['result_buffering']); return $result; } } @@ -387,7 +383,7 @@ return $this->raiseError(DB_ERROR_NOT_CAPABLE); } if ($fetchmode & DB_FETCHMODE_ASSOC) { - $moredata = @OCIFetchInto($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS); + $moredata = @oci_fetch_array($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS); if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $moredata) { @@ -394,7 +390,7 @@ $arr = array_change_key_case($arr, CASE_LOWER); } } else { - $moredata = OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS); + $moredata = oci_fetch_array($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS); } if (!$moredata) { return null; @@ -426,7 +422,7 @@ */ function freeResult($result) { - return is_resource($result) ? OCIFreeStatement($result) : false; + return is_resource($result) ? oci_free_statement($result) : false; } /** @@ -520,7 +516,7 @@ */ function numCols($result) { - $cols = @OCINumCols($result); + $cols = @oci_num_fields($result); if (!$cols) { return $this->oci8RaiseError($result); } @@ -592,7 +588,7 @@ $this->last_query = $query; $newquery = $this->modifyQuery($newquery); - if (!$stmt = @OCIParse($this->connection, $newquery)) { + if (!$stmt = @oci_parse($this->connection, $newquery)) { return $this->oci8RaiseError(); } $this->prepare_types[(int)$stmt] = $types; @@ -664,7 +660,7 @@ $data[$key] = $this->quoteFloat($data[$key]); } } - if (!@OCIBindByName($stmt, ':bind' . $i, $data[$key], -1)) { + if (!@oci_bind_by_name($stmt, ':bind' . $i, $data[$key], -1)) { $tmp = $this->oci8RaiseError($stmt); return $tmp; } @@ -673,9 +669,9 @@ $i++; } if ($this->autocommit) { - $success = @OCIExecute($stmt, OCI_COMMIT_ON_SUCCESS); + $success = @oci_execute($stmt, OCI_COMMIT_ON_SUCCESS); } else { - $success = @OCIExecute($stmt, OCI_DEFAULT); + $success = @oci_execute($stmt, OCI_DEFAULT); } if (!$success) { $tmp = $this->oci8RaiseError($stmt); @@ -688,7 +684,7 @@ $tmp = DB_OK; } else { $this->_last_query_manip = false; - @ocisetprefetch($stmt, $this->options['result_buffering']); + @oci_set_prefetch($stmt, $this->options['result_buffering']); $tmp = new DB_result($this, $stmt); } return $tmp; @@ -721,7 +717,7 @@ */ function commit() { - $result = @OCICommit($this->connection); + $result = @oci_commit($this->connection); if (!$result) { return $this->oci8RaiseError(); } @@ -738,7 +734,7 @@ */ function rollback() { - $result = @OCIRollback($this->connection); + $result = @oci_rollback($this->connection); if (!$result) { return $this->oci8RaiseError(); } @@ -760,7 +756,7 @@ if ($this->last_stmt === false) { return $this->oci8RaiseError(); } - $result = @OCIRowCount($this->last_stmt); + $result = @oci_num_rows($this->last_stmt); if ($result === false) { return $this->oci8RaiseError($this->last_stmt); } @@ -821,20 +817,20 @@ } else { $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL"; - if (!$result = @OCIParse($this->connection, $q_fields)) { + if (!$result = @oci_parse($this->connection, $q_fields)) { $this->last_query = $q_fields; return $this->oci8RaiseError(); } - if (!@OCIExecute($result, OCI_DEFAULT)) { + if (!@oci_execute($result, OCI_DEFAULT)) { $this->last_query = $q_fields; return $this->oci8RaiseError($result); } } - $ncols = OCINumCols($result); + $ncols = oci_num_fields($result); $cols = array(); for ( $i = 1; $i <= $ncols; $i++ ) { - $cols[] = '"' . OCIColumnName($result, $i) . '"'; + $cols[] = '"' . oci_field_name($result, $i) . '"'; } $fields = implode(', ', $cols); // XXX Test that (tip by John Lim) @@ -877,7 +873,7 @@ $repeat = 0; do { $this->expectError(DB_ERROR_NOSUCHTABLE); - $result = $this->query("SELECT ${seqname}.nextval FROM dual"); + $result = $this->query("SELECT {$seqname}.nextval FROM dual"); $this->popExpect(); if ($ondemand && DB::isError($result) && $result->getCode() == DB_ERROR_NOSUCHTABLE) { @@ -950,11 +946,11 @@ function oci8RaiseError($errno = null) { if ($errno === null) { - $error = @OCIError($this->connection); + $error = @oci_error($this->connection); return $this->raiseError($this->errorCode($error['code']), null, null, null, $error['message']); } elseif (is_resource($errno)) { - $error = @OCIError($errno); + $error = @oci_error($errno); return $this->raiseError($this->errorCode($error['code']), null, null, null, $error['message']); } @@ -973,9 +969,9 @@ function errorNative() { if (is_resource($this->last_stmt)) { - $error = @OCIError($this->last_stmt); + $error = @oci_error($this->last_stmt); } else { - $error = @OCIError($this->connection); + $error = @oci_error($this->connection); } if (is_array($error)) { return $error['code']; @@ -1029,21 +1025,21 @@ $this->last_query = $q_fields; - if (!$stmt = @OCIParse($this->connection, $q_fields)) { + if (!$stmt = @oci_parse($this->connection, $q_fields)) { return $this->oci8RaiseError(DB_ERROR_NEED_MORE_DATA); } - if (!@OCIExecute($stmt, OCI_DEFAULT)) { + if (!@oci_execute($stmt, OCI_DEFAULT)) { return $this->oci8RaiseError($stmt); } $i = 0; - while (@OCIFetch($stmt)) { + while (@oci_fetch($stmt)) { $res[$i] = array( 'table' => $case_func($result), - 'name' => $case_func(@OCIResult($stmt, 1)), - 'type' => @OCIResult($stmt, 2), - 'len' => @OCIResult($stmt, 3), - 'flags' => (@OCIResult($stmt, 4) == 'N') ? 'not_null' : '', + 'name' => $case_func(@oci_result($stmt, 1)), + 'type' => @oci_result($stmt, 2), + 'len' => @oci_result($stmt, 3), + 'flags' => (@oci_result($stmt, 4) == 'N') ? 'not_null' : '', ); if ($mode & DB_TABLEINFO_ORDER) { $res['order'][$res[$i]['name']] = $i; @@ -1057,7 +1053,7 @@ if ($mode) { $res['num_fields'] = $i; } - @OCIFreeStatement($stmt); + @oci_free_statement($stmt); } else { if (isset($result->result)) { @@ -1071,7 +1067,7 @@ $res = array(); if ($result === $this->last_stmt) { - $count = @OCINumCols($result); + $count = @oci_num_fields($result); if ($mode) { $res['num_fields'] = $count; } @@ -1078,9 +1074,9 @@ for ($i = 0; $i < $count; $i++) { $res[$i] = array( 'table' => '', - 'name' => $case_func(@OCIColumnName($result, $i+1)), - 'type' => @OCIColumnType($result, $i+1), - 'len' => @OCIColumnSize($result, $i+1), + 'name' => $case_func(@oci_field_name($result, $i+1)), + 'type' => @oci_field_type($result, $i+1), + 'len' => @oci_field_size($result, $i+1), 'flags' => '', ); if ($mode & DB_TABLEINFO_ORDER) { Modified: trunk/lib/pear/DB/odbc.php =================================================================== --- trunk/lib/pear/DB/odbc.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/odbc.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -44,7 +44,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB */ class DB_odbc extends DB_common @@ -331,7 +331,7 @@ return null; } if ($fetchmode !== DB_FETCHMODE_ORDERED) { - for ($i = 0; $i < count($arr); $i++) { + for ($i = 0, $iMax = count($arr); $i < $iMax; $i++) { $colName = @odbc_field_name($result, $i+1); $a[$colName] = $arr[$i]; } @@ -502,7 +502,7 @@ $repeat = 0; do { $this->pushErrorHandling(PEAR_ERROR_RETURN); - $result = $this->query("update ${seqname} set id = id + 1"); + $result = $this->query("update {$seqname} set id = id + 1"); $this->popErrorHandling(); if ($ondemand && DB::isError($result) && $result->getCode() == DB_ERROR_NOSUCHTABLE) { @@ -513,7 +513,7 @@ if (DB::isError($result)) { return $this->raiseError($result); } - $result = $this->query("insert into ${seqname} (id) values(0)"); + $result = $this->query("insert into {$seqname} (id) values(0)"); } else { $repeat = 0; } @@ -523,7 +523,7 @@ return $this->raiseError($result); } - $result = $this->query("select id from ${seqname}"); + $result = $this->query("select id from {$seqname}"); if (DB::isError($result)) { return $result; } Modified: trunk/lib/pear/DB/pgsql.php =================================================================== --- trunk/lib/pear/DB/pgsql.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/pgsql.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -43,7 +43,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB */ class DB_pgsql extends DB_common @@ -460,7 +460,7 @@ unset($this->row[(int)$result]); unset($this->_num_rows[(int)$result]); $this->affected = 0; - return @pg_freeresult($result); + return @pg_free_result($result); } return false; } @@ -534,7 +534,7 @@ */ function numCols($result) { - $cols = @pg_numfields($result); + $cols = @pg_num_fields($result); if (!$cols) { return $this->pgsqlRaiseError(); } @@ -559,7 +559,7 @@ */ function numRows($result) { - $rows = @pg_numrows($result); + $rows = @pg_num_rows($result); if ($rows === null) { return $this->pgsqlRaiseError(); } @@ -664,7 +664,7 @@ $repeat = false; do { $this->pushErrorHandling(PEAR_ERROR_RETURN); - $result = $this->query("SELECT NEXTVAL('${seqname}')"); + $result = $this->query("SELECT NEXTVAL('{$seqname}')"); $this->popErrorHandling(); if ($ondemand && DB::isError($result) && $result->getCode() == DB_ERROR_NOSUCHTABLE) { @@ -703,7 +703,7 @@ function createSequence($seq_name) { $seqname = $this->getSequenceName($seq_name); - $result = $this->query("CREATE SEQUENCE ${seqname}"); + $result = $this->query("CREATE SEQUENCE {$seqname}"); return $result; } @@ -791,7 +791,7 @@ */ function errorNative() { - return @pg_errormessage($this->connection); + return @pg_last_error($this->connection); } // }}} @@ -916,7 +916,7 @@ $case_func = 'strval'; } - $count = @pg_numfields($id); + $count = @pg_num_fields($id); $res = array(); if ($mode) { @@ -926,9 +926,9 @@ for ($i = 0; $i < $count; $i++) { $res[$i] = array( 'table' => $got_string ? $case_func($result) : '', - 'name' => $case_func(@pg_fieldname($id, $i)), - 'type' => @pg_fieldtype($id, $i), - 'len' => @pg_fieldsize($id, $i), + 'name' => $case_func(@pg_field_name($id, $i)), + 'type' => @pg_field_type($id, $i), + 'len' => @pg_field_size($id, $i), 'flags' => $got_string ? $this->_pgFieldFlags($id, $i, $result) : '', @@ -943,7 +943,7 @@ // free the result only if we were called on a table if ($got_string) { - @pg_freeresult($id); + @pg_free_result($id); } return $res; } @@ -967,7 +967,7 @@ */ function _pgFieldFlags($resource, $num_field, $table_name) { - $field_name = @pg_fieldname($resource, $num_field); + $field_name = @pg_field_name($resource, $num_field); // Check if there's a schema in $table_name and update things // accordingly. @@ -986,7 +986,7 @@ AND typ.typrelid = f.attrelid AND f.attname = '$field_name' AND $tableWhere"); - if (@pg_numrows($result) > 0) { + if (@pg_num_rows($result) > 0) { $row = @pg_fetch_row($result, 0); $flags = ($row[0] == 't') ? 'not_null ' : ''; @@ -1010,7 +1010,7 @@ AND f.attrelid = i.indrelid AND f.attname = '$field_name' AND $tableWhere"); - $count = @pg_numrows($result); + $count = @pg_num_rows($result); for ($i = 0; $i < $count ; $i++) { $row = @pg_fetch_row($result, $i); Modified: trunk/lib/pear/DB/sqlite.php =================================================================== --- trunk/lib/pear/DB/sqlite.php 2024-01-12 18:46:11 UTC (rev 11072) +++ trunk/lib/pear/DB/sqlite.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -47,7 +47,7 @@ * @author Daniel Convissor <da...@ph...> * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0 - * @version Release: 1.10.0 + * @version Release: 1.12.1 * @link http://pear.php.net/package/DB */ class DB_sqlite extends DB_common @@ -517,7 +517,7 @@ if (DB::isError($result)) { return($result); } - $query = "CREATE TRIGGER ${seqname}_cleanup AFTER INSERT ON $seqname + $query = "CREATE TRIGGER {$seqname}_cleanup AFTER INSERT ON $seqname BEGIN DELETE FROM $seqname WHERE id<LAST_INSERT_ROWID(); END "; Added: trunk/lib/pear/DB/sqlite3.php =================================================================== --- trunk/lib/pear/DB/sqlite3.php (rev 0) +++ trunk/lib/pear/DB/sqlite3.php 2024-01-17 09:19:45 UTC (rev 11073) @@ -0,0 +1,964 @@ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * The PEAR DB driver for PHP's sqlite3 extension + * for interacting with SQLite3 databases + * + * PHP version 8.0.10 + * + * LICENSE: This source file is subject to version 3.0 of the PHP license + * that is available through the world-wide-web at the following URI: + * http://www.php.net/license/3_0.txt. If you did not receive a copy of + * the PHP License and are unable to obtain it through the web, please + * send a note to li...@ph... so we can mail you a copy immediately. + * + * @category Database + * @package DB + * @author Urs Gehrig <ur...@ci...> + * @author Mika Tuupola <tu...@ap...> + * @author Daniel Convissor <da...@ph...> + * @author Armin Graefe <sch...@gm...> + * @copyright 1997-2007 The PHP Group + * @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0 + * @version CVS: $Id$ + * @link http://pear.php.net/package/DB + */ + +/** + * Obtain the DB_common class so it can be extended from + */ +require_once 'DB/common.php'; + +/** + * The methods PEAR DB uses to interact with PHP's sqlite extension + * for interacting with SQLite databases + * + * These methods overload the ones declared in DB_common. + * + * NOTICE: This driver needs PHP's track_errors ini setting to be on. + * It is automatically turned on when connecting to the database. + * Make sure your scripts don't turn it off. + * + * @category Database + * @package DB + * @author Urs Gehrig <ur...@ci...> + * @author Mika Tuupola <tu...@ap...> + * @author Daniel Convissor <da...@ph...> + * @author Armin Graefe <sch...@gm...> + * @copyright 1997-2007 The PHP Group + * @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0 + * @version Release: 1.12.1 + * @link http://pear.php.net/package/DB + */ +class DB_sqlite3 extends DB_common +{ + // {{{ properties + + /** + * The DB driver type (mysql, oci8, odbc, etc.) + * @var string + */ + var $phptype = 'sqlite3'; + + /** + * The database syntax variant to be used (db2, access, etc.), if any + * @var string + */ + var $dbsyntax = 'sqlite'; + + /** + * The capabilities of this DB implementation + * + * The 'new_link' element contains the PHP version that first provided + * new_link support for this DBMS. Contains false if it's unsupported. + * + * Meaning of the 'limit' element: + * + 'emulate' = emulate with fetch row by number + * + 'alter' = alter the query + * + false = skip rows + * + * @var array + */ + var $features = array( + 'limit' => 'alter', + 'new_link' => false, + 'numrows' => true, + 'pconnect' => true, + 'prepare' => false, + 'ssl' => false, + 'transactions' => false, + ); + + /** + * A mapping of native error codes to DB error codes + * + * {@internal Error codes according to sqlite_exec. See the online + * manual at http://sqlite.org/c_interface.html for info. + * This error handling based on sqlite_exec is not yet implemented.}} + * + * @var array + */ + var $errorcode_map = array( + ); + + /** + * The raw database connection created by PHP + * @var resource + */ + var $connection; + + /** + * The DSN information for connecting to a database + * @var array + */ + var $dsn = array(); + + + /** + * SQLite data types + * + * @link http://www.sqlite.org/datatypes.html + * + * @var array + */ + var $keywords = array ( + 'BLOB' => '', + 'BOOLEAN' => '', + 'CHARACTER' => '', + 'CLOB' => '', + 'FLOAT' => '', + 'INTEGER' => '', + 'KEY' => '', + 'NATIONAL' => '', + 'NUMERIC' => '', + 'NVARCHAR' => '', + 'PRIMARY' => '', + 'TEXT' => '', + 'TIMESTAMP' => '', + 'UNIQUE' => '', + 'VARCHAR' => '', + 'VARYING' => '', + ); + + /** + * The most recent error message from $php_errormsg + * @var string + * @access private + */ + var $_lasterror = ''; + + + // }}} + // {{{ constructor + + /** + * This constructor calls <kbd>parent::__construct()</kbd> + * + * @return void + */ + function __construct() + { + parent::__construct(); + } + + // }}} + // {{{ connect() + + /** + * Connect to the database server, log in and open the database + * + * Don't call this method directly. Use DB::connect() instead. + * + * PEAR DB's sqlite driver supports the following extra DSN options: + * + mode The permissions for the database file, in four digit + * chmod octal format (eg "0600"). + * + * Example of connecting to a database in read-only mode: + * <code> + * require_once 'DB.php'; + * + * $dsn = 'sqlite:///path/and/name/of/db/file?mode=0400'; + * $options = array( + * 'portability' => DB_PORTABILITY_ALL, + * ); + * + * $db = DB::connect($dsn, $options); + * if (PEAR::isError($db)) { + * die($db->getMessage()); + * } + * </code> + * + * @param array $dsn the data source name + * @param bool $persistent should the connection be persistent? + * + * @return int DB_OK on success. A DB_Error object on failure. + */ + function connect($dsn, $persistent = false) + { + $persistent = False; + if (!PEAR::loadExtension('sqlite3')) { + return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); + } + + $this->dsn = $dsn; + if ($dsn['dbsyntax']) { + $this->dbsyntax = $dsn['dbsyntax']; + } + + if (!$dsn['database']) { + return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); + } + + if ($dsn['database'] !== ':memory:') { + if (!file_exists($dsn['database'])) { + if (!touch($dsn['database'])) { + return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); + } + if (!isset($dsn['mode']) || + !is_numeric($dsn['mode'])) + { + $mode = 0644; + } else { + $mode = octdec($dsn['mode']); + } + if (!chmod($dsn['database'], $mode)) { + return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); + } + if (!file_exists($dsn['database'])) { + return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); + } + } + if (!is_file($dsn['database'])) { + return $this->sqliteRaiseError(DB_ERROR_INVALID); + } + if (!is_readable($dsn['database'])) { + return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); + } + } + + // track_errors must remain on for simpleQuery() + @ini_set('track_errors', 1); + $php_errormsg = ''; + + //var_dump($this->getOption('readable'));exit(); + + if (!$this->connection = @new SQLite3($dsn['database'])) { + return $this->raiseError(DB_ERROR_NODBSELECTED, + null, null, null, + $php_errormsg); + } + return DB_OK; + } + + // }}} + // {{{ disconnect() + + /** + * Disconnects from the database server + * + * @return bool TRUE on success, FALSE on failure + */ + function disconnect() + { + $ret = @$this->connection->close(); + $this->connection = null; + return $ret; + } + + // }}} + // {{{ simpleQuery() + + /** + * Sends a query to the database server + * + * NOTICE: This method needs PHP's track_errors ini setting to be on. + * It is automatically turned on when connecting to the database. + * Make sure your scripts don't turn it off. + * + * @param string the SQL query string + * + * @return mixed + a PHP result resrouce for successful SELECT queries + * + the DB_OK constant for other successful queries + * + a DB_Error object on failure + */ + function simpleQuery($query) + { + $ismanip = $this->_checkManip($query); + $this->last_query = $query; + $query = $this->modifyQuery($query); + + $php_errormsg = ''; + + $result = @$this->connection->query($query); + $this->_lasterror = $php_errormsg ? $php_errormsg : ''; + + $this->result = $result; + if (!$this->result) { + return $this->sqliteRaiseError(null); + } + + // sqlite_query() seems to allways return a resource + // so cant use that. Using $ismanip instead + if (!$ismanip) { + $numRows = $this->numRows($result); + if (is_object($numRows)) { + // we've got PEAR_Error + return $numRows; + } + return $result; + } + return DB_OK; + } + + // }}} + // {{{ nextResult() + + /** + * Move the internal sqlite result pointer to the next available result + * + * @param resource $result the valid sqlite result resource + * + * @return bool true if a result is available otherwise return false + */ + function nextResult($result) + { + return false; + } + + // }}} + // {{{ fetchInto() + + /** + * Places a row from the result set into the given array + * + * Formating of the array and the data therein are configurable. + * See DB_result::fetchInto() for more information. + * + * This method is not meant to be called directly. Use + * DB_result::fetchInto() instead. It can't be declared "protected" + * because DB_result is a separate object. + * + * @param resource $result the query result resource + * @param array $arr the referenced array to put the data in + * @param int $fetchmode how the resulting array should be indexed + * @param int $rownum the row number to fetch (0 = first row) + * + * @return mixed DB_OK on success, NULL when the end of a result set is + * reached or on failure + * + * @see DB_result::fetchInto() + */ + function fetchInto($result, &$arr, $fetchmode, $rownum = null) + { + if($fetchmode & DB_FETCHMODE_ASSOC){ + $sqlite_fetchmode = SQLITE3_ASSOC; + } else { + $sqlite_fetchmode = SQLITE3_NUM; + } + + if ($rownum !== null) { + $rownumber = -1; + while($rownum_res = @$result->fetchArray($sqlite_fetchmode)){ + $rownumber++; + if($rownum == $rownumber){ + $arr = $rownum_res; + break; + } + } + + if(!$arr){ + return null; + } + $result->reset(); + } else { + $arr = @$result->fetchArray($sqlite_fetchmode); + } + if ($fetchmode & DB_FETCHMODE_ASSOC) { + if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { + $arr = array_change_key_case($arr, CASE_LOWER); + } + + /* Remove extraneous " characters from the fields in the result. + * Fixes bug #11716. */ + if (is_array($arr) && count($arr) > 0) { + $strippedArr = array(); + foreach ($arr as $field => $value) { + $strippedArr[trim($field, '"')] = $value; + } + $arr = $strippedArr; + } + } + if (!$arr) { + return null; + } + if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { + /* + * Even though this DBMS already trims output, we do this because + * a field might have intentional whitespace at the end that + * gets removed by DB_PORTABILITY_RTRIM under another driver. + */ + $this->_rtrimArrayValues($arr); + } + if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { + $this->_convertNullArrayValuesToEmpty($arr); + } + return DB_OK; + } + + // }}} + // {{{ freeResult() + + /** + * Deletes the result set and frees the memory occupied by the result set + * + * This method is not meant to be called directly. Use + * DB_result::free() instead. It can't be declared "protected" + * because DB_result is a separate object. + * + * @param resource $result PHP's query result resource + * + * @return bool TRUE on success, FALSE if $result is invalid + * + * @see DB_result::free() + */ + function freeResult(&$result) + { + // XXX No native free? + if (!is_resource($result)) { + return false; + } + $result = null; + return true; + } + + // }}} + // {{{ numCols() + + /** + * Gets the number of columns in a result set + * + * This method is not meant to be called directly. Use + * DB_result::numCols() instead. It can't be declared "protected" + * because DB_result is a separate object. + * + * @param resource $result PHP's query result resource + * + * @return int the number of columns. A DB_Error object on failure. + * + * @see DB_result::numCols() + */ + function numCols($result) + { + $cols = @$result->numColumns(); + if (!$cols) { + return $this->sqliteRaiseError(); + } + return $cols; + } + + // }}} + // {{{ numRows() + + /** + * Gets the number of rows in a result set + * + * This method is not meant to be called directly. Use + * DB_result::numRows() instead. It can't be declared "protected" + * because DB_result is a separate object. + * + * @param resource $result PHP's query result resource + * + * @return int the number of rows. A DB_Error object on failure. + * + * @see DB_result::numRows() + */ + function numRows($result) + { + $numRows = 0; + while($rows = @$result->fetchArray(SQLITE3_NUM)){ + $numRows++; + } + return $numRows; + } + + // }}} + // {{{ affected() + + /** + * Determines the number of rows affected by a data maniuplation query + * + * 0 is returned for queries that don't manipulate data. + * + * @return int the number of rows. A DB_Error object on failure. + */ + function affectedRows() + { + return @$this->connection->changes(); + } + + // }}} + // {{{ dropSequence() + + /** + * Deletes a sequence + * + * @param string $seq_name name of the sequence to be deleted + * + * @return int DB_OK on success. A DB_Error object on failure. + * + * @see DB_common::dropSequence(), DB_common::getSequenceName(), + * DB_sqlite::nextID(), DB_sqlite::createSequence() + */ + function dropSequence($seq_name) + { + return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name)); + } + + /** + * Creates a new sequence + * + * @param string $seq_name name of the new sequence + * + * @return int DB_OK on success. A DB_Error object on failure. + * + * @see DB_common::createSequence(), DB_common::getSequenceName(), + * DB_sqlite::nextID(), DB_sqlite::dropSequence() + */ + function createSequence($seq_name) + { + $seqname = $this->getSequenceName($seq_name); + $query = 'CREATE TABLE ' . $seqname . + ' (id INTEGER UNSIGNED PRIMARY KEY) '; + $result = $this->query($query); + if (DB::isError($result)) { + return($result); + } + $query = "CREATE TRIGGER {$seqname}_cleanup AFTER INSERT ON $seqname + BEGIN + DELETE FROM $seqname WHERE id<LAST_INSERT_ROWID(); + END "; + $result = $this->query($query); + if (DB::isError($result)) { + return($result); + } + } + + // }}} + // {{{ nextId() + + /** + * Returns the next free id in a sequence + * + * @param string $seq_name name of the sequence + * @param boolean $ondemand when true, the seqence is automatically + * created if it does not exist + * + * @return int the next id number in the sequence. + * A DB_Error object on failure. + * + * @see DB_common::nextID(), DB_common::getSequenceName(), + * DB_sqlite::createSequence(), DB_sqlite::dropSequence() + */ + function nextId($seq_name, $ondemand = true) + { + $seqname = $this->getSequenceName($seq_name); + + do { + $repeat = 0; + $this->pushErrorHandling(PEAR_ERROR_RETURN); + $result = $this->query("INSERT INTO $seqname (id) VALUES (NULL)"); + $this->popErrorHandling(); + if ($result === DB_OK) { + $id = @$this->connection->lastInsertRowID(); + if ($id != 0) { + return $id; + } + } elseif ($ondemand && DB::isError($result) && + $result->getCode() == DB_ERROR_NOSUCHTABLE) + { + $result = $this->createSequence($seq_name); + if (DB::isError($result)) { + return $this->raiseError($result); + } else { + $repeat = 1; + } + } + } while ($repeat); + + return $this->raiseError($result); + } + + // }}} + // {{{ lastId() + + /** + * Returns the row ID of the most recent INSERT into the database + * + * @param string $link_identifier DBMS link identifier + * + * @return int the row ID of the most recent INSERT into the database. + * If no successful INSERTs into rowid tables have ever + * occurred on this database connection, + * then SQLite3::lastInsertRowID() returns 0 + * + * @see DB_common::lastID(), SQLite3::lastInsertRowID() + */ + function lastId($link_identifier = null) + { + $id = $this->connection->lastInsertRowID(); + if (empty($id) || !is_int($id)) { + return 0; + } + return $id; + } + + // }}} + // {{{ getDbFileStats() + + /** + * Get the file stats for the current database + * + * Possible arguments are dev, ino, mode, nlink, uid, gid, rdev, size, + * atime, mtime, ctime, blksize, blocks or a numeric key between + * 0 and 12. + * + * @param string $arg the array key for stats() + * + * @return mixed an array on an unspecified key, integer on a passed + * arg and false at a stats error + */ + function getDbFileStats($arg = '') + { + $stats = stat($this->dsn['database']); + if ($stats == false) { + return false; + } + if (is_array($stats)) { + if (is_numeric($arg)) { + if (((int)$arg <= 12) & ((int)$arg >= 0)) { + return false; + } + return $stats[$arg ]; + } + if (array_key_exists(trim($arg), $stats)) { + return $stats[$arg ]; + } + } + return $stats; + } + + // }}} + // {{{ escapeSimple() + + /** + * Escapes a string according to the current DBMS's standards + * + * In SQLite, this makes things safe for inserts/updates, but may + * cause problems when performing text comparisons against columns + * containing binary data. See the + * {@link http://php.net/sqlite_escape_string PHP manual} for more info. + * + * @param string $str the string to be escaped + * + * @return string the escaped string + * + * @since Method available since Release 1.6.1 + * @see DB_common::escapeSimple() + */ + function escapeSimple($str) + { + return @$this->connection->escapeString($str); + } + + // }}} + // {{{ modifyLimitQuery() + + /** + * Adds LIMIT clauses to a query string according to current DBMS standards + * + * @param string $query the query to modify + * @param int $from the row to start to fetching (0 = the first row) + * @param int $count the numbers of rows to fetch + * @param mixed $params array, string or numeric data to be used in + * execution of the statement. Quantity of items + * passed must match quantity of placeholders in + * query: meaning 1 placeholder for non-array + * parameters or 1 placeholder per array element. + * + * @return string the query string with LIMIT clauses added + * + * @access protected + */ + function modifyLimitQuery($query, $from, $count, $params = array()) + { + return "$query LIMIT $count OFFSET $from"; + } + + // }}} + // {{{ modifyQuery() + + /** + * Changes a query string for various DBMS specific reasons + * + * This little hack lets you know how many rows were deleted + * when running a "DELETE FROM table" query. Only implemented + * if the DB_PORTABILITY_DELETE_COUNT portability option is on. + * + * @param string $query the query string to modify + * + * @return string the modified query string + * + * @access protected + * @see DB_common::setOption() + */ + function modifyQuery($query) + { + if ($this->options['portability'] & DB_PORTABILITY_DELETE_COUNT) { + if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query)) { + $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', + 'DELETE FROM \1 WHERE 1=1', $query); + } + } + return $query; + } + + // }}} + // {{{ sqliteRaiseError() + + /** + * Pr... [truncated message content] |