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 sybase extension
6
 * The PEAR DB driver for PHP's sybase extension
7
 * for interacting with Sybase databases
7
 * for interacting with Sybase 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     Sterling Hughes <sterling@php.net>
19
 * @author     Sterling Hughes <sterling@php.net>
20
 * @author     Antônio Carlos Venâncio Júnior <floripa@php.net>
20
 * @author     Antônio Carlos Venâncio Júnior <floripa@php.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
23
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
24
 * @version    CVS: $Id: sybase.php,v 1.78 2005/02/20 00:44: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 42... Line 42...
42
 * @category   Database
42
 * @category   Database
43
 * @package    DB
43
 * @package    DB
44
 * @author     Sterling Hughes <sterling@php.net>
44
 * @author     Sterling Hughes <sterling@php.net>
45
 * @author     Antônio Carlos Venâncio Júnior <floripa@php.net>
45
 * @author     Antônio Carlos Venâncio Júnior <floripa@php.net>
46
 * @author     Daniel Convissor <danielc@php.net>
46
 * @author     Daniel Convissor <danielc@php.net>
47
 * @copyright  1997-2005 The PHP Group
47
 * @copyright  1997-2007 The PHP Group
48
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
48
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
49
 * @version    Release: 1.7.6
49
 * @version    Release: 1.9.2
50
 * @link       http://pear.php.net/package/DB
50
 * @link       http://pear.php.net/package/DB
51
 */
51
 */
