本文整理汇总了PHP中OCINewDescriptor函数的典型用法代码示例。如果您正苦于以下问题:PHP OCINewDescriptor函数的具体用法?PHP OCINewDescriptor怎么用?PHP OCINewDescriptor使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OCINewDescriptor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadImageData
function uploadImageData($db, $file, $currentPictureId, $table, $id)
{
// insert the new record into the media's table and load the
// corresponding blob with the media's data
// (we use oracle's pseudo column rowid which identifies a row
// within a table (but not within a database) to refer to the
// right record later on)
$sql = "DECLARE\n obj ORDSYS.ORDImage;\n iblob BLOB;\n BEGIN\n SELECT image INTO obj FROM {$table}\n WHERE {$id} = {$currentPictureId} FOR UPDATE;\n\n iblob := obj.source.localData;\n :extblob := iblob;\n\n UPDATE {$table} SET image = obj WHERE {$id} = {$currentPictureId};\n END;";
// the function OCINewDescriptor allocates storage to hold descriptors or
// lob locators.
// see http://www.php.net/manual/en/function.ocinewdescriptor.php
$blob = OCINewDescriptor($db, OCI_D_LOB);
$sql = strtr($sql, chr(13) . chr(10), " ");
$stmt = OCIParse($db, $sql);
// the function OCIBindByName binds a PHP variable to a oracle placeholder
// (whether the variable will be used for input or output will be determined
// run-time, and the necessary storage space will be allocated)
// see http://www.php.net/manual/en/function.ocibindbyname.php
OCIBindByName($stmt, ':extblob', $blob, -1, OCI_B_BLOB);
echo "{$this->log} - {$sql} <br />";
OCIExecute($stmt, OCI_DEFAULT);
// read the files data and load it into the blob
$blob->savefile($file);
OCIFreeStatement($stmt);
$blob->free();
}
示例2: add_image
function add_image($name, $imagetype, $file)
{
if (!is_null($file)) {
if ($file["error"] != 0 || $file["size"] == 0) {
error("Incorrect Image");
} else {
if ($file["size"] < 1024 * 1024) {
global $DB;
$imageid = get_dbid("images", "imageid");
$image = fread(fopen($file["tmp_name"], "r"), filesize($file["tmp_name"]));
if ($DB['TYPE'] == "ORACLE") {
DBstart();
$lobimage = OCINewDescriptor($DB['DB'], OCI_D_LOB);
$stid = OCIParse($DB['DB'], "insert into images (imageid,name,imagetype,image)" . " values ({$imageid}," . zbx_dbstr($name) . "," . $imagetype . ",EMPTY_BLOB())" . " return image into :image");
if (!$stid) {
$e = ocierror($stid);
error("Parse SQL error [" . $e["message"] . "] in [" . $e["sqltext"] . "]");
return false;
}
OCIBindByName($stid, ':image', $lobimage, -1, OCI_B_BLOB);
if (!OCIExecute($stid, OCI_DEFAULT)) {
$e = ocierror($stid);
error("Execute SQL error [" . $e["message"] . "] in [" . $e["sqltext"] . "]");
return false;
}
$result = DBend($lobimage->save($image));
if (!$result) {
error("Couldn't save image!\n");
return false;
}
$lobimage->free();
OCIFreeStatement($stid);
return $stid;
} else {
if ($DB['TYPE'] == "POSTGRESQL") {
$image = pg_escape_bytea($image);
} else {
if ($DB['TYPE'] == "SQLITE3") {
$image = bin2hex($image);
}
}
}
return DBexecute("insert into images (imageid,name,imagetype,image)" . " values ({$imageid}," . zbx_dbstr($name) . "," . $imagetype . "," . zbx_dbstr($image) . ")");
} else {
error("Image size must be less than 1Mb");
}
}
} else {
error("Select image to download");
}
return false;
}
示例3: QueryB
function QueryB($sql)
{
global $conn;
$stmt = OCIParse($conn, $sql);
$DBody = OCINewDescriptor($conn, OCI_D_LOB);
OCIBindByName($stmt, ":Body_Loc", $DBody, -1, OCI_B_BLOB);
$err = OCIExecute($stmt, OCI_DEFAULT);
if (!$err) {
$error = OCIError($stmt);
//echo '<strong>Произошла ошибка: <font color="#889999">'.$error["message"].'</font><br>Запрос: <font color="#889999">'.$error["sqltext"].'</font></strong>';
QError($error);
die;
}
return $DBody;
}
示例4: retrieveImage
function retrieveImage($db, $id, $table, $column)
{
// the function OCINewDescriptor allocates storage to hold descriptors or
// lob locators,
// see http://www.php.net/manual/en/function.ocinewdescriptor.php
$data;
$blob = OCINewDescriptor($db, OCI_D_LOB);
// construct the sql query with which we will get the media's data
$sql = "DECLARE\n obj ORDSYS.ORDImage;\n BEGIN\n SELECT {$column} INTO obj FROM {$table} WHERE picture_id = :id;\n :extblob := obj.getContent;\n END;";
$sql = strtr($sql, chr(13) . chr(10), " ");
$stmt = OCIParse($db, $sql);
// the function OCIBindByName binds a PHP variable to a oracle placeholder
// (wheter the variable will be used for input or output will be determined
// run-time, and the necessary storage space will be allocated)
// see http://www.php.net/manual/en/function.ocibindbyname.php
OCIBindByName($stmt, ':extBlob', $blob, -1, OCI_B_BLOB);
OCIBindByName($stmt, ':id', $id);
OCIExecute($stmt, OCI_DEFAULT);
// load the binary data
$data = $blob->load();
return $data;
}
示例5: Bind
function Bind(&$stmt, &$var, $size = 4000, $type = false, $name = false)
{
if (!is_array($stmt)) {
return false;
}
if ($type == OCI_B_CURSOR && sizeof($stmt) >= 5) {
return OCIBindByName($stmt[1], ":" . $name, $stmt[4], $size, $type);
}
if ($name == false) {
if ($type !== false) {
$rez = OCIBindByName($stmt[1], ":" . $name, $var, $size, $type);
} else {
$rez = OCIBindByName($stmt[1], ":" . $stmt[2], $var, $size);
}
// +1 byte for null terminator
$stmt[2] += 1;
} else {
if ($type == OCI_B_BLOB) {
//we have to create a new Descriptor here
$_blob = OCINewDescriptor($this->_connectionID, OCI_D_LOB);
$rez = OCIBindByName($stmt[1], ":" . $name, &$_blob, -1, OCI_B_BLOB);
$rez = $_blob;
} else {
if ($type !== false) {
$rez = OCIBindByName($stmt[1], ":" . $name, $var, $size, $type);
} else {
$rez = OCIBindByName($stmt[1], ":" . $name, $var, $size);
}
// +1 byte for null terminator
}
}
return $rez;
}
示例6: write
public function write($id, $data)
{
$query = "MERGE INTO " . self::$_table["saveHandler"]["options"]["name"] . " M ";
$query .= "USING (SELECT '" . $id . "' AS ID, :TIME AS LIFETIME, :DADOS AS DATAVAL FROM DUAL) N ";
$query .= "ON (M." . self::$_table["saveHandler"]["options"]["primary"][0] . " = N.ID ) ";
$query .= "WHEN MATCHED THEN ";
$query .= "UPDATE SET M." . self::$_table["saveHandler"]["options"]["lifetimeColumn"] . " = N.LIFETIME, ";
$query .= "M." . self::$_table["saveHandler"]["options"]["dataColumn"] . " = N.DATAVAL ";
$query .= "WHEN NOT MATCHED THEN INSERT( " . self::$_table["saveHandler"]["options"]["primary"][0] . ", ";
$query .= self::$_table["saveHandler"]["options"]["lifetimeColumn"] . ", ";
$query .= self::$_table["saveHandler"]["options"]["dataColumn"] . " ) ";
$query .= "VALUES(N.ID, N.LIFETIME, N.DATAVAL) ";
$stmt = OCIParse(self::$_db, $query);
$clob = OCINewDescriptor(self::$_db, OCI_D_LOB);
OCIBindByName($stmt, ':TIME', time());
OCIBindByName($stmt, ':DADOS', $clob, -1, OCI_B_CLOB);
$clob->WriteTemporary($data, OCI_TEMP_CLOB);
$exe = OCIExecute($stmt, OCI_DEFAULT);
if ($exe === true) {
$ret = true;
OCICommit(self::$_db);
} else {
$ret = false;
OCIRollback(self::$_db);
}
$clob->close();
$clob->free();
OCIFreeStatement($stmt);
return $ret;
}
示例7: DBSaveLob
function DBSaveLob($connection, $sql, $blobParamName, $data, $lobType)
{
// Guarda datos en un clob..
global $dbError;
$lob = OCINewDescriptor($connection, OCI_D_LOB);
$stmt = OCIParse($connection, $sql);
OCIBindByName($stmt, ":" . $blobParamName, $lob, -1, $lobType);
$error = !oci_execute($stmt, OCI_DEFAULT);
$result = $lob->write($data);
if ($result) {
OCICommit($connection);
}
if ($error) {
$dbError = oci_error($stmt);
if (isset($dbError["offset"])) {
throw new Exception($dbError["message"]);
}
}
return $result;
}
示例8: array
/**
* Execute a prepared query statement helper method.
*
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access private
*/
function &_execute($result_class = true, $result_wrap_class = false)
{
if (is_null($this->statement)) {
$result =& parent::_execute($result_class, $result_wrap_class);
return $result;
}
$this->db->last_query = $this->query;
$this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'pre', 'parameters' => $this->values));
if ($this->db->getOption('disable_query')) {
$result = $this->is_manip ? 0 : null;
return $result;
}
$connection = $this->db->getConnection();
if (PEAR::isError($connection)) {
return $connection;
}
$result = MDB2_OK;
$lobs = $quoted_values = array();
$i = 0;
foreach ($this->positions as $parameter) {
if (!array_key_exists($parameter, $this->values)) {
return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'Unable to bind to missing placeholder: ' . $parameter, __FUNCTION__);
}
$value = $this->values[$parameter];
$type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null;
if ($type == 'clob' || $type == 'blob') {
$lobs[$i]['file'] = false;
if (is_resource($value)) {
$fp = $value;
$value = '';
while (!feof($fp)) {
$value .= fread($fp, 8192);
}
} elseif (preg_match('/^(\\w+:\\/\\/)(.*)$/', $value, $match)) {
$lobs[$i]['file'] = true;
if ($match[1] == 'file://') {
$value = $match[2];
}
}
$lobs[$i]['value'] = $value;
$lobs[$i]['descriptor'] = @OCINewDescriptor($connection, OCI_D_LOB);
if (!is_object($lobs[$i]['descriptor'])) {
$result = $this->db->raiseError(null, null, null, 'Unable to create descriptor for LOB in parameter: ' . $parameter, __FUNCTION__);
break;
}
$lob_type = $type == 'blob' ? OCI_B_BLOB : OCI_B_CLOB;
if (!@OCIBindByName($this->statement, ':' . $parameter, $lobs[$i]['descriptor'], -1, $lob_type)) {
$result = $this->db->raiseError($this->statement, null, null, 'could not bind LOB parameter', __FUNCTION__);
break;
}
} else {
$quoted_values[$i] = $this->db->quote($value, $type, false);
if (PEAR::isError($quoted_values[$i])) {
return $quoted_values[$i];
}
if (!@OCIBindByName($this->statement, ':' . $parameter, $quoted_values[$i])) {
$result = $this->db->raiseError($this->statement, null, null, 'could not bind non LOB parameter', __FUNCTION__);
break;
}
}
++$i;
}
$lob_keys = array_keys($lobs);
if (!PEAR::isError($result)) {
$mode = !empty($lobs) || $this->db->in_transaction ? OCI_DEFAULT : OCI_COMMIT_ON_SUCCESS;
if (!@OCIExecute($this->statement, $mode)) {
$err =& $this->db->raiseError($this->statement, null, null, 'could not execute statement', __FUNCTION__);
return $err;
}
if (!empty($lobs)) {
foreach ($lob_keys as $i) {
if (!is_null($lobs[$i]['value']) && $lobs[$i]['value'] !== '') {
if ($lobs[$i]['file']) {
$result = $lobs[$i]['descriptor']->savefile($lobs[$i]['value']);
} else {
$result = $lobs[$i]['descriptor']->save($lobs[$i]['value']);
}
if (!$result) {
$result = $this->db->raiseError(null, null, null, 'Unable to save descriptor contents', __FUNCTION__);
break;
}
}
}
if (!PEAR::isError($result)) {
if (!$this->db->in_transaction) {
if (!@OCICommit($connection)) {
$result = $this->db->raiseError(null, null, null, 'Unable to commit transaction', __FUNCTION__);
}
} else {
++$this->db->uncommitedqueries;
}
}
//.........这里部分代码省略.........
示例9: UpdateBlobFile
/**
* Usage: store file pointed to by $var in a blob
*/
function UpdateBlobFile($table, $column, $val, $where, $blobtype = 'BLOB')
{
switch (strtoupper($blobtype)) {
default:
ADOConnection::outp("<b>UpdateBlob</b>: Unknown blobtype={$blobtype}");
return false;
case 'BLOB':
$type = OCI_B_BLOB;
break;
case 'CLOB':
$type = OCI_B_CLOB;
break;
}
if ($this->databaseType == 'oci8po') {
$sql = "UPDATE {$table} set {$column}=EMPTY_{$blobtype}() WHERE {$where} RETURNING {$column} INTO ?";
} else {
$sql = "UPDATE {$table} set {$column}=EMPTY_{$blobtype}() WHERE {$where} RETURNING {$column} INTO :blob";
}
$desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB);
$arr['blob'] = array($desc, -1, $type);
$this->BeginTrans();
$rs = ADODB_oci8::Execute($sql, $arr);
if ($rez = !empty($rs)) {
$desc->savefile($val);
}
$desc->free();
$this->CommitTrans();
if ($rez) {
$rs->Close();
}
return $rez;
}
示例10: _doQuery
/**
* all the RDBMS specific things needed close a DB connection
*
* @access private
*/
function _doQuery($query, $first = 0, $limit = 0, $prepared_query = 0)
{
$lobs = 0;
$success = MDB_OK;
$result = 0;
$descriptors = array();
if ($prepared_query) {
$columns = '';
$variables = '';
for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
$position = key($this->clobs[$prepared_query]);
if (gettype($descriptors[$position] = @OCINewDescriptor($this->connection, OCI_D_LOB)) != 'object') {
$success = $this->raiseError(MDB_ERROR, NULL, NULL, 'Do query: Could not create descriptor for clob parameter');
break;
}
$columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['Fields'][$position - 1];
$variables .= ($lobs == 0 ? ' INTO ' : ',') . ':clob' . $position;
$lobs++;
}
if (!MDB::isError($success)) {
for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
$position = key($this->blobs[$prepared_query]);
if (gettype($descriptors[$position] = @OCINewDescriptor($this->connection, OCI_D_LOB)) != 'object') {
$success = $this->raiseError(MDB_ERROR, NULL, NULL, 'Do query: Could not create descriptor for blob parameter');
break;
}
$columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['Fields'][$position - 1];
$variables .= ($lobs == 0 ? ' INTO ' : ',') . ':blob' . $position;
$lobs++;
}
$query .= $columns . $variables;
}
}
if (!MDB::isError($success)) {
if ($statement = @OCIParse($this->connection, $query)) {
if ($lobs) {
for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
$position = key($this->clobs[$prepared_query]);
if (!@OCIBindByName($statement, ':clob' . $position, $descriptors[$position], -1, OCI_B_CLOB)) {
$success = $this->oci8RaiseError(NULL, 'Do query: Could not bind clob upload descriptor');
break;
}
}
if (!MDB::isError($success)) {
for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
$position = key($this->blobs[$prepared_query]);
if (!@OCIBindByName($statement, ':blob' . $position, $descriptors[$position], -1, OCI_B_BLOB)) {
$success = $this->oci8RaiseError(NULL, 'Do query: Could not bind blob upload descriptor');
break;
}
}
}
}
if (!MDB::isError($success)) {
if ($result = @OCIExecute($statement, $lobs == 0 && $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT)) {
if ($lobs) {
for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
$position = key($this->clobs[$prepared_query]);
$clob_stream = $this->prepared_queries[$prepared_query - 1]['Values'][$position - 1];
for ($value = ''; !$this->endOfLOB($clob_stream);) {
if ($this->readLOB($clob_stream, $data, $this->getOption('lob_buffer_length')) < 0) {
$success = $this->raiseError();
break;
}
$value .= $data;
}
if (!MDB::isError($success) && !$descriptors[$position]->save($value)) {
$success = $this->oci8RaiseError(NULL, 'Do query: Could not upload clob data');
}
}
if (!MDB::isError($success)) {
for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
$position = key($this->blobs[$prepared_query]);
$blob_stream = $this->prepared_queries[$prepared_query - 1]['Values'][$position - 1];
for ($value = ''; !$this->endOfLOB($blob_stream);) {
if ($this->readLOB($blob_stream, $data, $this->getOption('lob_buffer_length')) < 0) {
$success = $this->raiseError();
break;
}
$value .= $data;
}
if (!MDB::isError($success) && !$descriptors[$position]->save($value)) {
$success = $this->oci8RaiseError(NULL, 'Do query: Could not upload blob data');
}
}
}
}
if ($this->auto_commit) {
if ($lobs) {
if (MDB::isError($success)) {
if (!@OCIRollback($this->connection)) {
$success = $this->oci8RaiseError(NULL, 'Do query: ' . $success->getUserinfo() . ' and then could not rollback LOB updating transaction');
}
} else {
if (!@OCICommit($this->connection)) {
//.........这里部分代码省略.........
示例11: _doQuery
/**
* Execute a query
* @param string $query the SQL query
* @return mixed result identifier if query executed, else MDB2_error
* @access private
**/
function _doQuery($query, $ismanip = null, $prepared_query = 0)
{
$lobs = 0;
$success = MDB2_OK;
$result = 0;
$descriptors = array();
if ($prepared_query) {
$columns = '';
$variables = '';
for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
$clob_stream = key($this->clobs[$prepared_query]);
$descriptors[$clob_stream] = @OCINewDescriptor($this->connection, OCI_D_LOB);
if (!is_object($descriptors[$clob_stream])) {
$success = $this->raiseError(MDB2_ERROR, null, null, 'Could not create descriptor for clob parameter');
break;
}
$parameter = $GLOBALS['_MDB2_LOBs'][$clob_stream]->parameter;
$columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['fields'][$parameter - 1];
$variables .= ($lobs == 0 ? ' INTO ' : ',') . ':clob' . $parameter;
++$lobs;
}
if (!MDB2::isError($success)) {
for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
$blob_stream = key($this->blobs[$prepared_query]);
$descriptors[$blob_stream] = @OCINewDescriptor($this->connection, OCI_D_LOB);
if (!is_object($descriptors[$blob_stream])) {
$success = $this->raiseError(MDB2_ERROR, null, null, 'Could not create descriptor for blob parameter');
break;
}
$parameter = $GLOBALS['_MDB2_LOBs'][$blob_stream]->parameter;
$columns .= ($lobs == 0 ? ' RETURNING ' : ',') . $this->prepared_queries[$prepared_query - 1]['fields'][$parameter - 1];
$variables .= ($lobs == 0 ? ' INTO ' : ',') . ':blob' . $parameter;
++$lobs;
}
$query .= $columns . $variables;
}
}
if (!MDB2::isError($success)) {
if ($statement = @OCIParse($this->connection, $query)) {
if ($lobs) {
for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
$clob_stream = key($this->clobs[$prepared_query]);
$parameter = $GLOBALS['_MDB2_LOBs'][$clob_stream]->parameter;
if (!OCIBindByName($statement, ':clob' . $parameter, $descriptors[$clob_stream], -1, OCI_B_CLOB)) {
$success = $this->raiseError();
break;
}
}
if (!MDB2::isError($success)) {
for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
$blob_stream = key($this->blobs[$prepared_query]);
$parameter = $GLOBALS['_MDB2_LOBs'][$blob_stream]->parameter;
if (!OCIBindByName($statement, ':blob' . $parameter, $descriptors[$blob_stream], -1, OCI_B_BLOB)) {
$success = $this->raiseError();
break;
}
}
}
}
if (!MDB2::isError($success)) {
$mode = $lobs == 0 && $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT;
$result = @OCIExecute($statement, $mode);
if ($result) {
if ($lobs) {
for (reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, next($this->clobs[$prepared_query])) {
$clob_stream = key($this->clobs[$prepared_query]);
for ($value = ''; !$this->datatype->endOfLOB($clob_stream);) {
if ($this->datatype->readLOB($clob_stream, $data, $this->options['lob_buffer_length']) < 0) {
$success = $this->raiseError();
break;
}
$value .= $data;
}
if (!MDB2::isError($success) && !$descriptors[$clob_stream]->save($value)) {
$success = $this->raiseError();
}
}
if (!MDB2::isError($success)) {
for (reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, next($this->blobs[$prepared_query])) {
$blob_stream = key($this->blobs[$prepared_query]);
for ($value = ''; !$this->datatype->endOfLOB($blob_stream);) {
if ($this->datatype->readLOB($blob_stream, $data, $this->options['lob_buffer_length']) < 0) {
$success = $this->raiseError();
break;
}
$value .= $data;
}
if (!MDB2::isError($success) && !$descriptors[$blob_stream]->save($value)) {
$success = $this->raiseError();
}
}
}
}
if ($this->auto_commit) {
//.........这里部分代码省略.........
示例12: DoQuery
function DoQuery($query, $first = 0, $limit = 0, $prepared_query = 0)
{
$lobs = 0;
$success = 1;
$result = 0;
$descriptors = array();
if ($prepared_query) {
$columns = "";
$variables = "";
for (Reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, Next($this->clobs[$prepared_query])) {
$position = Key($this->clobs[$prepared_query]);
if (GetType($descriptors[$position] = OCINewDescriptor($this->connection, OCI_D_LOB)) != "object") {
$this->SetError("Do query", "Could not create descriptor for clob parameter");
$success = 0;
break;
}
$columns .= ($lobs == 0 ? " RETURNING " : ",") . $this->prepared_queries[$prepared_query - 1]["Fields"][$position - 1];
$variables .= ($lobs == 0 ? " INTO " : ",") . ":clob" . $position;
$lobs++;
}
if ($success) {
for (Reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, Next($this->blobs[$prepared_query])) {
$position = Key($this->blobs[$prepared_query]);
if (GetType($descriptors[$position] = OCINewDescriptor($this->connection, OCI_D_LOB)) != "object") {
$this->SetError("Do query", "Could not create descriptor for blob parameter");
$success = 0;
break;
}
$columns .= ($lobs == 0 ? " RETURNING " : ",") . $this->prepared_queries[$prepared_query - 1]["Fields"][$position - 1];
$variables .= ($lobs == 0 ? " INTO " : ",") . ":blob" . $position;
$lobs++;
}
$query .= $columns . $variables;
}
}
if ($success) {
if ($statement = OCIParse($this->connection, $query)) {
if ($lobs) {
for (Reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, Next($this->clobs[$prepared_query])) {
$position = Key($this->clobs[$prepared_query]);
if (!OCIBindByName($statement, ":clob" . $position, $descriptors[$position], -1, OCI_B_CLOB)) {
$this->SetOCIError("Do query", "Could not bind clob upload descriptor", OCIError($statement));
$success = 0;
break;
}
}
if ($success) {
for (Reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, Next($this->blobs[$prepared_query])) {
$position = Key($this->blobs[$prepared_query]);
if (!OCIBindByName($statement, ":blob" . $position, $descriptors[$position], -1, OCI_B_BLOB)) {
$this->SetOCIError("Do query", "Could not bind blob upload descriptor", OCIError($statement));
$success = 0;
break;
}
}
}
}
if ($success) {
if ($result = @OCIExecute($statement, $lobs == 0 && $this->auto_commit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT)) {
if ($lobs) {
for (Reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++, Next($this->clobs[$prepared_query])) {
$position = Key($this->clobs[$prepared_query]);
$clob_stream = $this->prepared_queries[$prepared_query - 1]["Values"][$position - 1];
for ($value = ""; !MetabaseEndOfLOB($clob_stream);) {
if (MetabaseReadLOB($clob_stream, $data, $this->lob_buffer_length) < 0) {
$this->SetError("Do query", MetabaseLOBError($clob));
$success = 0;
break;
}
$value .= $data;
}
if ($success && !$descriptors[$position]->save($value)) {
$this->SetOCIError("Do query", "Could not upload clob data", OCIError($statement));
$success = 0;
}
}
if ($success) {
for (Reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++, Next($this->blobs[$prepared_query])) {
$position = Key($this->blobs[$prepared_query]);
$blob_stream = $this->prepared_queries[$prepared_query - 1]["Values"][$position - 1];
for ($value = ""; !MetabaseEndOfLOB($blob_stream);) {
if (MetabaseReadLOB($blob_stream, $data, $this->lob_buffer_length) < 0) {
$this->SetError("Do query", MetabaseLOBError($blob));
$success = 0;
break;
}
$value .= $data;
}
if ($success && !$descriptors[$position]->save($value)) {
$this->SetOCIError("Do query", "Could not upload blob data", OCIError($statement));
$success = 0;
}
}
}
}
if ($this->auto_commit) {
if ($lobs) {
if ($success) {
if (!OCICommit($this->connection)) {
$this->SetOCIError("Do query", "Could not commit pending LOB updating transaction", OCIError());
//.........这里部分代码省略.........
示例13: _execute
/**
* Execute a prepared query statement helper method.
*
* @param mixed $result_class string which specifies which result class to use
* @param mixed $result_wrap_class string which specifies which class to wrap results in
*
* @return mixed MDB2_Result or integer (affected rows) on success,
* a MDB2 error on failure
* @access private
*/
function _execute($result_class = true, $result_wrap_class = false)
{
if (null === $this->statement) {
return parent::_execute($result_class, $result_wrap_class);
}
$this->db->last_query = $this->query;
$this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'pre', 'parameters' => $this->values));
if ($this->db->getOption('disable_query')) {
$result = $this->is_manip ? 0 : null;
return $result;
}
$connection = $this->db->getConnection();
if (PEAR::isError($connection)) {
return $connection;
}
$result = MDB2_OK;
$lobs = $quoted_values = array();
$i = 0;
foreach ($this->positions as $parameter) {
if (!array_key_exists($parameter, $this->values)) {
return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'Unable to bind to missing placeholder: ' . $parameter, __FUNCTION__);
}
$type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null;
if ($type == 'clob' || $type == 'blob') {
$lobs[$i]['file'] = false;
if (is_resource($this->values[$parameter])) {
$fp = $this->values[$parameter];
$this->values[$parameter] = '';
while (!feof($fp)) {
$this->values[$parameter] .= fread($fp, 8192);
}
} elseif (is_a($this->values[$parameter], 'OCI-Lob')) {
//do nothing
} elseif ($this->db->getOption('lob_allow_url_include') && preg_match('/^(\\w+:\\/\\/)(.*)$/', $this->values[$parameter], $match)) {
$lobs[$i]['file'] = true;
if ($match[1] == 'file://') {
$this->values[$parameter] = $match[2];
}
}
$lobs[$i]['value'] = $this->values[$parameter];
$lobs[$i]['descriptor'] =& $this->values[$parameter];
// Test to see if descriptor has already been created for this
// variable (i.e. if it has been bound more than once):
if (!is_a($this->values[$parameter], 'OCI-Lob')) {
$this->values[$parameter] = @OCINewDescriptor($connection, OCI_D_LOB);
if (false === $this->values[$parameter]) {
$result = $this->db->raiseError(null, null, null, 'Unable to create descriptor for LOB in parameter: ' . $parameter, __FUNCTION__);
break;
}
}
$lob_type = $type == 'blob' ? OCI_B_BLOB : OCI_B_CLOB;
if (!@OCIBindByName($this->statement, ':' . $parameter, $lobs[$i]['descriptor'], -1, $lob_type)) {
$result = $this->db->raiseError($this->statement, null, null, 'could not bind LOB parameter', __FUNCTION__);
break;
}
} else {
if ($type == OCI_B_BFILE) {
// Test to see if descriptor has already been created for this
// variable (i.e. if it has been bound more than once):
if (!is_a($this->values[$parameter], "OCI-Lob")) {
$this->values[$parameter] = @OCINewDescriptor($connection, OCI_D_FILE);
if (false === $this->values[$parameter]) {
$result = $this->db->raiseError(null, null, null, 'Unable to create descriptor for BFILE in parameter: ' . $parameter, __FUNCTION__);
break;
}
}
if (!@OCIBindByName($this->statement, ':' . $parameter, $this->values[$parameter], -1, $type)) {
$result = $this->db->raiseError($this->statement, null, null, 'Could not bind BFILE parameter', __FUNCTION__);
break;
}
} else {
if ($type == OCI_B_ROWID) {
// Test to see if descriptor has already been created for this
// variable (i.e. if it has been bound more than once):
if (!is_a($this->values[$parameter], "OCI-Lob")) {
$this->values[$parameter] = @OCINewDescriptor($connection, OCI_D_ROWID);
if (false === $this->values[$parameter]) {
$result = $this->db->raiseError(null, null, null, 'Unable to create descriptor for ROWID in parameter: ' . $parameter, __FUNCTION__);
break;
}
}
if (!@OCIBindByName($this->statement, ':' . $parameter, $this->values[$parameter], -1, $type)) {
$result = $this->db->raiseError($this->statement, null, null, 'Could not bind ROWID parameter', __FUNCTION__);
break;
}
} else {
if ($type == OCI_B_CURSOR) {
// Test to see if cursor has already been allocated for this
// variable (i.e. if it has been bound more than once):
if (!is_resource($this->values[$parameter]) || !get_resource_type($this->values[$parameter]) == "oci8 statement") {
//.........这里部分代码省略.........
示例14: UpdateBlob
/**
* Usage:
* Store BLOBs and CLOBs
*
* Example: to store $var in a blob
*
* $conn->Execute('insert into TABLE (id,ablobb) values(12,empty_blob())');
* $conn->UpdateBlob('TABLE', 'COLUMN', $var, 'ID=1', 'BLOB');
*
* $blobtype supports 'BLOB' and 'CLOB'
*
* to get length of LOB:
* select DBMS_LOB.GETLENGTH(ablob) from TABLE
*/
function UpdateBlob($table, $column, $val, $where, $blobtype = 'BLOB')
{
switch (strtoupper($blobtype)) {
default:
print "<b>UpdateBlob</b>: Unknown blobtype={$blobtype}<br>";
return false;
case 'BLOB':
$type = OCI_B_BLOB;
break;
case 'CLOB':
$type = OCI_B_CLOB;
break;
}
$sql = "UPDATE {$table} set {$column}=EMPTY_{$blobtype}() WHERE {$where} RETURNING {$column} INTO :blob";
$desc = OCINewDescriptor($this->_connectionID, OCI_D_LOB);
$arr['blob'] = array($desc, -1, $type);
$this->BeginTrans();
$rs = $this->Execute($sql, $arr);
$rez = !empty($rs);
$desc->save($val);
$desc->free();
$this->CommitTrans();
if ($rez) {
$rs->Close();
}
return $rez;
}
示例15: Bind
function Bind(&$stmt,&$var,$size=4000,$type=false,$name=false,$isOutput=false)
{
if (!is_array($stmt)) return false;
if (($type == OCI_B_CURSOR) && sizeof($stmt) >= 5) {
return OCIBindByName($stmt[1],":".$name,$stmt[4],$size,$type);
}
if ($name == false) {
if ($type !== false) $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size,$type);
else $rez = OCIBindByName($stmt[1],":".$stmt[2],$var,$size); // +1 byte for null terminator
$stmt[2] += 1;
} elseif (oci_lob_desc($type)) {
if ($this->debug) {
ADOConnection::outp("<b>Bind</b>: name = $name");
}
//we have to create a new Descriptor here
$numlob = count($this->_refLOBs);
$this->_refLOBs[$numlob]['LOB'] = OCINewDescriptor($this->_connectionID, oci_lob_desc($type));
$this->_refLOBs[$numlob]['TYPE'] = $isOutput;
$tmp = $this->_refLOBs[$numlob]['LOB'];
$rez = OCIBindByName($stmt[1], ":".$name, $tmp, -1, $type);
if ($this->debug) {
ADOConnection::outp("<b>Bind</b>: descriptor has been allocated, var (".$name.") binded");
}
// if type is input then write data to lob now
if ($isOutput == false) {
$var = $this->BlobEncode($var);
$tmp->WriteTemporary($var);
$this->_refLOBs[$numlob]['VAR'] = $var;
if ($this->debug) {
ADOConnection::outp("<b>Bind</b>: LOB has been written to temp");
}
} else {
$this->_refLOBs[$numlob]['VAR'] = $var;
}
$rez = $tmp;
} else {
if ($this->debug)
ADOConnection::outp("<b>Bind</b>: name = $name");
if ($type !== false) $rez = OCIBindByName($stmt[1],":".$name,$var,$size,$type);
else $rez = OCIBindByName($stmt[1],":".$name,$var,$size); // +1 byte for null terminator
}
return $rez;
}