Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : SQLite Functions (PDO_SQLITE) : PDO->sqliteCreateAggregate()

PDO->sqliteCreateAggregate()

Registers an aggregating User Defined Function for use in SQL statements ()

Example 2341. max_length aggregation function example

<?php
$data
= array(
 
'one',
 
'two',
 
'three',
 
'four',
 
'five',
 
'six',
 
'seven',
 
'eight',
 
'nine',
 
'ten',
  );
$db = new PDO('sqlite::memory:');
$db->exec("CREATE TABLE strings(a)");
$insert = $db->prepare('INSERT INTO strings VALUES (?)');
foreach (
$data as $str) {
   
$insert->execute(array($str));
}
$insert = null;

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

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

$db->sqliteCreateAggregate('max_len', 'max_len_step', 'max_len_finalize');

var_dump($db->query('SELECT max_len(a) from strings')->fetchAll());

?>

Change Language


Follow Navioo On Twitter
PDO_SQLITE DSN
PDO->sqliteCreateAggregate()
PDO->sqliteCreateFunction()
eXTReMe Tracker