Exemplo n.º 1
0
 public function testExecutePersist()
 {
     $fileIn = tempnam(sys_get_temp_dir(), 'PgOidIn');
     file_put_contents($fileIn, 'content');
     $lo = new PgLargeObject($fileIn);
     $this->assertTrue($lo->isNew());
     $this->assertTrue($lo->isChanged());
     $this->assertFalse($lo->isDeleted());
     $this->assertSame($lo->getFilePath(), $fileIn);
     $task = new Persist($this->entityManager->recordManager);
     $task->setObject($lo);
     $this->assertTrue($task->execute($this->db));
     $this->assertFalse($lo->isNew());
     $this->assertFalse($lo->isChanged());
     $this->assertFalse($lo->isDeleted());
     $this->assertNull($lo->getFilePath());
     // the task has been inserted correctly
     $this->assertTrue(is_numeric($lo->getOid()));
     $this->db->query(new PgQuery('BEGIN'));
     $fileOut = tempnam(sys_get_temp_dir(), 'PgOidOut');
     pg_lo_export($this->db->resource->get(), $lo->getOid(), $fileOut);
     $this->db->query(new PgQuery('COMMIT'));
     $this->assertFileEquals($fileIn, $fileOut);
     pg_lo_unlink($this->db->resource->get(), $lo->getOid());
 }
Exemplo n.º 2
0
 public function getblob($oid, $filename)
 {
     $this->query = pg_query($this->dbhandle, "begin");
     $blob = pg_lo_export($this->dbhandle, $oid, $filename);
     pg_query($this->dbhandle, "commit");
     return $blob;
     //TODO: kontola, ali je bil query ok izveden!
 }
 /**
  * Executa leitura de um arquivo LO apartir de seu OID, e o gera no caminho ($sCaminhoArquivo)
  * @param integer $iOid
  * @param string $sCaminhoArquivo
  */
 public static function leitura($iOid, $sCaminhoArquivo)
 {
     global $conn;
     if (!db_utils::inTransaction()) {
         throw new Exception("Sem transação Ativa.");
     }
     $lEscritaArquivo = pg_lo_export($iOid, $sCaminhoArquivo, $conn);
     return $lEscritaArquivo;
 }
 /**
  * Exporta o arquivo para o tmp
  * 
  * @param integer $iOid
  *        	OID do arquivo no banco
  * @return mixed - Nome do arquivo ou false em caso de erro
  */
 public function baixarDocumento($iOid)
 {
     $oDataSource = $this->getDataSource();
     $oDataSource->begin($this);
     $lArquivo = pg_lo_export($oDataSource->connection, $iOid, DS . "tmp" . DS . $iOid);
     $oDataSource->commit($this);
     if (!$lArquivo) {
         return false;
     }
     return array('path' => DS . 'tmp' . DS, 'file' => $iOid);
 }
 /**
  * Configura o arquivo para download
  * 
  * @param integer $iCodigoDocumento        	
  * @return array
  */
 public function download($iCodigoDocumento)
 {
     $aDocumento = $this->find("first", array("fields" => array("documento", "nome"), "conditions" => "id = {$iCodigoDocumento}"));
     $iOidDocumento = $aDocumento["LicitacaoDocumento"]['documento'];
     $sNomeDocumento = $aDocumento["LicitacaoDocumento"]['nome'];
     $sNomeDocumento = str_replace(" ", "", $sNomeDocumento);
     $sNomeDocumento = str_replace("º", "", $sNomeDocumento);
     $sNomeDocumento = str_replace("ª", "", $sNomeDocumento);
     $oDataSource = $resDataSource = $this->getDataSource();
     $oDataSource->begin();
     $lExportArquivo = pg_lo_export($oDataSource->connection, $iOidDocumento, self::PATH_ARQUIVO . $sNomeDocumento);
     $oDataSource->commit();
     if (!$lExportArquivo) {
         return false;
     }
     return self::PATH_ARQUIVO . $sNomeDocumento;
 }
Exemplo n.º 6
0
 public function loExport($oid, $pathname)
 {
     assert('is_int($oid)');
     assert('is_string($pathname)');
     return pg_lo_export($this->_pg, $oid, $pathname);
 }
Exemplo n.º 7
0
 protected function _fetch_lob(&$p, &$col)
 {
     $tmp_file = tempnam(sys_get_temp_dir(), 'phppdo_');
     if (!$tmp_file) {
         return false;
     }
     if (!@pg_lo_export($this->_link, $col, $tmp_file)) {
         // maybe this is a 'bytea'
         return parent::_fetch_lob($p, $col);
     }
     $p = fopen($tmp_file, 'rb');
     if ($p) {
         $this->tmp_lobs[$tmp_file] = $p;
     }
 }
Exemplo n.º 8
0
function DB_lo_export($contest, $conn, $oid, $file)
{
    if (strcmp(phpversion(), '4.2.0') < 0) {
        $stat = pg_loexport($oid, $file, $conn);
    } else {
        $stat = pg_lo_export($oid, $file, $conn);
    }
    if ($stat === false) {
        return false;
    }
    if (!is_readable($file)) {
        return false;
    }
    if (($str = DB_unlock($contest, file_get_contents($file), $conn)) !== false) {
        file_put_contents($file, $str);
        return 2;
    }
    return 1;
}
Exemplo n.º 9
0
 function lo_export($p_oid, $tmp)
 {
     return pg_lo_export($this->db, $p_oid, $tmp);
 }
