sqlite_udf_decode_binary

(PHP 5)

sqlite_udf_decode_binary -- Decodifica dati binari passati come parametri in UDF.

Descrizione

string sqlite_udf_decode_binary ( string data)

La funzione sqlite_udf_decode_binary() decodifica i dati binari in modo che possano essere utilizzati come parametri per sqlite_udf_encode_binary() o sqlite_escape_string().

Occorre eseguire questa funzione sui parametri passati agli UDF se questi devono gestire dati binari, poiché la codifica dei dati binari utilizzata dal PHP nasconde il contenuto.

Il PHP non esegue questa codifica/decodifica in automatico, avrebbe impatti negativi sulle performance.

Esempio 1. Esempio di una funzione di aggregazione lunghezza_massima binary-safe

<?php
$data
= array(
   
'one',
   
'two',
   
'three',
   
'four',
   
'five',
   
'six',
   
'seven',
   
'eight',
   
'nine',
   
'ten',
   );
$db = sqlite_open(':memory:');
sqlite_query($db, "CREATE TABLE strings(a)");
foreach (
$data as $str) {
    
$str = sqlite_escape_string($str);
    
sqlite_query($db, "INSERT INTO strings VALUES ('$str')");
}

function
max_len_step(&$context, $string)
{
    
$string = sqlite_udf_decode_binary($string);
    if (
strlen($string) > $context) {
        
$context = strlen($string);
    }
}

function
max_len_finalize(&$context)
{
    return
$context;
}

sqlite_create_aggregate($db, 'max_len', 'max_len_step', 'max_len_finalize');

var_dump(sqlite_array_query($db, 'SELECT max_len(a) from strings'));

?>

Vedere anche sqlite_udf_encode_binary(), sqlite_create_function() e sqlite_create_aggregate().