/**
  * Returns string processed by sqlite_udf_encode_binary() to ensure that binary contents will be handled correctly by sqlite.
  * @param  mixed  $blob Blob or string
  * @return string encoded text
  */
 protected function getBlobSql($blob)
 {
     // they took magic __toString() out of PHP5.0.0; this sucks
     if (is_object($blob)) {
         $blob = $blob->__toString();
     }
     return "'" . sqlite_udf_encode_binary($blob) . "'";
 }
 /**
  * Applies sqlite_udf_encode_binary() to ensure that binary contents will be handled correctly by sqlite.
  * @see PreparedStatement::setBlob()
  * @see ResultSet::getBlob()
  */
 function setBlob($paramIndex, $blob)
 {
     if ($blob === null) {
         $this->setNull($paramIndex);
     } else {
         // they took magic __toString() out of PHP5.0.0; this sucks
         if (is_object($blob)) {
             $blob = $blob->__toString();
         }
         $this->boundInVars[$paramIndex] = "'" . sqlite_udf_encode_binary($blob) . "'";
     }
 }
Example #3
0
function sqlitem_udf_encode_binary($data)
{
    die('sqlitem_udf_encode_binary not implemented in PDO');
    return sqlite_udf_encode_binary($data);
}
 public function quoteBinary($data)
 {
     return "'" . sqlite_udf_encode_binary($data) . "'";
 }
Example #5
0
function sqlitem_udf_encode_binary($data)
{
    return sqlite_udf_encode_binary($data);
}
Example #6
0
 /**
  * This method return encoded binary data
  *
  * @param	string		$file	name/path of file
  * @access	public
  * @return	string
  */
 function encodeBinary($file)
 {
     if (file_exists($file) && is_readable($file)) {
         $fr = fopen($file, 'rb');
         do {
             $data = fread($fr, 1024);
             if (strlen($data) == '') {
                 break;
             }
             $content .= $data;
         } while (true);
         return sqlite_udf_encode_binary($content);
     } else {
         $this->_showError('Impossible find file');
     }
 }
 function GetBLOBFieldValue($prepared_query, $parameter, $blob, &$value)
 {
     for ($value = "'"; !MetabaseEndOfLOB($blob);) {
         if (!MetabaseReadLOB($blob, $data, $this->lob_buffer_length)) {
             $value = "";
             return $this->SetError("Get BLOB field value", MetabaseLOBError($blob));
         }
         $value .= sqlite_udf_encode_binary($data);
     }
     $value .= "'";
     return 1;
 }
Example #8
0
<?php

// string escaping
$str = "foo ' '' \\' \\ \" \\\"";
echo sqlite_escape_string($str) . "\n";
$str = "this has a " . chr(0) . " char in the middle";
echo sqlite_escape_string($str) . "\n";
// encodeing/decoding binary
$data = array("hello there", "this has a " . chr(0) . " char in the middle", chr(1) . " this has an 0x01 at the start", "this has " . chr(1) . " in the middle", "");
foreach ($data as $item) {
    echo "raw: {$item}\n";
    $coded = sqlite_udf_encode_binary($item);
    echo "coded: {$coded}\n";
    $decoded = sqlite_udf_decode_binary($coded);
    echo "decoded: {$decoded}\n";
    if ($item != $decoded) {
        echo "FAIL:\n";
        echo "[{$item}]\n";
        echo "[{$decoded}]\n";
    }
}
?>

Example #9
0
function most_similar_finalize(&$context)
{
    // encode the data so that it can be safely retrieved
    return sqlite_udf_encode_binary($context['title']);
}
Example #10
0
function dbi_update_blob($table, $column, $key, $data)
{
    global $unavail_DBI_Update_blob;
    $unavail_DBI_Update_blob = str_replace('XXX', '"dbi_update_blob"', translate('Unfortunately, XXX is not implemented for')) . ' (' . $GLOBALS['db_type'] . ').';
    assert('! empty ( $table )');
    assert('! empty ( $column )');
    assert('! empty ( $key )');
    assert('! empty ( $data )');
    $sql = 'UPDATE ' . $table . ' SET ' . $column;
    if (strcmp($GLOBALS['db_type'], 'mysql') == 0) {
        return dbi_execute($sql . ' = \'' . (function_exists('mysql_real_escape_string') ? mysql_real_escape_string($data) : addslashes($data)) . '\' WHERE ' . $key);
    } elseif (strcmp($GLOBALS['db_type'], 'sqlite') == 0) {
        return dbi_execute($sql . ' = \'' . sqlite_udf_encode_binary($data) . '\' WHERE ' . $key);
    } elseif (strcmp($GLOBALS['db_type'], 'mssql') == 0) {
        return dbi_execute($sql . ' = 0x' . bin2hex($data) . ' WHERE ' . $key);
    } elseif (strcmp($GLOBALS['db_type'], 'postgresql') == 0) {
        return dbi_execute($sql . ' = \'' . pg_escape_bytea($data) . '\' WHERE ' . $key);
    } else {
        // TODO!
        die_miserable_death($unavail_DBI_Update_blob);
    }
}