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 7... Line 7...
7
 * for interacting with Interbase and Firebird databases
7
 * for interacting with Interbase and Firebird databases
8
 *
8
 *
9
 * While this class works with PHP 4, PHP's InterBase extension is
9
 * While this class works with PHP 4, PHP's InterBase extension is
10
 * unstable in PHP 4.  Use PHP 5.
10
 * unstable in PHP 4.  Use PHP 5.
11
 *
11
 *
12
 * PHP versions 4 and 5
12
 * PHP version 5
13
 *
13
 *
14
 * LICENSE: This source file is subject to version 3.0 of the PHP license
14
 * LICENSE: This source file is subject to version 3.0 of the PHP license
15
 * that is available through the world-wide-web at the following URI:
15
 * that is available through the world-wide-web at the following URI:
16
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
16
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
17
 * the PHP License and are unable to obtain it through the web, please
17
 * the PHP License and are unable to obtain it through the web, please
Line 19... Line 19...
19
 *
19
 *
20
 * @category   Database
20
 * @category   Database
21
 * @package    DB
21
 * @package    DB
22
 * @author     Sterling Hughes <sterling@php.net>
22
 * @author     Sterling Hughes <sterling@php.net>
23
 * @author     Daniel Convissor <danielc@php.net>
23
 * @author     Daniel Convissor <danielc@php.net>
24
 * @copyright  1997-2005 The PHP Group
24
 * @copyright  1997-2007 The PHP Group
25
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
25
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
26
 * @version    CVS: $Id: ibase.php,v 1.109 2005/03/04 23:12:36 danielc Exp $
26
 * @version    CVS: $Id$
27
 * @link       http://pear.php.net/package/DB
27
 * @link       http://pear.php.net/package/DB
28
 */
28
 */
Line 29... Line 29...
29
 
29
 
30
/**
30
/**
Line 45... Line 45...
45
 *
45
 *
46
 * @category   Database
46
 * @category   Database
47
 * @package    DB
47
 * @package    DB
48
 * @author     Sterling Hughes <sterling@php.net>
48
 * @author     Sterling Hughes <sterling@php.net>
49
 * @author     Daniel Convissor <danielc@php.net>
49
 * @author     Daniel Convissor <danielc@php.net>
50
 * @copyright  1997-2005 The PHP Group
50
 * @copyright  1997-2007 The PHP Group
51
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
51
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
52
 * @version    Release: 1.7.6
52
 * @version    Release: 1.9.2
53
 * @link       http://pear.php.net/package/DB
53
 * @link       http://pear.php.net/package/DB
54
 * @since      Class became stable in Release 1.7.0
54
 * @since      Class became stable in Release 1.7.0
55
 */
55
 */
56
class DB_ibase extends DB_common
56
class DB_ibase extends DB_common
57
{
57
{
Line 121... Line 121...
121
        -552 => DB_ERROR_ACCESS_VIOLATION,
121
        -552 => DB_ERROR_ACCESS_VIOLATION,
122
        // -607 =>  // Covers too many errors, need to use regex on msg
122
        // -607 =>  // Covers too many errors, need to use regex on msg
123
        -625 => DB_ERROR_CONSTRAINT_NOT_NULL,
123
        -625 => DB_ERROR_CONSTRAINT_NOT_NULL,
124
        -803 => DB_ERROR_CONSTRAINT,
124
        -803 => DB_ERROR_CONSTRAINT,
125
        -804 => DB_ERROR_VALUE_COUNT_ON_ROW,
125
        -804 => DB_ERROR_VALUE_COUNT_ON_ROW,
-
 
126
        // -902 =>  // Covers too many errors, need to use regex on msg
126
        -904 => DB_ERROR_CONNECT_FAILED,
127
        -904 => DB_ERROR_CONNECT_FAILED,
127
        -922 => DB_ERROR_NOSUCHDB,
128
        -922 => DB_ERROR_NOSUCHDB,
128
        -923 => DB_ERROR_CONNECT_FAILED,
129
        -923 => DB_ERROR_CONNECT_FAILED,
129
        -924 => DB_ERROR_CONNECT_FAILED
130
        -924 => DB_ERROR_CONNECT_FAILED
130
    );
131
    );
