alecpl
2010-01-26 2273d4117fd50ee44dcdaa28fd6444383dc403a0
program/lib/MDB2/Driver/sqlite.php
@@ -43,7 +43,7 @@
// | 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 $
//
/**
@@ -131,7 +131,7 @@
        // 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(
@@ -194,10 +194,11 @@
    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) {
@@ -234,7 +235,7 @@
            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__);
        }
@@ -269,7 +270,7 @@
            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__);
        }
@@ -364,7 +365,11 @@
                '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)) {
@@ -412,21 +417,19 @@
                '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;
    }
@@ -479,34 +482,10 @@
            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;
    }
    // }}}
@@ -536,7 +515,7 @@
            return $result;
        }
        if (is_null($connection)) {
        if (null === $connection) {
            $connection = $this->getConnection();
            if (PEAR::isError($connection)) {
                return $connection;
@@ -582,7 +561,7 @@
     */
    function _affectedRows($connection, $result = null)
    {
        if (is_null($connection)) {
        if (null === $connection) {
            $connection = $this->getConnection();
            if (PEAR::isError($connection)) {
                return $connection;
@@ -673,8 +652,7 @@
    /**
     * 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
@@ -898,7 +876,7 @@
     */
    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;
@@ -918,7 +896,7 @@
           $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;
@@ -949,7 +927,8 @@
            if ($object_class == 'stdClass') {
                $row = (object) $row;
            } else {
                $row = new $object_class($row);
                $rowObj = new $object_class($row);
                $row = $rowObj;
            }
        }
        ++$this->rownum;
@@ -998,11 +977,12 @@
    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,
@@ -1033,10 +1013,11 @@
    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,
@@ -1076,11 +1057,12 @@
    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,
@@ -1101,5 +1083,4 @@
{
}
?>