Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 4... Line 4...
4
 
4
 
5
/**
5
/**
6
 * The PEAR DB driver for PHP's sqlite extension
6
 * The PEAR DB driver for PHP's sqlite extension
7
 * for interacting with SQLite databases
7
 * for interacting with SQLite databases
8
 *
8
 *
9
 * PHP versions 4 and 5
9
 * PHP version 5
10
 *
10
 *
11
 * LICENSE: This source file is subject to version 3.0 of the PHP license
11
 * LICENSE: This source file is subject to version 3.0 of the PHP license
12
 * that is available through the world-wide-web at the following URI:
12
 * that is available through the world-wide-web at the following URI:
13
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
13
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
Line 17... Line 17...
17
 * @category   Database
17
 * @category   Database
18
 * @package    DB
18
 * @package    DB
19
 * @author     Urs Gehrig <urs@circle.ch>
19
 * @author     Urs Gehrig <urs@circle.ch>
20
 * @author     Mika Tuupola <tuupola@appelsiini.net>
20
 * @author     Mika Tuupola <tuupola@appelsiini.net>
21
 * @author     Daniel Convissor <danielc@php.net>
21
 * @author     Daniel Convissor <danielc@php.net>
22
 * @copyright  1997-2005 The PHP Group
22
 * @copyright  1997-2007 The PHP Group
23
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 3.0
23
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 3.0
24
 * @version    CVS: $Id: sqlite.php,v 1.109 2005/03/10 01:22:48 danielc Exp $
24
 * @version    CVS: $Id$
25
 * @link       http://pear.php.net/package/DB
25
 * @link       http://pear.php.net/package/DB
26
 */
26
 */
Line 27... Line 27...
27
 
27
 
28
/**
28
/**
Line 43... Line 43...
43
 * @category   Database
43
 * @category   Database
44
 * @package    DB
44
 * @package    DB
45
 * @author     Urs Gehrig <urs@circle.ch>
45
 * @author     Urs Gehrig <urs@circle.ch>
46
 * @author     Mika Tuupola <tuupola@appelsiini.net>
46
 * @author     Mika Tuupola <tuupola@appelsiini.net>
47
 * @author     Daniel Convissor <danielc@php.net>
47
 * @author     Daniel Convissor <danielc@php.net>
48
 * @copyright  1997-2005 The PHP Group
48
 * @copyright  1997-2007 The PHP Group
49
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 3.0
49
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 3.0
50
 * @version    Release: 1.7.6
50
 * @version    Release: 1.9.2
51
 * @link       http://pear.php.net/package/DB
51
 * @link       http://pear.php.net/package/DB
52
 */
52
 */