Line 177... Line 178...
177
 
178
 
178
    // }}}
179
    // }}}
Line 179... Line 180...
179
    // {{{ constructor
180
    // {{{ constructor
180
 
181
 
181
    /**
182
    /**
182
     * This constructor calls <kbd>$this->DB_common()</kbd>
183
     * This constructor calls <kbd>parent::__construct()</kbd>
183
     *
184
     *
184
     * @return void
185
     * @return void
185
     */
186
     */
186
    function DB_ibase()
187
    function __construct()
187
    {
188
    {
Line 188... Line 189...
188
        $this->DB_common();
189
        parent::__construct();
189
    }
190
    }
Line 273... Line 274...
273
     *                + the DB_OK constant for other successful queries
274
     *                + the DB_OK constant for other successful queries
274
     *                + a DB_Error object on failure
275
     *                + a DB_Error object on failure
275
     */
276
     */
276
    function simpleQuery($query)
277
    function simpleQuery($query)
277
    {
278
    {
278
        $ismanip = DB::isManip($query);
279
        $ismanip = $this->_checkManip($query);
279
        $this->last_query = $query;
280
        $this->last_query = $query;
280
        $query = $this->modifyQuery($query);
281
        $query = $this->modifyQuery($query);
281
        $result = @ibase_query($this->connection, $query);
282
        $result = @ibase_query($this->connection, $query);
Line 282... Line 283...
282
 
283
 
Line 410... Line 411...
410
     *
411
     *
411
     * @see DB_result::free()
412
     * @see DB_result::free()
412
     */
413
     */
413
    function freeResult($result)
414
    function freeResult($result)
414
    {
415
    {
415
        return @ibase_free_result($result);
416
        return is_resource($result) ? ibase_free_result($result) : false;
416
    }
417
    }
Line 417... Line 418...
417
 
418
 
418
    // }}}
419
    // }}}
Line 419... Line 420...
419
    // {{{ freeQuery()
420
    // {{{ freeQuery()
420
 
421
 
421
    function freeQuery($query)
422
    function freeQuery($query)
422
    {
-
 
423
        @ibase_free_query($query);
423
    {
Line 424... Line 424...
424
        return true;
424
        return is_resource($query) ? ibase_free_query($query) : false;
425
    }
425
    }
Line 519... Line 519...
519
 
519
 
520
        $newquery = substr($newquery, 0, -1);
520
        $newquery = substr($newquery, 0, -1);
521
        $this->last_query = $query;
521
        $this->last_query = $query;
522
        $newquery = $this->modifyQuery($newquery);
522
        $newquery = $this->modifyQuery($newquery);
-
 
523
        $stmt = @ibase_prepare($this->connection, $newquery);
-
 
524
 
-
 
525
        if ($stmt === false) {
-
 
526
            $stmt = $this->ibaseRaiseError();
523
        $stmt = @ibase_prepare($this->connection, $newquery);
527
        } else {
524
        $this->prepare_types[(int)$stmt] = $types;
528
            $this->prepare_types[(int)$stmt] = $types;
-
 
529
            $this->manip_query[(int)$stmt]   = DB::isManip($query);
-
 
530
        }
525
        $this->manip_query[(int)$stmt]   = DB::isManip($query);
531
 
526
        return $stmt;
532
        return $stmt;
Line 527... Line 533...
527
    }
533
    }
528
 
534
 
Line 545... Line 551...
545
    function &execute($stmt, $data = array())
551
    function &execute($stmt, $data = array())
