Exemple #1
0
 /**
  * Initializes and opens the database
  *
  * Needs to be called right after loading this helper plugin
  */
 function init($dbname, $updatedir)
 {
     global $conf;
     // check for already open DB
     if ($this->db) {
         if ($this->dbname == $dbname) {
             // db already open
             return true;
         }
         // close other db
         sqlite_close($this->db);
         $this->db = null;
         $this->dbname = '';
     }
     $this->dbname = $dbname;
     $dbfile = $conf['metadir'] . '/' . $dbname . '.sqlite';
     $init = !@file_exists($dbfile) || (int) @filesize($dbfile) < 3;
     $error = '';
     $this->db = sqlite_open($dbfile, 0666, $error);
     if (!$this->db) {
         msg("SQLite: failed to open SQLite " . $this->dbname . " database ({$error})", -1);
         return false;
     }
     // register our custom aggregate function
     sqlite_create_aggregate($this->db, 'group_concat', array($this, '_sqlite_group_concat_step'), array($this, '_sqlite_group_concat_finalize'), 2);
     $this->_updatedb($init, $updatedir);
     return true;
 }
Exemple #2
0
 protected function process()
 {
     array_map(array($this, 'usedWithThisMethod'), $b);
     array_filter($array, array('A', 'usedStaticallyInArrayMethod'));
     preg_replace_callback('regex', $variable, 'A::usedStaticallyInStringMethod');
     sqlite_create_aggregate('handler0', 'handler1', 'handler2', array('A::undefinedMethod'));
 }
Exemple #3
0
 public function createAggregate($queryFuction, $stepFunction, $finalizeFunction, $args)
 {
     if (!$args) {
         sqlite_create_aggregate($this->handle, $queryFuction, $stepFunction, $finalizeFunction);
     } else {
         sqlite_create_aggregate($this->handle, $queryFuction, $stepFunction, $finalizeFunction, $args);
     }
     return true;
 }
 /**
  * open db
  */
 public function opendb($init, $sqliteupgrade = false)
 {
     if ($this->isSqlite3db($this->dbfile)) {
         msg("SQLite: failed to open SQLite '" . $this->dbname . "' database (DB has a sqlite3 format instead of sqlite2 format.)", -1);
         return false;
     }
     $error = '';
     $this->db = sqlite_open($this->dbfile, 0666, $error);
     if (!$this->db) {
         msg("SQLite: failed to open SQLite '" . $this->dbname . "' database ({$error})", -1);
         return false;
     }
     // register our custom aggregate function
     sqlite_create_aggregate($this->db, 'group_concat', array($this, '_sqlite_group_concat_step'), array($this, '_sqlite_group_concat_finalize'), 2);
     return true;
 }
 /**
  * Registers an aggregating user defined function for use in SQL statements.
  * @param  string  function name
  * @param  mixed   callback called for each row of the result set
  * @param  mixed   callback called to aggregate the "stepped" data from each row
  * @param  int     num of arguments
  * @return void
  */
 public function registerAggregateFunction($name, $rowCallback, $agrCallback, $numArgs = -1)
 {
     sqlite_create_aggregate($this->connection, $name, $rowCallback, $agrCallback, $numArgs);
 }
