note 122883 deleted from function.sqlite-udf-decode-binary by cmb
| From: | cmb@php.net | Date: | Mon, 02 Nov 2020 15:03:32 +0000 |
| Subject: | note 122883 deleted from function.sqlite-udf-decode-binary by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215761@lists.php.net to get a copy of this message | ||
Note Submitter: BenWa
----
I had to migrate an existing SQLITE2 db with UDF encoded fields. SQLITE3 does not support
sqlite_udf_decode_binary. So I wrote a replacement for the migration.
function sqlite_udf_decode_binary($in){
if ( substr($in,0,1)==chr(1) ) {
$n=strlen($in);
$e=ord(substr($in,1,1));
$i=2 ;
while($i<$n){
$x = ord(substr($in,$i,1)) ;
if ($x==1) {
$i++;
$x = ord(substr($in,$i,1)) - 1 ;
}
$out .= chr($x+$e) ;
$i++;
}
} else {
$out = $in ;
}
return $out ;
}