546
    {
552
    {
547
        $data = (array)$data;
553
        $data = (array)$data;
548
        $this->last_parameters = $data;
554
        $this->last_parameters = $data;
Line 549... Line 555...
549
 
555
 
550
        $types =& $this->prepare_types[(int)$stmt];
556
        $types = $this->prepare_types[(int)$stmt];
551
        if (count($types) != count($data)) {
557
        if (count($types) != count($data)) {
552
            $tmp =& $this->raiseError(DB_ERROR_MISMATCH);
558
            $tmp = $this->raiseError(DB_ERROR_MISMATCH);
553
            return $tmp;
559
            return $tmp;
Line 554... Line 560...
554
        }
560
        }
555
 
561
 
Line 566... Line 572...
566
                $data[$key] = preg_replace("/^'(.*)'$/", "\\1", $data[$key]);
572
                $data[$key] = preg_replace("/^'(.*)'$/", "\\1", $data[$key]);
567
                $data[$key] = str_replace("''", "'", $data[$key]);
573
                $data[$key] = str_replace("''", "'", $data[$key]);
568
            } elseif ($types[$i] == DB_PARAM_OPAQUE) {
574
            } elseif ($types[$i] == DB_PARAM_OPAQUE) {
569
                $fp = @fopen($data[$key], 'rb');
575
                $fp = @fopen($data[$key], 'rb');
570
                if (!$fp) {
576
                if (!$fp) {
571
                    $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
577
                    $tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION);
572
                    return $tmp;
578
                    return $tmp;
573
                }
579
                }
574
                $data[$key] = fread($fp, filesize($data[$key]));
580
                $data[$key] = fread($fp, filesize($data[$key]));
575
                fclose($fp);
581
                fclose($fp);
576
            }
582
            }
Line 579... Line 585...
579
 
585
 
Line 580... Line 586...
580
        array_unshift($data, $stmt);
586
        array_unshift($data, $stmt);
581
 
587
 
582
        $res = call_user_func_array('ibase_execute', $data);
588
        $res = call_user_func_array('ibase_execute', $data);
583
        if (!$res) {
589
        if (!$res) {
584
            $tmp =& $this->ibaseRaiseError();
590
            $tmp = $this->ibaseRaiseError();
585
            return $tmp;
591
            return $tmp;
586
        }
592
        }
587
        /* XXX need this?
593
        /* XXX need this?
588
        if ($this->autocommit && $this->manip_query[(int)$stmt]) {
594
        if ($this->autocommit && $this->manip_query[(int)$stmt]) {
589
            @ibase_commit($this->connection);
595
            @ibase_commit($this->connection);
-
 
596
        }*/
590
        }*/
597
        $this->last_stmt = $stmt;
-
 
598
        if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) {
591
        $this->last_stmt = $stmt;
599
            $this->_last_query_manip = true;
592
        if ($this->manip_query[(int)$stmt]) {
600
            $this->_next_query_manip = false;
-
 
601
            $tmp = DB_OK;
593
            $tmp = DB_OK;
602
        } else {
594
        } else {
603
            $this->_last_query_manip = false;
595
            $tmp =& new DB_result($this, $res);
604
            $tmp = new DB_result($this, $res);
596
        }
605
        }
Line 597... Line 606...
597
        return $tmp;
606
        return $tmp;