Exemple #6
0
 /**
  * Initializes and opens the database
  *
  * Needs to be called right after loading this helper plugin
  */
 function init($dbname, $updatedir)
 {
     global $conf;
     // check for already open DB
     if ($this->db) {
         if ($this->dbname == $dbname) {
             // db already open
             return true;
         }
         // close other db
         if ($this->extension == DOKU_EXT_SQLITE) {
             sqlite_close($this->db);
         } else {
             $this->db->close();
         }
         $this->db = null;
         $this->dbname = '';
     }
     $this->dbname = $dbname;
     // Separate the database files to prevent not-requested autoupgrades.
     if ($this->extension == DOKU_EXT_SQLITE) {
         $fileextension = '.sqlite';
     } else {
         $fileextension = '.sqlite3';
     }
     $this->dbfile = $conf['metadir'] . '/' . $dbname . $fileextension;
     $init = !@file_exists($this->dbfile) || (int) @filesize($this->dbfile) < 3;
     //first line tell the format of db file http://marc.info/?l=sqlite-users&m=109383875408202
     $firstline = @file_get_contents($this->dbfile, false, null, 0, 15);
     if ($this->extension == DOKU_EXT_SQLITE) {
         if ($firstline == 'SQLite format 3') {
             msg("SQLite: failed to open SQLite '" . $this->dbname . "' database (DB has a sqlite3 format instead of sqlite2 format.)", -1);
             return false;
         }
         $error = '';
         $this->db = sqlite_open($this->dbfile, 0666, $error);
         if (!$this->db) {
             msg("SQLite: failed to open SQLite '" . $this->dbname . "' database ({$error})", -1);
             return false;
         }
         // register our custom aggregate function
         sqlite_create_aggregate($this->db, 'group_concat', array($this, '_sqlite_group_concat_step'), array($this, '_sqlite_group_concat_finalize'), 2);
     } else {
         if ($init) {
             $oldDbfile = substr($this->dbfile, 0, -1);
             if (@file_exists($oldDbfile)) {
                 $notfound_msg = "SQLite: '" . $this->dbname . $fileextension . "' database not found. In the meta directory is '" . $this->dbname . substr($fileextension, 0, -1) . "' available. ";
                 $firstline = @file_get_contents($oldDbfile, false, null, 0, 15);
                 if ($firstline == 'SQLite format 3') {
                     msg($notfound_msg . "PDO sqlite needs you rename manual the file extension to '.sqlite3' .", -1);
                     return false;
                 } else {
                     msg($notfound_msg . "PDO sqlite needs you upgrade manual this sqlite2 db to sqlite3 format.", -1);
                     return false;
                 }
             }
         } else {
             if ($firstline != 'SQLite format 3') {
                 msg("SQLite: failed to open SQLite '" . $this->dbname . "' database (DB has not a sqlite3 format.)", -1);
                 return false;
             }
         }
         $dsn = 'sqlite:' . $this->dbfile;
         try {
             $this->db = new PDO($dsn);
         } catch (PDOException $e) {
             msg("SQLite: failed to open SQLite '" . $this->dbname . "' database (" . $e->getMessage() . ")", -1);
             return false;
         }
         $this->db->sqliteCreateAggregate('group_concat', array($this, '_pdo_group_concat_step'), array($this, '_pdo_group_concat_finalize'));
     }
     $this->_updatedb($init, $updatedir);
     return true;
 }
Exemple #7
0
function sqlitem_create_aggregate($dhb, $function_name, $step_func, $finalize_func, $num_args = null)
{
    return sqlite_create_aggregate($dhb, $function_name, $step_func, $finalize_func, $num_args);
}
 function create_aggregate($function_name, $step_func, $finalize_func, $num_args = null)
 {
     if (DEBUG) {
         return sqlite_create_aggregate($this->connId, $function_name, $step_func, $finalize_func, $num_args);
     } else {
         return @sqlite_create_aggregate($this->connId, $function_name, $step_func, $finalize_func, $num_args);
     }
 }
Exemple #9
0
<?php

require 's_common.inc';
$db = makedb();
sqlite_create_function($db, 'md5rev', 'md5_and_reverse', 1);
sqlite_create_aggregate($db, 'max_len', 'max_len_step', 'max_len_finalize');
// generic php callback
$rows = sqlite_array_query($db, "SELECT php('md5', my_string) from mytable");
var_dump($rows);
$rows = sqlite_array_query($db, "SELECT php('max', my_float, 2) from mytable");
var_dump($rows);
// callback error
$rows = sqlite_array_query($db, "SELECT php('unknown', my_string) from mytable");
var_dump($rows);
/// PHP UDF
function md5_and_reverse($string)
{
    echo "in callback, original string is {$string}\n";
    return strrev(md5($string));
}
$sql = 'SELECT md5rev(my_string) FROM mytable';
$rows = sqlite_array_query($db, $sql);
var_dump($rows);
/// aggregate
$data = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten');
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)
Exemple #10
0
<?php

