function DB_lo_open($conn, $file, $mode) { if (strcmp(phpversion(), '4.2.0') < 0) { return pg_loopen($conn, $file, $mode); } else { return pg_lo_open($conn, $file, $mode); } }
function GetLOBFieldValue($prepared_query, $parameter, $lob, &$value) { if (!$this->Connect()) { return 0; } if ($this->auto_commit && !@pg_Exec($this->connection, "BEGIN")) { return 0; } $success = 1; if ($lo = pg_locreate($this->connection)) { if ($handle = pg_loopen($this->connection, $lo, "w")) { while (!MetabaseEndOfLOB($lob)) { if (MetabaseReadLOB($lob, $data, $this->lob_buffer_length) < 0) { $this->SetError("Get LOB field value", MetabaseLOBError($lob)); $success = 0; break; } if (!pg_lowrite($handle, $data)) { $this->SetError("Get LOB field value", pg_ErrorMessage($this->connection)); $success = 0; break; } } pg_loclose($handle); if ($success) { $value = strval($lo); } } else { $this->SetError("Get LOB field value", pg_ErrorMessage($this->connection)); $success = 0; } if (!$success) { pg_lounlink($this->connection, $lo); } } else { $this->SetError("Get LOB field value", pg_ErrorMessage($this->connection)); $success = 0; } if ($this->auto_commit) { @pg_Exec($this->connection, "END"); } return $success; }
/** * Convert a text value into a DBMS specific format that is suitable to * compose query statements. * * @param resource $prepared_query query handle from prepare() * @param $parameter * @param $lob * @return string text string that represents the given argument value in * a DBMS specific format. * @access private */ function _getLobValue($prepared_query, $parameter, $lob) { $connect = $this->connect(); if (MDB::isError($connect)) { return $connect; } if ($this->auto_commit && !@pg_exec($this->connection, 'BEGIN')) { return $this->raiseError(MDB_ERROR, NULL, NULL, '_getLobValue: error starting transaction'); } if ($lo = @pg_locreate($this->connection)) { if ($handle = @pg_loopen($this->connection, $lo, 'w')) { while (!$this->endOfLob($lob)) { $result = $this->readLob($lob, $data, $this->options['lob_buffer_length']); if (MDB::isError($result)) { break; } if (!@pg_lowrite($handle, $data)) { $result = $this->raiseError(MDB_ERROR, NULL, NULL, 'Get LOB field value: ' . @pg_errormessage($this->connection)); break; } } @pg_loclose($handle); if (!MDB::isError($result)) { $value = strval($lo); } } else { $result = $this->raiseError(MDB_ERROR, NULL, NULL, 'Get LOB field value: ' . @pg_errormessage($this->connection)); } if (MDB::isError($result)) { $result = @pg_lounlink($this->connection, $lo); } } else { $result = $this->raiseError(MDB_ERROR, NULL, NULL, 'Get LOB field value: ' . pg_ErrorMessage($this->connection)); } if ($this->auto_commit) { @pg_exec($this->connection, 'END'); } if (MDB::isError($result)) { return $result; } return $value; }
function Open($mode = "rw") { if (version_compare(phpversion(), "4.2.0", "ge") > 0) { $this->result = pg_lo_open($this->dbconnect, $this->oid, $mode); } else { $this->result = pg_loopen($this->dbconnect, $this->oid, $mode); } return $this->result; }
/** * retrieve LOB from the database * * @param int $lob handle to a lob created by the createLOB() function * @return mixed MDB2_OK on success, a MDB2 error on failure * @access private */ function _retrieveLOB($lob) { $db =& $GLOBALS['_MDB2_databases'][$this->db_index]; if (!isset($db->lobs[$lob])) { return $db->raiseError(MDB2_ERROR_INVALID, null, null, 'did not specified a valid lob'); } if (!isset($db->lobs[$lob]['handle'])) { if ($db->auto_commit) { if (!pg_exec($db->connection, 'BEGIN')) { return $db->raiseError(); } $db->lobs[$lob]['in_transaction'] = true; } $db->lobs[$lob]['handle'] = @pg_loopen($db->connection, $db->lobs[$lob]['value'], 'r'); if (!$db->lobs[$lob]['handle']) { if (isset($db->lobs[$lob]['in_transaction'])) { @pg_Exec($db->connection, 'END'); unset($db->lobs[$lob]['in_transaction']); } unset($db->lobs[$lob]['value']); return $db->raiseError(); } } return MDB2_OK; }