Line 696... Line 705...
696
    {
705
    {
697
        $sqn = strtoupper($this->getSequenceName($seq_name));
706
        $sqn = strtoupper($this->getSequenceName($seq_name));
698
        $repeat = 0;
707
        $repeat = 0;
699
        do {
708
        do {
700
            $this->pushErrorHandling(PEAR_ERROR_RETURN);
709
            $this->pushErrorHandling(PEAR_ERROR_RETURN);
701
            $result =& $this->query("SELECT GEN_ID(${sqn}, 1) "
710
            $result = $this->query("SELECT GEN_ID(${sqn}, 1) "
702
                                   . 'FROM RDB$GENERATORS '
711
                                   . 'FROM RDB$GENERATORS '
703
                                   . "WHERE RDB\$GENERATOR_NAME='${sqn}'");
712
                                   . "WHERE RDB\$GENERATOR_NAME='${sqn}'");
704
            $this->popErrorHandling();
713
            $this->popErrorHandling();
705
            if ($ondemand && DB::isError($result)) {
714
            if ($ondemand && DB::isError($result)) {
706
                $repeat = 1;
715
                $repeat = 1;
Line 854... Line 863...
854
    function &ibaseRaiseError($errno = null)
863
    function &ibaseRaiseError($errno = null)
855
    {
864
    {
856
        if ($errno === null) {
865
        if ($errno === null) {
857
            $errno = $this->errorCode($this->errorNative());
866
            $errno = $this->errorCode($this->errorNative());
858
        }
867
        }
859
        $tmp =& $this->raiseError($errno, null, null, null, @ibase_errmsg());
868
        $tmp = $this->raiseError($errno, null, null, null, @ibase_errmsg());
860
        return $tmp;
869
        return $tmp;
861
    }
870
    }
Line 862... Line 871...
862
 
871
 
863
    // }}}
872
    // }}}
Line 905... Line 914...
905
        static $error_regexps;
914
        static $error_regexps;
906
        if (!isset($error_regexps)) {
915
        if (!isset($error_regexps)) {
907
            $error_regexps = array(
916
            $error_regexps = array(
908
                '/generator .* is not defined/'
917
                '/generator .* is not defined/'
909
                    => DB_ERROR_SYNTAX,  // for compat. w ibase_errcode()
918
                    => DB_ERROR_SYNTAX,  // for compat. w ibase_errcode()
-
 
919
                '/violation of [\w ]+ constraint/i'
-
 
920
                    => DB_ERROR_CONSTRAINT,
910
                '/table.*(not exist|not found|unknown)/i'
921
                '/table.*(not exist|not found|unknown)/i'
911
                    => DB_ERROR_NOSUCHTABLE,
922
                    => DB_ERROR_NOSUCHTABLE,
912
                '/table .* already exists/i'
923
                '/table .* already exists/i'
913
                    => DB_ERROR_ALREADY_EXISTS,
924
                    => DB_ERROR_ALREADY_EXISTS,
914
                '/unsuccessful metadata update .* failed attempt to store duplicate value/i'
925
                '/unsuccessful metadata update .* failed attempt to store duplicate value/i'
915
                    => DB_ERROR_ALREADY_EXISTS,
926
                    => DB_ERROR_ALREADY_EXISTS,
916
                '/unsuccessful metadata update .* not found/i'
927
                '/unsuccessful metadata update .* not found/i'
917
                    => DB_ERROR_NOT_FOUND,
928
                    => DB_ERROR_NOT_FOUND,
918
                '/validation error for column .* value "\*\*\* null/i'
929
                '/validation error for column .* value "\*\*\* null/i'
919
                    => DB_ERROR_CONSTRAINT_NOT_NULL,
930
                    => DB_ERROR_CONSTRAINT_NOT_NULL,
920
                '/violation of [\w ]+ constraint/i'
-
 
921
                    => DB_ERROR_CONSTRAINT,
-
 
922
                '/conversion error from string/i'
931
                '/conversion error from string/i'
923
                    => DB_ERROR_INVALID_NUMBER,
932
                    => DB_ERROR_INVALID_NUMBER,
924
                '/no permission for/i'
933
                '/no permission for/i'
925
                    => DB_ERROR_ACCESS_VIOLATION,
934
                    => DB_ERROR_ACCESS_VIOLATION,
926
                '/arithmetic exception, numeric overflow, or string truncation/i'
935
                '/arithmetic exception, numeric overflow, or string truncation/i'
927
                    => DB_ERROR_INVALID,
936
                    => DB_ERROR_INVALID,
-
 
937
                '/feature is not supported/i'
-
 
938
                    => DB_ERROR_NOT_CAPABLE,
928
            );
939
            );
929
        }
940
        }
Line 930... Line 941...
930
 
941
 
931
        $errormsg = @ibase_errmsg();
942
        $errormsg = @ibase_errmsg();