Patch for oci8 driver for PEAR::DB

From: Date: Wed, 28 May 2003 09:42:49 +0000
Subject: Patch for oci8 driver for PEAR::DB
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16765@lists.php.net to get a copy of this message
Hi All. As I use prepared statement pretty much on a project I'm currently working on, I had a bad surprise testing my application with Oralce : For prepared statement, it does not accept the '!' mark. the oci8 driver uses the Oracle bind variable technique for prepared statement, thus, the '!' marker is useless. But my application needs to work with other DB's as well, and I need the '!' in my queries. For compatibility reasons, I simply added the management for the '!' in the prepare($query) method of the oci8 driver. Here is a dif and the modified method in the oci8.php script : diff : < $tokens = split('[\&\?]', $query); ---
$tokens = split('[\&\?\!]', $query);
           case '!':
               $types[$token++] = DB_PARAM_SCALAR;
               break;
method prepare :
    // {{{ prepare()
    /**
     * Prepares a query for multiple execution with execute().  With
     * oci8, this is emulated.
     * @param $query query to be prepared
     *
     * @return DB statement resource
     */
    function prepare($query)
    {
        $tokens = split('[\&\?\!]', $query);
        $token = 0;
        $types = array();
        for ($i = 0; $i < strlen($query); $i++) {
            switch ($query[$i]) {
                case '?':
                    $types[$token++] = DB_PARAM_SCALAR;
                    break;
                case '&':
                    $types[$token++] = DB_PARAM_OPAQUE;
                    break;
                case '!':
                    $types[$token++] = DB_PARAM_SCALAR;
                    break;
            }
        }
        $binds = sizeof($tokens) - 1;
        $newquery = '';
        for ($i = 0; $i < $binds; $i++) {
            $newquery .= $tokens[$i] . ":bind" . $i;
        }
        $newquery .= $tokens[$i];
        $this->last_query = $query;
        $newquery = $this->modifyQuery($newquery);
        $stmt = @OCIParse($this->connection, $newquery);
        $this->prepare_types[$stmt] = $types;
        $this->manip_query[(int)$stmt] = DB::isManip($query);
        return $stmt;
    }
As the driver uses the Oracle variable bind technique, the prepare() method simply does the same thing for '?' and '!' markers, but it allows my application to work with the same queries for Oracle and all other databases... Can this by applied as a patch for the oci8 PEAR::DB driver ??? (Of course, I can send you my modified version with this patch applied of the oci8.php script) Thanks, Antoine. -- Antoine ANGENIEUX http://www.clever-age.com Clever Age - conseil en architecture technique GSM: +33 6 63 58 36 95 Tél: +33 1 49 01 28 63

« previous php.pear.dev (#16765) next »