52
class DB_sybase extends DB_common
52
class DB_sybase extends DB_common
53
{
53
{
54
    // {{{ properties
54
    // {{{ properties
Line 139... Line 139...
139
 
139
 
140
    // }}}
140
    // }}}
Line 141... Line 141...
141
    // {{{ constructor
141
    // {{{ constructor
142
 
142
 
143
    /**
143
    /**
144
     * This constructor calls <kbd>$this->DB_common()</kbd>
144
     * This constructor calls <kbd>parent::__construct()</kbd>
145
     *
145
     *
146
     * @return void
146
     * @return void
147
     */
147
     */
148
    function DB_sybase()
148
    function __construct()
149
    {
149
    {
Line 150... Line 150...
150
        $this->DB_common();
150
        parent::__construct();
151
    }
151
    }
Line 246... Line 246...
246
     *                + the DB_OK constant for other successful queries
246
     *                + the DB_OK constant for other successful queries
247
     *                + a DB_Error object on failure
247
     *                + a DB_Error object on failure
248
     */
248
     */
249
    function simpleQuery($query)
249
    function simpleQuery($query)
250
    {
250
    {
251
        $ismanip = DB::isManip($query);
251
        $ismanip = $this->_checkManip($query);
252
        $this->last_query = $query;
252
        $this->last_query = $query;
253
        if (!@sybase_select_db($this->_db, $this->connection)) {
253
        if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
254
            return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
254
            return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
255
        }
255
        }
256
        $query = $this->modifyQuery($query);
256
        $query = $this->modifyQuery($query);
257
        if (!$this->autocommit && $ismanip) {
257
        if (!$this->autocommit && $ismanip) {
258
            if ($this->transaction_opcount == 0) {
258
            if ($this->transaction_opcount == 0) {
Line 368... Line 368...
368
     *
368
     *
369
     * @see DB_result::free()
369
     * @see DB_result::free()
370
     */
370
     */
371
    function freeResult($result)
371
    function freeResult($result)
372
    {
372
    {
373
        return @sybase_free_result($result);
373
        return is_resource($result) ? sybase_free_result($result) : false;
374
    }
374
    }
Line 375... Line 375...
375
 
375
 
376
    // }}}
376
    // }}}
Line 433... Line 433...
433
     *
433
     *
434
     * @return int  the number of rows.  A DB_Error object on failure.
434
     * @return int  the number of rows.  A DB_Error object on failure.
435
     */
435
     */
436
    function affectedRows()
436
    function affectedRows()
437
    {
437
    {
438
        if (DB::isManip($this->last_query)) {
438
        if ($this->_last_query_manip) {
439
            $result = @sybase_affected_rows($this->connection);
439
            $result = @sybase_affected_rows($this->connection);
440
        } else {
440
        } else {
441
            $result = 0;
441
            $result = 0;
442
        }
442
        }
443
        return $result;
443
        return $result;
Line 460... Line 460...
460
     *      DB_sybase::createSequence(), DB_sybase::dropSequence()
460
     *      DB_sybase::createSequence(), DB_sybase::dropSequence()
461
     */
461
     */
462
    function nextId($seq_name, $ondemand = true)
462
    function nextId($seq_name, $ondemand = true)
463
    {
463
    {
464
        $seqname = $this->getSequenceName($seq_name);
464
        $seqname = $this->getSequenceName($seq_name);
465
        if (!@sybase_select_db($this->_db, $this->connection)) {
465
        if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
466
            return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
466
            return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
467
        }
467
        }
468
        $repeat = 0;
468
        $repeat = 0;
469
        do {
469
        do {
470
            $this->pushErrorHandling(PEAR_ERROR_RETURN);
470
            $this->pushErrorHandling(PEAR_ERROR_RETURN);
Line 477... Line 477...
477
                $result = $this->createSequence($seq_name);
477
                $result = $this->createSequence($seq_name);
478
                if (DB::isError($result)) {
478
                if (DB::isError($result)) {
479
                    return $this->raiseError($result);
479
                    return $this->raiseError($result);
480
                }
480
                }
481
            } elseif (!DB::isError($result)) {
481
            } elseif (!DB::isError($result)) {
482
                $result =& $this->query("SELECT @@IDENTITY FROM $seqname");
482
                $result = $this->query("SELECT @@IDENTITY FROM $seqname");
483
                $repeat = 0;
483
                $repeat = 0;
484
            } else {
484
            } else {
485
                $repeat = false;
485
                $repeat = false;
486
            }
486
            }
487
        } while ($repeat);
487
        } while ($repeat);
Line 527... Line 527...
527
    {
527
    {
528
        return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
528
        return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));
529
    }
529
    }
Line 530... Line 530...
530
 
530
 
-
 
531
    // }}}
-
 
532
    // {{{ quoteFloat()
-
 
533
 
-
 
534
    /**
-
 
535
     * Formats a float value for use within a query in a locale-independent
-
 
536
     * manner.
-
 
537
     *
-
 
538
     * @param float the float value to be quoted.
-
 
539
     * @return string the quoted string.
-
 
540
     * @see DB_common::quoteSmart()
-
 
541
     * @since Method available since release 1.7.8.
-
 
542
     */
-
 
543
    function quoteFloat($float) {
-
 
544
        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
-
 
545
    }
-
 
546
     
531
    // }}}
547
    // }}}
Line 532... Line 548...
532
    // {{{ autoCommit()
548
    // {{{ autoCommit()
533
 
549
 
534
    /**
550
    /**
Line 556... Line 572...
556
     * @return int  DB_OK on success.  A DB_Error object on failure.
572
     * @return int  DB_OK on success.  A DB_Error object on failure.
557
     */
573
     */
558
    function commit()
574
    function commit()
559
    {
575
    {
560
        if ($this->transaction_opcount > 0) {
576
        if ($this->transaction_opcount > 0) {
561
            if (!@sybase_select_db($this->_db, $this->connection)) {
577
            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
562
                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
578
                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
563
            }
579
            }
564
            $result = @sybase_query('COMMIT', $this->connection);
580
            $result = @sybase_query('COMMIT', $this->connection);
565
            $this->transaction_opcount = 0;
581
            $this->transaction_opcount = 0;
566
            if (!$result) {
582
            if (!$result) {
Line 579... Line 595...
579
     * @return int  DB_OK on success.  A DB_Error object on failure.
595
     * @return int  DB_OK on success.  A DB_Error object on failure.
580
     */
596
     */
581
    function rollback()
597
    function rollback()
582
    {
598
    {
583
        if ($this->transaction_opcount > 0) {
599
        if ($this->transaction_opcount > 0) {
584
            if (!@sybase_select_db($this->_db, $this->connection)) {
600
            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
585
                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
601
                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
586
            }
602
            }
587
            $result = @sybase_query('ROLLBACK', $this->connection);
603
            $result = @sybase_query('ROLLBACK', $this->connection);
588
            $this->transaction_opcount = 0;
604
            $this->transaction_opcount = 0;
589
            if (!$result) {
605
            if (!$result) {
Line 640... Line 656...
640
     * @return integer  an error number from a DB error constant
656
     * @return integer  an error number from a DB error constant
641
     */
657
     */
642
    function errorCode($errormsg)
658
    function errorCode($errormsg)
643
    {
659
    {
644
        static $error_regexps;
660
        static $error_regexps;
-
 
661
        
-
 
662
        // PHP 5.2+ prepends the function name to $php_errormsg, so we need
-
 
663
        // this hack to work around it, per bug #9599.
-
 
664
        $errormsg = preg_replace('/^sybase[a-z_]+\(\): /', '', $errormsg);
-
 
665
        
645
        if (!isset($error_regexps)) {
666
        if (!isset($error_regexps)) {
646
            $error_regexps = array(
667
            $error_regexps = array(
647
                '/Incorrect syntax near/'
668
                '/Incorrect syntax near/'
648
                    => DB_ERROR_SYNTAX,
669
                    => DB_ERROR_SYNTAX,
649
                '/^Unclosed quote before the character string [\"\'].*[\"\']\./'
670
                '/^Unclosed quote before the character string [\"\'].*[\"\']\./'
Line 672... Line 693...
672
                    => DB_ERROR_NOT_FOUND,
693
                    => DB_ERROR_NOT_FOUND,
673
                '/^There is already an index/i'
694
                '/^There is already an index/i'
674
                    => DB_ERROR_ALREADY_EXISTS,
695
                    => DB_ERROR_ALREADY_EXISTS,
675
                '/^There are fewer columns in the INSERT statement than values specified/i'
696
                '/^There are fewer columns in the INSERT statement than values specified/i'
676
                    => DB_ERROR_VALUE_COUNT_ON_ROW,
697
                    => DB_ERROR_VALUE_COUNT_ON_ROW,
-
 
698
                '/Divide by zero/i'
-
 
699
                    => DB_ERROR_DIVZERO,
677
            );
700
            );
678
        }
701
        }
Line 679... Line 702...
679
 
702
 
680
        foreach ($error_regexps as $regexp => $code) {
703
        foreach ($error_regexps as $regexp => $code) {
Line 712... Line 735...
712
        if (is_string($result)) {
735
        if (is_string($result)) {
713
            /*
736
            /*
714
             * Probably received a table name.
737
             * Probably received a table name.
715
             * Create a result resource identifier.
738
             * Create a result resource identifier.
716
             */
739
             */
717
            if (!@sybase_select_db($this->_db, $this->connection)) {
740
            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
718
                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
741
                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
719
            }
742
            }
720
            $id = @sybase_query("SELECT * FROM $result WHERE 1=0",
743
            $id = @sybase_query("SELECT * FROM $result WHERE 1=0",
721
                                $this->connection);
744
                                $this->connection);
722
            $got_string = true;
745
            $got_string = true;
Line 809... Line 832...
809
 
832
 
810
        if ($table != $tableName) {
833
        if ($table != $tableName) {
811
            $flags = array();
834
            $flags = array();
Line -... Line 835...
-
 
835
            $tableName = $table;
-
 
836
 
-
 
837
            /* We're running sp_helpindex directly because it doesn't exist in
812
            $tableName = $table;
838
             * older versions of ASE -- unfortunately, we can't just use
813
 
839
             * DB::isError() because the user may be using callback error
Line 814... Line 840...
814
            // get unique/primary keys
840
             * handling. */
-
 
841
            $res = @sybase_query("sp_helpindex $table", $this->connection);
815
            $res = $this->getAll("sp_helpindex $table", DB_FETCHMODE_ASSOC);
842
 
816
 
843
            if ($res === false || $res === true) {
Line -... Line 844...
-
 
844
                // Fake a valid response for BC reasons.
-
 
845
                return '';
-
 
846
            }
-
 
847
 
817
            if (!isset($res[0]['index_description'])) {
848
            while (($val = sybase_fetch_assoc($res)) !== false) {
-
 
849
                if (!isset($val['index_keys'])) {
-
 
850
                    /* No useful information returned. Break and be done with
818
                return '';
851
                     * it, which preserves the pre-1.7.9 behaviour. */
Line 819... Line 852...
819
            }
852
                    break;
820
 
853
                }
821
            foreach ($res as $val) {
854
 
Line 832... Line 865...
832
                        $this->_add_flag($flags[$key], 'unique_key');
865
                        $this->_add_flag($flags[$key], 'unique_key');
833
                    }
866
                    }
834
                }
867
                }
835
            }
868
            }
Line -... Line 869...
-
 
869
 
-
 
870
            sybase_free_result($res);
836
 
871
 
Line 837... Line 872...
837
        }
872
        }
838
 
873
 
839
        if (array_key_exists($column, $flags)) {
874
        if (array_key_exists($column, $flags)) {