53
class DB_sqlite extends DB_common
53
class DB_sqlite extends DB_common
54
{
54
{
55
    // {{{ properties
55
    // {{{ properties
Line 150... Line 150...
150
 
150
 
151
    // }}}
151
    // }}}
Line 152... Line 152...
152
    // {{{ constructor
152
    // {{{ constructor
153
 
153
 
154
    /**
154
    /**
155
     * This constructor calls <kbd>$this->DB_common()</kbd>
155
     * This constructor calls <kbd>parent::__construct()</kbd>
156
     *
156
     *
157
     * @return void
157
     * @return void
158
     */
158
     */
159
    function DB_sqlite()
159
    function __construct()
160
    {
160
    {
Line 161... Line 161...
161
        $this->DB_common();
161
        parent::__construct();
162
    }
162
    }
Line 180... Line 180...
180
     * $dsn = 'sqlite:///path/and/name/of/db/file?mode=0400';
180
     * $dsn = 'sqlite:///path/and/name/of/db/file?mode=0400';
181
     * $options = array(
181
     * $options = array(
182
     *     'portability' => DB_PORTABILITY_ALL,
182
     *     'portability' => DB_PORTABILITY_ALL,
183
     * );
183
     * );
184
     * 
184
     * 
185
     * $db =& DB::connect($dsn, $options);
185
     * $db = DB::connect($dsn, $options);
186
     * if (PEAR::isError($db)) {
186
     * if (PEAR::isError($db)) {
187
     *     die($db->getMessage());
187
     *     die($db->getMessage());
188
     * }
188
     * }
189
     * </code>
189
     * </code>
190
     *
190
     *
Line 202... Line 202...
202
        $this->dsn = $dsn;
202
        $this->dsn = $dsn;
203
        if ($dsn['dbsyntax']) {
203
        if ($dsn['dbsyntax']) {
204
            $this->dbsyntax = $dsn['dbsyntax'];
204
            $this->dbsyntax = $dsn['dbsyntax'];
205
        }
205
        }
Line 206... Line 206...
206
 
206
 
-
 
207
        if (!$dsn['database']) {
-
 
208
            return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
-
 
209
        }
-
 
210
 
207
        if ($dsn['database']) {
211
        if ($dsn['database'] !== ':memory:') {
208
            if (!file_exists($dsn['database'])) {
212
            if (!file_exists($dsn['database'])) {
209
                if (!touch($dsn['database'])) {
213
                if (!touch($dsn['database'])) {
210
                    return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
214
                    return $this->sqliteRaiseError(DB_ERROR_NOT_FOUND);
211
                }
215
                }
Line 227... Line 231...
227
                return $this->sqliteRaiseError(DB_ERROR_INVALID);
231
                return $this->sqliteRaiseError(DB_ERROR_INVALID);
228
            }
232
            }
229
            if (!is_readable($dsn['database'])) {
233
            if (!is_readable($dsn['database'])) {
230
                return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
234
                return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
231
            }
235
            }
232
        } else {
-
 
233
            return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION);
-
 
234
        }
236
        }
Line 235... Line 237...
235
 
237
 
Line 236... Line 238...
236
        $connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open';
238
        $connect_function = $persistent ? 'sqlite_popen' : 'sqlite_open';
237
 
239
 
238
        // track_errors must remain on for simpleQuery()
240
        // track_errors must remain on for simpleQuery()
Line 239... Line 241...
239
        ini_set('track_errors', 1);
241
        @ini_set('track_errors', 1);
240
        $php_errormsg = '';
242
        $php_errormsg = '';
241
 
243
 
Line 278... Line 280...
278
     *                + the DB_OK constant for other successful queries
280
     *                + the DB_OK constant for other successful queries
279
     *                + a DB_Error object on failure
281
     *                + a DB_Error object on failure
280
     */
282
     */
281
    function simpleQuery($query)
283
    function simpleQuery($query)
282
    {
284
    {
283
        $ismanip = DB::isManip($query);
285
        $ismanip = $this->_checkManip($query);
284
        $this->last_query = $query;
286
        $this->last_query = $query;
285
        $query = $this->modifyQuery($query);
287
        $query = $this->modifyQuery($query);
Line 286... Line 288...
286
 
288
 
Line 355... Line 357...
355
        if ($fetchmode & DB_FETCHMODE_ASSOC) {
357
        if ($fetchmode & DB_FETCHMODE_ASSOC) {
356
            $arr = @sqlite_fetch_array($result, SQLITE_ASSOC);
358
            $arr = @sqlite_fetch_array($result, SQLITE_ASSOC);
357
            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
359
            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
358
                $arr = array_change_key_case($arr, CASE_LOWER);
360
                $arr = array_change_key_case($arr, CASE_LOWER);
359
            }
361
            }
-
 
362
 
-
 
363
            /* Remove extraneous " characters from the fields in the result.
-
 
364
             * Fixes bug #11716. */
-
 
365
            if (is_array($arr) && count($arr) > 0) {
-
 
366
                $strippedArr = array();
-
 
367
                foreach ($arr as $field => $value) {
-
 
368
                    $strippedArr[trim($field, '"')] = $value;
-
 
369
                }
-
 
370
                $arr = $strippedArr;
-
 
371
            }
360
        } else {
372
        } else {
361
            $arr = @sqlite_fetch_array($result, SQLITE_NUM);
373
            $arr = @sqlite_fetch_array($result, SQLITE_NUM);
362
        }
374
        }
363
        if (!$arr) {
375
        if (!$arr) {
364
            return null;
376
            return null;
Line 725... Line 737...
725
     * @return integer  the DB error number
737
     * @return integer  the DB error number
726
     */
738
     */
727
    function errorCode($errormsg)
739
    function errorCode($errormsg)
728
    {
740
    {
729
        static $error_regexps;
741
        static $error_regexps;
-
 
742
        
-
 
743
        // PHP 5.2+ prepends the function name to $php_errormsg, so we need
-
 
744
        // this hack to work around it, per bug #9599.
-
 
745
        $errormsg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $errormsg);
-
 
746
        
730
        if (!isset($error_regexps)) {
747
        if (!isset($error_regexps)) {
731
            $error_regexps = array(
748
            $error_regexps = array(
732
                '/^no such table:/' => DB_ERROR_NOSUCHTABLE,
749
                '/^no such table:/' => DB_ERROR_NOSUCHTABLE,
733
                '/^no such index:/' => DB_ERROR_NOT_FOUND,
750
                '/^no such index:/' => DB_ERROR_NOT_FOUND,
734
                '/^(table|index) .* already exists$/' => DB_ERROR_ALREADY_EXISTS,
751
                '/^(table|index) .* already exists$/' => DB_ERROR_ALREADY_EXISTS,
Line 736... Line 753...
736
                '/is not unique/' => DB_ERROR_CONSTRAINT,
753
                '/is not unique/' => DB_ERROR_CONSTRAINT,
737
                '/columns .* are not unique/i' => DB_ERROR_CONSTRAINT,
754
                '/columns .* are not unique/i' => DB_ERROR_CONSTRAINT,
738
                '/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT,
755
                '/uniqueness constraint failed/' => DB_ERROR_CONSTRAINT,
739
                '/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
756
                '/may not be NULL/' => DB_ERROR_CONSTRAINT_NOT_NULL,
740
                '/^no such column:/' => DB_ERROR_NOSUCHFIELD,
757
                '/^no such column:/' => DB_ERROR_NOSUCHFIELD,
-
 
758
                '/no column named/' => DB_ERROR_NOSUCHFIELD,
741
                '/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD,
759
                '/column not present in both tables/i' => DB_ERROR_NOSUCHFIELD,
742
                '/^near ".*": syntax error$/' => DB_ERROR_SYNTAX,
760
                '/^near ".*": syntax error$/' => DB_ERROR_SYNTAX,
743
                '/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW,
761
                '/[0-9]+ values for [0-9]+ columns/i' => DB_ERROR_VALUE_COUNT_ON_ROW,
744
            );
762
            );
745
        }
763
        }
Line 809... Line 827...
809
            }
827
            }
Line 810... Line 828...
810
 
828
 
811
            $flags = '';
829
            $flags = '';
812
            if ($id[$i]['pk']) {
830
            if ($id[$i]['pk']) {
-
 
831
                $flags .= 'primary_key ';
-
 
832
                if (strtoupper($type) == 'INTEGER') {
-
 
833
                    $flags .= 'auto_increment ';
813
                $flags .= 'primary_key ';
834
                }
814
            }
835
            }
815
            if ($id[$i]['notnull']) {
836
            if ($id[$i]['notnull']) {
816
                $flags .= 'not_null ';
837
                $flags .= 'not_null ';
817
            }
838
            }