| | |
| | | // | Author: Lukas Smith <smith@pooteeweet.org> |
|
| | | // +----------------------------------------------------------------------+
|
| | | //
|
| | | // $Id: sqlite.php,v 1.158 2008/03/08 14:18:39 quipo Exp $
|
| | | // $Id: sqlite.php 292715 2009-12-28 14:06:34Z quipo $ |
| | | //
|
| | |
|
| | | /**
|
| | |
| | | // this hack to work around it, per bug #9599.
|
| | | $native_msg = preg_replace('/^sqlite[a-z_]+\(\)[^:]*: /', '', $native_msg);
|
| | |
|
| | | if (is_null($error)) {
|
| | | if (null === $error) { |
| | | static $error_regexps;
|
| | | if (empty($error_regexps)) {
|
| | | $error_regexps = array(
|
| | |
| | | function beginTransaction($savepoint = null)
|
| | | {
|
| | | $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint));
|
| | | if (!is_null($savepoint)) {
|
| | | if (null !== $savepoint) { |
| | | return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
|
| | | 'savepoints are not supported', __FUNCTION__);
|
| | | } elseif ($this->in_transaction) {
|
| | | } |
| | | if ($this->in_transaction) { |
| | | return MDB2_OK; //nothing to do
|
| | | }
|
| | | if (!$this->destructor_registered && $this->opened_persistent) {
|
| | |
| | | return $this->raiseError(MDB2_ERROR_INVALID, null, null,
|
| | | 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
|
| | | }
|
| | | if (!is_null($savepoint)) {
|
| | | if (null !== $savepoint) { |
| | | return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
|
| | | 'savepoints are not supported', __FUNCTION__);
|
| | | }
|
| | |
| | | return $this->raiseError(MDB2_ERROR_INVALID, null, null,
|
| | | 'rollback cannot be done changes are auto committed', __FUNCTION__);
|
| | | }
|
| | | if (!is_null($savepoint)) {
|
| | | if (null !== $savepoint) { |
| | | return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
|
| | | 'savepoints are not supported', __FUNCTION__);
|
| | | }
|
| | |
| | | 'extension '.$this->phptype.' is not compiled into PHP', __FUNCTION__);
|
| | | }
|
| | |
|
| | | if (!empty($this->database_name)) {
|
| | | if (empty($this->database_name)) { |
| | | return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, |
| | | 'unable to establish a connection', __FUNCTION__); |
| | | } |
| | | |
| | | if ($database_file !== ':memory:') {
|
| | | if (!file_exists($database_file)) {
|
| | | if (!touch($database_file)) {
|
| | |
| | | 'unable to establish a connection', __FUNCTION__);
|
| | | }
|
| | |
|
| | | /* |
| | | if (!empty($this->dsn['charset'])) {
|
| | | $result = $this->setCharset($this->dsn['charset'], $connection);
|
| | | if (PEAR::isError($result)) {
|
| | | return $result;
|
| | | if ($this->fix_assoc_fields_names || |
| | | $this->options['portability'] & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES) |
| | | { |
| | | @sqlite_query("PRAGMA short_column_names = 1", $connection); |
| | | $this->fix_assoc_fields_names = true; |
| | | }
|
| | | }
|
| | | */ |
| | |
|
| | | $this->connection = $connection;
|
| | | $this->connected_dsn = $this->dsn;
|
| | | $this->connected_database_name = $database_file;
|
| | | $this->opened_persistent = $this->getoption('persistent');
|
| | | $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
|
| | | }
|
| | | |
| | | return MDB2_OK;
|
| | | }
|
| | |
|
| | |
| | | if (!$this->opened_persistent || $force) {
|
| | | @sqlite_close($this->connection);
|
| | | }
|
| | | } else { |
| | | return false; |
| | | }
|
| | | return parent::disconnect($force);
|
| | | }
|
| | |
|
| | | // }}}
|
| | | // {{{ getConnection()
|
| | |
|
| | | /**
|
| | | * Returns a native connection
|
| | | *
|
| | | * @return mixed a valid MDB2 connection object,
|
| | | * or a MDB2 error object on error
|
| | | * @access public
|
| | | */
|
| | | function getConnection()
|
| | | {
|
| | | $connection = parent::getConnection();
|
| | | if (PEAR::isError($connection)) {
|
| | | return $connection;
|
| | | }
|
| | |
|
| | | $fix_assoc_fields_names = $this->options['portability'] & MDB2_PORTABILITY_FIX_ASSOC_FIELD_NAMES;
|
| | | if ($fix_assoc_fields_names !== $this->fix_assoc_fields_names) {
|
| | | @sqlite_query("PRAGMA short_column_names = $fix_assoc_fields_names;", $connection);
|
| | | $this->fix_assoc_fields_names = $fix_assoc_fields_names;
|
| | | }
|
| | |
|
| | | return $connection;
|
| | | }
|
| | |
|
| | | // }}}
|
| | |
| | | return $result;
|
| | | }
|
| | |
|
| | | if (is_null($connection)) {
|
| | | if (null === $connection) { |
| | | $connection = $this->getConnection();
|
| | | if (PEAR::isError($connection)) {
|
| | | return $connection;
|
| | |
| | | */
|
| | | function _affectedRows($connection, $result = null)
|
| | | {
|
| | | if (is_null($connection)) {
|
| | | if (null === $connection) { |
| | | $connection = $this->getConnection();
|
| | | if (PEAR::isError($connection)) {
|
| | | return $connection;
|
| | |
| | | /**
|
| | | * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
|
| | | * query, except that if there is already a row in the table with the same
|
| | | * key field values, the REPLACE query just updates its values instead of
|
| | | * inserting a new row.
|
| | | * key field values, the old row is deleted before the new row is inserted. |
| | | *
|
| | | * The REPLACE type of query does not make part of the SQL standards. Since
|
| | | * practically only SQLite implements it natively, this type of query is
|
| | |
| | | */
|
| | | function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
|
| | | {
|
| | | if (!is_null($rownum)) {
|
| | | if (null !== $rownum) { |
| | | $seek = $this->seek($rownum);
|
| | | if (PEAR::isError($seek)) {
|
| | | return $seek;
|
| | |
| | | $row = @sqlite_fetch_array($this->result, SQLITE_NUM);
|
| | | }
|
| | | if (!$row) {
|
| | | if ($this->result === false) {
|
| | | if (false === $this->result) { |
| | | $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
|
| | | 'resultset has already been freed', __FUNCTION__);
|
| | | return $err;
|
| | |
| | | if ($object_class == 'stdClass') {
|
| | | $row = (object) $row;
|
| | | } else {
|
| | | $row = new $object_class($row);
|
| | | $rowObj = new $object_class($row); |
| | | $row = $rowObj; |
| | | }
|
| | | }
|
| | | ++$this->rownum;
|
| | |
| | | function numCols()
|
| | | {
|
| | | $cols = @sqlite_num_fields($this->result);
|
| | | if (is_null($cols)) {
|
| | | if ($this->result === false) {
|
| | | if (null === $cols) { |
| | | if (false === $this->result) { |
| | | return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
|
| | | 'resultset has already been freed', __FUNCTION__);
|
| | | } elseif (is_null($this->result)) {
|
| | | } |
| | | if (null === $this->result) { |
| | | return count($this->types);
|
| | | }
|
| | | return $this->db->raiseError(null, null, null,
|
| | |
| | | function seek($rownum = 0)
|
| | | {
|
| | | if (!@sqlite_seek($this->result, $rownum)) {
|
| | | if ($this->result === false) {
|
| | | if (false === $this->result) { |
| | | return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
|
| | | 'resultset has already been freed', __FUNCTION__);
|
| | | } elseif (is_null($this->result)) {
|
| | | } |
| | | if (null === $this->result) { |
| | | return MDB2_OK;
|
| | | }
|
| | | return $this->db->raiseError(MDB2_ERROR_INVALID, null, null,
|
| | |
| | | function numRows()
|
| | | {
|
| | | $rows = @sqlite_num_rows($this->result);
|
| | | if (is_null($rows)) {
|
| | | if ($this->result === false) {
|
| | | if (null === $rows) { |
| | | if (false === $this->result) { |
| | | return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,
|
| | | 'resultset has already been freed', __FUNCTION__);
|
| | | } elseif (is_null($this->result)) {
|
| | | } |
| | | if (null === $this->result) { |
| | | return 0;
|
| | | }
|
| | | return $this->db->raiseError(null, null, null,
|
| | |
| | | {
|
| | |
|
| | | }
|
| | |
|
| | | ?> |