| version 1.2, 2005/11/07 20:37:25 |
version 1.3, 2011/06/17 13:56:39 |
|
|
| * @author Urs Gehrig <urs@circle.ch> |
* @author Urs Gehrig <urs@circle.ch> |
| * @author Mika Tuupola <tuupola@appelsiini.net> |
* @author Mika Tuupola <tuupola@appelsiini.net> |
| * @author Daniel Convissor <danielc@php.net> |
* @author Daniel Convissor <danielc@php.net> |
| * @copyright 1997-2005 The PHP Group |
* @copyright 1997-2007 The PHP Group |
| * @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0 |
| * @version CVS: $Id$ |
* @version CVS: $Id$ |
| * @link http://pear.php.net/package/DB |
* @link http://pear.php.net/package/DB |
| Line 45 require_once 'DB/common.php'; |
|
| Line 45 require_once 'DB/common.php'; |
|
| * @author Urs Gehrig <urs@circle.ch> |
* @author Urs Gehrig <urs@circle.ch> |
| * @author Mika Tuupola <tuupola@appelsiini.net> |
* @author Mika Tuupola <tuupola@appelsiini.net> |
| * @author Daniel Convissor <danielc@php.net> |
* @author Daniel Convissor <danielc@php.net> |
| * @copyright 1997-2005 The PHP Group |
* @copyright 1997-2007 The PHP Group |
| * @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 3.0 |
| * @version Release: 1.7.6 |
* @version Release: 1.7.14RC2 |
| * @link http://pear.php.net/package/DB |
* @link http://pear.php.net/package/DB |
| */ |
*/ |
| class DB_sqlite extends DB_common |
class DB_sqlite extends DB_common |
| Line 182 class DB_sqlite extends DB_common |
|
| Line 182 class DB_sqlite extends DB_common |
|
| * 'portability' => DB_PORTABILITY_ALL, |
* 'portability' => DB_PORTABILITY_ALL, |
| * ); |
* ); |
| * |
* |
| * $db =& DB::connect($dsn, $options); |
* $db = DB::connect($dsn, $options); |
| * if (PEAR::isError($db)) { |
* if (PEAR::isError($db)) { |
| * die($db->getMessage()); |
* die($db->getMessage()); |
| * } |
* } |
| Line 204 class DB_sqlite extends DB_common |
|
| Line 204 class DB_sqlite extends DB_common |
|
| $this->dbsyntax = $dsn['dbsyntax']; |
$this->dbsyntax = $dsn['dbsyntax']; |
| } |
} |
| |
|
| if ($dsn['database']) { |
if (!$dsn['database']) { |
| |
return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); |
| |
} |
| |
|
| |
if ($dsn['database'] !== ':memory:') { |
| if (!file_exists($dsn['database'])) { |
if (!file_exists($dsn['database'])) { |
| if (!touch($dsn['database'])) { |
if (!touch($dsn['database'])) { |
| return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); |
return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND); |
| Line 229 class DB_sqlite extends DB_common |
|
| Line 233 class DB_sqlite extends DB_common |
|
| if (!is_readable($dsn['database'])) { |
if (!is_readable($dsn['database'])) { |
| return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); |
return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); |
| } |
} |
| } else { |
|
| return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); |
|
| } |
} |
| |
|
| $connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open'; |
$connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open'; |
| |
|
| // track_errors must remain on for simpleQuery() |
// track_errors must remain on for simpleQuery() |
| ini_set('track_errors', 1); |
@ini_set('track_errors', 1); |
| $php_errormsg = ''; |
$php_errormsg = ''; |
| |
|
| if (!$this->connection = @$connect_function($dsn['database'])) { |
if (!$this->connection = @$connect_function($dsn['database'])) { |
| Line 280 class DB_sqlite extends DB_common |
|
| Line 282 class DB_sqlite extends DB_common |
|
| */ |
*/ |
| function simpleQuery($query) |
function simpleQuery($query) |
| { |
{ |
| $ismanip = DB::isManip($query); |
$ismanip = $this->_checkManip($query); |
| $this->last_query = $query; |
$this->last_query = $query; |
| $query = $this->modifyQuery($query); |
$query = $this->modifyQuery($query); |
| |
|
| Line 357 class DB_sqlite extends DB_common |
|
| Line 359 class DB_sqlite extends DB_common |
|
| if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { |
| $arr = array_change_key_case($arr, CASE_LOWER); |
$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; |
| |
} |
| } else { |
} else { |
| $arr = @sqlite_fetch_array($result, SQLITE_NUM); |
$arr = @sqlite_fetch_array($result, SQLITE_NUM); |
| } |
} |
| Line 727 class DB_sqlite extends DB_common |
|
| Line 739 class DB_sqlite extends DB_common |
|
| function errorCode($errormsg) |
function errorCode($errormsg) |
| { |
{ |
| static $error_regexps; |
static $error_regexps; |
| |
|
| |
// PHP 5.2+ prepends the function name to $php_errormsg, so we need |
| |
// this hack to work around it, per bug #9599. |
| |
$errormsg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $errormsg); |
| |
|
| if (!isset($error_regexps)) { |
if (!isset($error_regexps)) { |
| $error_regexps = array( |
$error_regexps = array( |
| '/^no such table:/' => DB_ERROR_NOSUCHTABLE, |
'/^no such table:/' => DB_ERROR_NOSUCHTABLE, |
| Line 738 class DB_sqlite extends DB_common |
|
| Line 755 class DB_sqlite extends DB_common |
|
| '/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT, |
'/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT, |
| '/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL, |
'/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL, |
| '/^no such column:/' => DB_ERROR_NOSUCHFIELD, |
'/^no such column:/' => DB_ERROR_NOSUCHFIELD, |
| |
'/no column named/' => DB_ERROR_NOSUCHFIELD, |
| '/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD, |
'/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD, |
| '/^near ".*": syntax error$/' => DB_ERROR_SYNTAX, |
'/^near ".*": syntax error$/' => DB_ERROR_SYNTAX, |
| '/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW, |
'/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW, |
| Line 811 class DB_sqlite extends DB_common |
|
| Line 829 class DB_sqlite extends DB_common |
|
| $flags = ''; |
$flags = ''; |
| if ($id[$i]['pk']) { |
if ($id[$i]['pk']) { |
| $flags .= 'primary_key '; |
$flags .= 'primary_key '; |
| |
if (strtoupper($type) == 'INTEGER') { |
| |
$flags .= 'auto_increment '; |
| |
} |
| } |
} |
| if ($id[$i]['notnull']) { |
if ($id[$i]['notnull']) { |
| $flags .= 'not_null '; |
$flags .= 'not_null '; |