function db_buscaImagemBanco($cadban, $conn)
{
    /*
     * $cadban = codigo k15_codigo da cadban
     * $conn   =  conexão
     */
    $sqlcodban = "select k15_codbco from cadban where k15_codigo = {$cadban}";
    $resultcadban = db_query($sqlcodban);
    $linhascadban = pg_num_rows($resultcadban);
    if ($linhascadban > 0) {
        //db_fieldsmemory($resultcadban,0);
        $k15_codbco = pg_result($resultcadban, 0, "k15_codbco");
        $banco = str_pad($k15_codbco, 3, "0", STR_PAD_LEFT);
        // busca os dados do banco..logo etc
        $sqlBanco = "select  * from db_bancos where db90_codban = '" . $banco . "'";
        $resultBanco = db_query($sqlBanco);
        $linhasBanco = pg_num_rows($resultBanco);
        if ($linhasBanco > 0) {
            //db_fieldsmemory($resultBanco,0);
            $db90_digban = pg_result($resultBanco, 0, "db90_digban");
            $db90_abrev = pg_result($resultBanco, 0, "db90_abrev");
            $db90_logo = pg_result($resultBanco, 0, "db90_logo");
            // se não tiver os dados do banco na db_bancos não deve emitir o recibo.
            if ($db90_digban == "" || $db90_abrev == "" || $db90_logo == "") {
                return false;
                //	  	db_redireciona('db_erros.php?fechar=true&db_erro=Configure os dados(Digito verificador, Nome abreviado do banco e o Arquivo do logo) do Banco: '.$banco.'-'.$db90_descr.', no Cadastro de Bancos');
            }
            // seta os dados para o boleto passando as informações do logo
            db_query($conn, "begin");
            $caminho = "tmp/" . $banco . ".jpg";
            pg_lo_export("{$db90_logo}", $caminho, $conn);
            db_query($conn, "commit");
            $arr = array("numbanco" => $banco . "-" . $db90_digban, "banco" => $db90_abrev, "imagemlogo" => $caminho);
            return $arr;
        } else {
            // se não tiver o banco na db_bancos
            db_redireciona('db_erros.php?fechar=true&db_erro=Não existe Banco cadastrado para o código' . $banco . ' no Cadastro de Bancos' . $sqlBanco);
        }
    }
}
 function getImagemBanco()
 {
     $sSqlBanco = " select  * \t\t\t\t\t\t \t\t\t                  ";
     $sSqlBanco .= "   from db_bancos\t\t\t\t\t\t\t                ";
     $sSqlBanco .= "  where db90_codban = '{$this->getCodBanco()}' ";
     $rsBanco = pg_query($sSqlBanco);
     $iNroLinhasBanco = pg_num_rows($rsBanco);
     if ($iNroLinhasBanco > 0) {
         $oBanco = db_utils::fieldsMemory($rsBanco, 0);
         if ($oBanco->db90_digban == "" || $oBanco->db90_abrev == "" || $oBanco->db90_logo == "") {
             throw new Exception("Configure o banco no Cadastro de Bancos!");
         }
         pg_query("begin");
         $sCaminho = "tmp/" . $this->getCodBanco() . ".jpg";
         global $conn;
         pg_lo_export("{$oBanco->db90_logo}", $sCaminho, $conn);
         pg_query("commit");
         return $sCaminho;
     } else {
         throw new Exception("Não existe Banco cadastrado para o código {$this->getCodBanco()}!");
     }
 }
Exemplo n.º 12
0
pg_lo_close($handle);
pg_exec($db, "commit");
echo "unlink LO\n";
pg_exec($db, "begin");
pg_lo_unlink($db, $oid) or print "pg_lo_unlink() error 1\n";
pg_exec($db, "commit");
// more pg_lo_unlink() tests
echo "Test without connection\n";
pg_exec($db, "begin");
$oid = pg_lo_create($db) or print "pg_lo_create() error\n";
pg_lo_unlink($oid) or print "pg_lo_unlink() error 2\n";
pg_exec($db, "commit");
echo "Test with string oid value\n";
pg_exec($db, "begin");
$oid = pg_lo_create($db) or print "pg_lo_create() error\n";
pg_lo_unlink($db, (string) $oid) or print "pg_lo_unlink() error 3\n";
pg_exec($db, "commit");
echo "import/export LO\n";
$path = dirname(__FILE__) . '/';
pg_query($db, 'begin');
$oid = pg_lo_import($db, $path . 'php.gif');
pg_query($db, 'commit');
pg_query($db, 'begin');
@unlink($path . 'php.gif.exported');
pg_lo_export($oid, $path . 'php.gif.exported', $db);
if (!file_exists($path . 'php.gif.exported')) {
    echo "Export failed\n";
}
@unlink($path . 'php.gif.exported');
pg_query($db, 'commit');
echo "OK";
Exemplo n.º 13
0
 /**
  * Export the data stored in the large object resource to the specified file.
  * @param mixed $destination
  * @return boolean.
  */
 public function export($destination, $overwriteIfExists = false)
 {
     if (!is_string($destination)) {
         throw new \RuntimeException(sprintf('Expected $destination to be a string, got type: %s', gettype($destination)));
     }
     if (file_exists($destination) and !$overwriteIfExists) {
         throw new \RuntimeException(sprintf("File '%s' already exists.", $destination));
     }
     if (!is_writable(dirname($destination))) {
         throw new \RuntimeException(sprintf("File '%s' is not writable.", $destination));
     }
     if (isset($this->filePath)) {
         return copy($this->filePath, $destination);
     }
     $pg = $this->oid->pg;
     $pg->query(new Query('BEGIN'));
     $result = pg_lo_export($pg->resource->get(), $this->oid->oid, $destination);
     $pg->query(new Query('COMMIT'));
     return $result;
 }