Ejemplo n.º 1
0
 public function freeDescriptor($descriptor)
 {
     set_error_handler(static::getErrorHandler());
     $isSuccess = oci_free_descriptor($descriptor);
     restore_error_handler();
     return $isSuccess;
 }
Ejemplo n.º 2
0
 public function bindParam($parameter, &$variable, $data_type = -1, $length = 0, $driver_options = null)
 {
     if ($parameter[0] != ':' && !is_numeric($parameter)) {
         $parameter = ':' . $parameter;
     }
     if (!$length) {
         $length = -1;
     }
     $params_info =& $this->_params_info;
     switch ($data_type) {
         case PDO::PARAM_INT:
             $type = SQLT_INT;
             break;
         case PDO::PARAM_LOB:
             if (isset($params_info[$parameter])) {
                 $p = $params_info[$parameter];
                 $lob = oci_new_descriptor($this->_link, OCI_DTYPE_LOB);
                 if (oci_bind_by_name($this->_result, $p, $lob, -1, SQLT_BLOB)) {
                     $this->_bound_params[$p] = 1;
                     $this->lobs[$p] = array(&$lob, &$variable);
                     return true;
                 }
                 oci_free_descriptor($lob);
             }
             return false;
             break;
         default:
             $type = SQLT_CHR;
             break;
     }
     if (isset($params_info[$parameter]) && oci_bind_by_name($this->_result, $params_info[$parameter], $variable, $length, $type)) {
         $this->_bound_params[$params_info[$parameter]] = 1;
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 protected function free_descriptors($descriptors)
 {
     foreach ($descriptors as $descriptor) {
         oci_free_descriptor($descriptor);
     }
 }
Ejemplo n.º 4
0
 protected function free_descriptors($descriptors)
 {
     foreach ($descriptors as $descriptor) {
         // Because all descriptors used in the driver come from LOB::writeTemporary() calls
         // we can safely close them here unconditionally.
         $descriptor->close();
         // Free resources.
         oci_free_descriptor($descriptor);
     }
 }
Ejemplo n.º 5
0
function send($id, $message, $conn)
{
    $stid = oci_parse($conn, "INSERT INTO MESSAGES (ID, AUTHOR, RECEPIENT, MESSAGE, MDATE)\n                              VALUES(SMESSAGES.nextval, :1,:6, EMPTY_CLOB(),(SYSDATE)) RETURNING MESSAGE INTO :7");
    $clob = oci_new_descriptor($conn, OCI_DTYPE_LOB);
    oci_bind_by_name($stid, ':1', $_SESSION['user_id']);
    oci_bind_by_name($stid, ':6', $id);
    oci_bind_by_name($stid, ':7', $clob, -1, OCI_B_CLOB);
    echo 'bitch!';
    oci_execute($stid, 0);
    $clob->save($message);
    oci_commit($conn);
    oci_free_descriptor($clob);
}
Ejemplo n.º 6
0
 public static function executequery($str_sql, $expect, $transaction, $ob)
 {
     if (is_array($transaction)) {
         self::interpolateQuery($str_sql, $transaction);
         if (self::$dbtype == self::ORACLE) {
             $rowcount = 1;
             if ($expect === self::ALL) {
                 $rowcount = self::getrowcount($str_sql, $transaction);
             }
             $parse = oci_parse(self::$ob[self::$database_in_use], $str_sql);
             $clobs = [];
             foreach ($transaction as $bindkey => $bindvalue) {
                 if (self::startswith($bindkey, "clob:")) {
                     $clob_descriptor = oci_new_descriptor(self::$ob[self::$database_in_use], OCI_DTYPE_LOB);
                     oci_bind_by_name($parse, $bindkey, $clob_descriptor, -1, SQLT_CLOB);
                     $clob_descriptor->writeTemporary($transaction[$bindkey], OCI_TEMP_CLOB);
                     $clobs[$bindkey] = $clob_descriptor;
                 } else {
                     oci_bind_by_name($parse, $bindkey, $transaction[$bindkey]);
                 }
             }
             $execute = isset(self::$transaction[self::$database_in_use]) && self::$transaction[self::$database_in_use] ? oci_execute($parse, OCI_NO_AUTO_COMMIT) : !empty($clobs) ? oci_execute($parse, OCI_DEFAULT) : oci_execute($parse);
             if ($execute) {
                 if ($expect === self::DEL || $expect === self::UPD || $expect === self::NUM) {
                     self::$lastquerytime[md5($str_sql)]["end"] = microtime(true);
                     return new RESULTSET(null, oci_num_rows($parse), self::NUM, true, true);
                 } else {
                     if ($expect === self::PUT || $expect === self::INS) {
                         if (!empty($clobs)) {
                             foreach ($clobs as $bindkey => $bindvalue) {
                                 $x = oci_free_descriptor($clobs[$bindkey]);
                             }
                             oci_commit(self::$ob[self::$database_in_use]);
                         }
                         self::$lastquerytime[md5($str_sql)]["end"] = microtime(true);
                         return new RESULTSET(null, self::lastInsertId(), self::INS, true, true);
                     } else {
                         if ($expect === self::FET) {
                             $result = oci_fetch_array($parse);
                             oci_free_statement($parse);
                             self::$lastquerytime[md5($str_sql)]["end"] = microtime(true);
                             return new RESULTSET($result, 1, self::FET, true, true);
                         } else {
                             self::$lastquerytime[md5($str_sql)]["end"] = microtime(true);
                             return new RESULTSET($parse, $rowcount, self::ALL, true, true);
                         }
                     }
                 }
             } else {
                 ob_start();
                 print_r($transaction);
                 $backtrace = ob_get_contents();
                 ob_end_clean();
                 $backtrace = "SQL:\n" . $str_sql . "\nVALUES:\n" . $backtrace;
                 self::oci8_debug($parse, $backtrace);
             }
         }
     } else {
         if ($transaction === self::TRA) {
             if (!isset(self::$transaction[self::$database_in_use]) || isset(self::$transaction[self::$database_in_use]) && !self::$transaction[self::$database_in_use]) {
                 self::$transaction[self::$database_in_use] = true;
                 return self::$transaction[self::$database_in_use];
             }
         } else {
             if ($transaction === self::COM) {
                 self::$transaction[self::$database_in_use] = false;
                 return oci_commit(self::$ob[self::$database_in_use]);
             } else {
                 if ($transaction === self::ROL) {
                     self::$transaction[self::$database_in_use] = false;
                     return oci_rollback(self::$ob[self::$database_in_use]);
                 } else {
                     self::interpolateQuery($str_sql, []);
                     if (self::$dbtype == self::ORACLE) {
                         $rowcount = 1;
                         if ($expect === self::ALL) {
                             $rowcount = self::getrowcount($str_sql, $transaction);
                         }
                         $parse = oci_parse(self::$ob[self::$database_in_use], $str_sql);
                         $execute = isset(self::$transaction[self::$database_in_use]) && self::$transaction[self::$database_in_use] ? oci_execute($parse, OCI_NO_AUTO_COMMIT) : oci_execute($parse);
                         if ($execute) {
                             if ($expect === self::DEL || $expect === self::UPD || $expect === self::NUM) {
                                 self::$lastquerytime[md5($str_sql)]["end"] = microtime(true);
                                 return new RESULTSET(null, oci_num_rows($parse), self::NUM, true, true);
                             } else {
                                 if ($expect === self::PUT || $expect === self::INS) {
                                     self::$lastquerytime[md5($str_sql)]["end"] = microtime(true);
                                     return new RESULTSET(null, self::lastInsertId(), self::INS, true, true);
                                 } else {
                                     if ($expect === self::FET) {
                                         $result = oci_fetch_array($parse);
                                         oci_free_statement($parse);
                                         self::$lastquerytime[md5($str_sql)]["end"] = microtime(true);
                                         return new RESULTSET($result, 1, self::FET, true, true);
                                     } else {
                                         self::$lastquerytime[md5($str_sql)]["end"] = microtime(true);
                                         return new RESULTSET($parse, $rowcount, self::ALL, true, true);
                                     }
                                 }
                             }
                         } else {
                             self::oci8_debug($parse, $str_sql);
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
 /**
  * Exécution d'une requête de base de données en utilisant
  *
  * @param	string 	$pQueryString	la requête à exécuter
  * @param 	string	$pParameters	les paramètres à donner à la requête
  * @param 	int		$pOffset		la ligne à partir de laquelle on veut récupérer les donénes
  * @param	int 	$pCount 		le nombre d'enregistrements que l'on souhaite récupérer à partir de l'offset
  * @return  array
  */
 private function _doQuery($pQueryString, $pParams = array(), $pOffset = null, $pCount = null)
 {
     $resultsOfQueryParsing = $this->_parseQuery($pQueryString, $pParams, $pOffset, $pCount);
     $pQueryString = $resultsOfQueryParsing['query'];
     //Préparation de la requête
     $stmt = ociparse($this->_ct, $pQueryString);
     if ($stmt === false) {
         throw new CopixDBException($pQueryString);
     }
     //On analyse les paramètres
     $arVariablesName = array();
     $arVariables = array();
     foreach ($pParams as $name => $param) {
         $variableName = substr($name, 1);
         if (!is_array($param)) {
             ${$variableName} = $param;
             if (!OCI_Bind_By_Name($stmt, $name, ${$variableName}, -1)) {
                 throw new CopixDBException("Bind ['{$name}'] - [" . ${$variableName} . "] taille [" . $arVariables[$variableName]['maxlength'] . "] type [" . $this->_convertQueryParam($arVariables[$variableName]['type']) . "]");
             }
             $arVariables[$variableName]['type'] = $this->_defaultBindType;
             $arVariables[$variableName]['value'] = $param;
             //               $arVariables[$variableName]['type'] = 'AUTO';
             //               $arVariables[$variableName]['value'] = $param;
         } else {
             if (!isset(${$variableName})) {
                 ${$variableName} = isset($param['value']) ? $param['value'] : null;
             }
             $arVariables[$variableName] = $param;
             if (!isset($arVariables[$variableName]['type'])) {
                 $arVariables[$variableName]['type'] = $this->_defaultBindType;
             }
             if (!isset($arVariables[$variableName]['maxlength'])) {
                 $arVariables[$variableName]['maxlength'] = $this->_defaultBindLength;
             }
             //        	   if (! isset ($arVariables[$variableName]['type'])){
             //        	   	$arVariables[$variableName]['type'] = CopixDBQueryParam::DB_AUTO;
             //       	   }
             //        	   if (! isset ($arVariables[$variableName]['maxlength'])){
             //        	   	$arVariables[$variableName]['maxlength'] = -1;
             //        	   }
             if ($arVariables[$variableName]['type'] === CopixDBQueryParam::DB_CURSOR) {
                 ${$variableName} = oci_new_cursor($this->_ct);
             }
             if (!OCI_Bind_By_Name($stmt, $name, ${$variableName}, $arVariables[$variableName]['maxlength'], $this->_convertQueryParam($arVariables[$variableName]['type']))) {
                 oci_free_statement($stmt);
                 throw new CopixDBException("Bind ['{$name}'] - [" . ${$variableName} . "] taille [" . $arVariables[$variableName]['maxlength'] . "] type [" . $this->_convertQueryParam($arVariables[$variableName]['type']) . "]");
             }
         }
     }
     //on exécute la requête
     if (!oci_execute($stmt, OCI_DEFAULT)) {
         $statementErrors = oci_error($stmt);
         oci_free_statement($stmt);
         throw new CopixDBException($pQueryString . ' - ' . var_export($statementErrors, true) . ' - ' . var_export($arVariables, true));
     }
     //Mise à jour des champs de type lob
     foreach ($arVariables as $name => $value) {
         //Si c'est un curseur
         if ($value['type'] === CopixDBQueryParam::DB_LOB || $value['type'] === CopixDBQueryParam::DB_BLOB || $value['type'] === CopixDBQueryParam::DB_CLOB) {
             ${$name}->save($value);
         }
     }
     //retourne les résultats.
     if ($resultsOfQueryParsing['isSelect']) {
         $results = array();
         while ($o = oci_fetch_array($stmt, OCI_ASSOC + OCI_RETURN_LOBS + OCI_RETURN_NULLS)) {
             $results[] = $this->_getCases($o, $pQueryString);
         }
     } else {
         $results = oci_num_rows($stmt);
     }
     //On commit si le mode est autocommit
     if ($this->_autoCommitMode == self::OCI_AUTO_COMMIT) {
         $this->commit();
     }
     //Libération des lobs
     foreach ($arVariables as $name => $value) {
         //Si c'est un curseur
         if ($value['type'] === CopixDBQueryParam::DB_LOB || $value['type'] === CopixDBQueryParam::DB_BLOB || $value['type'] === CopixDBQueryParam::DB_CLOB) {
             oci_free_descriptor(${$name});
         }
     }
     oci_free_statement($stmt);
     return $results;
 }