// #0
assert(array('a', 'b'));
// #1
uasort($array, array($c, 'd'));
// #2
preg_replace_callback($s, $ss, array($e, 'f'));
// #3
sqlite_create_aggregate($a1, $a2, $a3, array($g, '$h'));
// #4
session_set_save_handler($sssh0, $sssh1, $sssh2, $sssh3, array($sssh4, 'sssh4'));
// #5
session_set_save_handler($sssh0, $sssh1, $sssh2, $sssh3, $sssh4, array($sssh5, 'sssh5'));
// #6
session_set_save_handler($sssh0, $sssh1, $sssh2, $sssh3, $sssh4, $sssh5, array($sssh6, 'sssh6'));
// #7
session_set_save_handler($sssh0, $sssh1, $sssh2, $sssh3, $sssh4, $sssh5, $sssh6, array($sssh7, 'sssh7'));
// 2nd to last arg
array_udiff_uassoc($a1, $a2, $a3, array($i, 'j'), $last);
// last arg
array_udiff($a1, $a2, $a3, array($k, 'l'));
Exemple #11
0
<?php

function most_similar(&$context, $string, $source_str)
{
    /* Calculate the similarity between two strings */
    $sim = similar_text($string, $source_str);
    if (empty($context) || $sim > $context['sim']) {
        $context = array('sim' => $sim, 'title' => $string);
    }
}
function most_similar_finalize(&$context)
{
    return $context['title'];
}
$db = sqlite_open(dirname(__FILE__) . "/db2.sqlite");
/* bool sqlite_create_aggregate (resource dbhandle, string function_name, mixed step_func, mixed finalize_func [, int num_args]) */
sqlite_create_aggregate($db, 'similar_text', 'most_similar', 'most_similar_finalize', 2);
$title = 'mesg #2';
echo "Most Similar title to '{$title}' according to similar_text() is: ";
echo sqlite_single_query("SELECT similar_text(title, '{$title}') FROM messages", $db);
echo "<br />\n";
Exemple #12
0
<?php

// #0
assert(['a', 'b']);
// #1
uasort($array, [$c, 'd']);
// #2
preg_replace_callback($s, $ss, [$e, 'f']);
// #3
sqlite_create_aggregate($a1, $a2, $a3, [$g, '$h']);
// #4
session_set_save_handler($sssh0, $sssh1, $sssh2, $sssh3, [$sssh4, 'sssh4']);
// #5
session_set_save_handler($sssh0, $sssh1, $sssh2, $sssh3, $sssh4, [$sssh5, 'sssh5']);
// #6
session_set_save_handler($sssh0, $sssh1, $sssh2, $sssh3, $sssh4, $sssh5, [$sssh6, 'sssh6']);
// #7
session_set_save_handler($sssh0, $sssh1, $sssh2, $sssh3, $sssh4, $sssh5, $sssh6, [$sssh7, 'sssh7']);
// 2nd to last arg
array_udiff_uassoc($a1, $a2, $a3, [$i, 'j'], $last);
// last arg
array_udiff($a1, $a2, $a3, [$k, 'l']);
Exemple #13
0
<?php

array_map('callableString', $array);
call_user_func($array, 'nonCallableString');
//array_map($array, $nonCallableVar);
array_filter($array, array('string', 'string'));
array_reduce(array('string', 'string'), $array);
preg_replace_callback('a', 'b', 'MyClass::myCallbackMethod');
sqlite_create_function('MyClass::myNonCallbackMethod', $b, $c);
sqlite_create_aggregate($a, 'MyClass2::myNonCallbackMethod', $c);
Exemple #14
0
 /**
  * 集約UDFを登録する(sqlite_create_aggregate()ラッパー)。
  */
 function create_aggregate($function_name, $step_func, $finalize_func, $num_args = null)
 {
     if ($num_args === null) {
         return sqlite_create_aggregate($this->link, $function_name, $step_func, $finalize_func);
     } else {
         return sqlite_create_aggregate($this->link, $function_name, $step_func, $finalize_func, $num_args);
     }
 }