[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-cvs
Subject:    [DOC-CVS] =?utf-8?q?svn:_/phpdoc/en/trunk/reference/_pdo=5Fsqlite/PDO/sqliteCreateAggregate.xml_pdo=
From:       Christoph_Michael_Becker <cmb () php ! net>
Date:       2018-09-22 10:40:40
Message-ID: svn-cmb-1537612840-345679-225487382 () svn ! php ! net
[Download RAW message or body]

cmb                                      Sat, 22 Sep 2018 10:40:40 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=345679

Log:
Fix #61661: SQLite3::createAggregate() callbacks: insufficient docs

Bug: https://bugs.php.net/61661 (Verified) SQLite3::createAggregate() callbacks: insufficient docs
      
Changed paths:
    U   phpdoc/en/trunk/reference/pdo_sqlite/PDO/sqliteCreateAggregate.xml
    U   phpdoc/en/trunk/reference/pdo_sqlite/PDO/sqliteCreateFunction.xml
    U   phpdoc/en/trunk/reference/sqlite3/sqlite3/createaggregate.xml
    U   phpdoc/en/trunk/reference/sqlite3/sqlite3/createcollation.xml
    U   phpdoc/en/trunk/reference/sqlite3/sqlite3/createfunction.xml


["svn-diffs-345679.txt" (text/x-diff)]

Modified: phpdoc/en/trunk/reference/pdo_sqlite/PDO/sqliteCreateAggregate.xml
===================================================================
--- phpdoc/en/trunk/reference/pdo_sqlite/PDO/sqliteCreateAggregate.xml	2018-09-22 \
                10:12:36 UTC (rev 345678)
+++ phpdoc/en/trunk/reference/pdo_sqlite/PDO/sqliteCreateAggregate.xml	2018-09-22 \
10:40:40 UTC (rev 345679) @@ -57,20 +57,44 @@
         <methodparam><type>mixed</type><parameter>context</parameter></methodparam>
         <methodparam><type>int</type><parameter>rownumber</parameter></methodparam>
         <methodparam><type>mixed</type><parameter>value1</parameter></methodparam>
-        <methodparam \
                choice="opt"><type>mixed</type><parameter>value2</parameter></methodparam>
                
-        <methodparam \
choice="opt"><type>mixed</type><parameter>..</parameter></methodparam> +        \
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>  \
                </methodsynopsis>
-      </para>
-      <para>
-       <varname>context</varname> will be &null; for the first row; on
-       subsequent rows it will have the value that was previously returned
-       from the step function; you should use this to maintain the aggregate
-       state.
-      </para>
-      <para>
-       <varname>rownumber</varname> will hold the current row number.
-      </para>
-      <para>
+       <variablelist>
+        <varlistentry>
+         <term><parameter>context</parameter></term>
+         <listitem>
+          <para>
+           &null; for the first row; on subsequent rows it will have the value
+           that was previously returned from the step function; you should use
+           this to maintain the aggregate state.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>rownumber</parameter></term>
+         <listitem>
+          <para>
+           The current row number.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>value1</parameter></term>
+         <listitem>
+          <para>
+           The first argument passed to the aggregate.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>...</parameter></term>
+         <listitem>
+          <para>
+           Further arguments passed to the aggregate.
+          </para>
+         </listitem>
+        </varlistentry>
+       </variablelist>
        The return value of this function will be used as the
        <parameter>context</parameter> argument in the next call of the step or
        finalize functions.
@@ -84,7 +108,7 @@
        Callback function to aggregate the "stepped" data from each row.
        Once all the rows have been processed, this function will be called
        and it should then take the data from the aggregation context and
-       return the result. Callback functions should return a type understood
+       return the result. This callback function should return a type understood
        by SQLite (i.e. <link
        linkend="language.types.intro">scalar type</link>).
       </para>
@@ -93,18 +117,26 @@
        <methodsynopsis>
         <type>mixed</type><methodname><replaceable>fini</replaceable></methodname>
         <methodparam><type>mixed</type><parameter>context</parameter></methodparam>
-        <methodparam><type>int</type><parameter>rownumber</parameter></methodparam>
+        <methodparam><type>int</type><parameter>rowcount</parameter></methodparam>
        </methodsynopsis>
-      </para>
-      <para>
-       <varname>context</varname> will hold the return value from the very
-       last call to the step function.
-      </para>
-      <para>
-       <varname>rownumber</varname> will hold the number of rows over which
-       the aggregate was performed.
-      </para>
-      <para>
+       <variablelist>
+        <varlistentry>
+         <term><parameter>context</parameter></term>
+         <listitem>
+          <para>
+           Holds the return value from the very last call to the step function.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>rowcount</parameter></term>
+         <listitem>
+          <para>
+           Holds the number of rows over which the aggregate was performed.
+          </para>
+         </listitem>
+        </varlistentry>
+       </variablelist>
        The return value of this function will be used as the return value for
        the aggregate.
       </para>
@@ -158,7 +190,7 @@
 }
 $insert = null;

-function max_len_step(&$context, $rownumber, $string)
+function max_len_step($context, $rownumber, $string)
 {
     if (strlen($string) > $context) {
         $context = strlen($string);
@@ -166,7 +198,7 @@
     return $context;
 }

-function max_len_finalize(&$context, $rownumber)
+function max_len_finalize($context, $rowcount)
 {
     return $context === null ? 0 : $context;
 }
@@ -184,11 +216,11 @@
    In this example, we are creating an aggregating function that will
    calculate the length of the longest string in one of the columns of the
    table.  For each row, the <literal>max_len_step</literal> function is
-   called and passed a <parameter>context</parameter> parameter.  The context
+   called and passed a <literal>context</literal> parameter.  The context
    parameter is just like any other PHP variable and be set to hold an array
    or even an object value.  In this example, we are simply using it to hold
    the maximum length we have seen so far; if the
-   <parameter>string</parameter> has a length longer than the current
+   <literal>string</literal> has a length longer than the current
    maximum, we update the context to hold this new maximum length.
   </para>
   <para>
@@ -195,7 +227,7 @@
    After all of the rows have been processed, SQLite calls the
    <literal>max_len_finalize</literal> function to determine the aggregate
    result.  Here, we could perform some kind of calculation based on the
-   data found in the <parameter>context</parameter>.  In our simple example
+   data found in the <literal>context</literal>.  In our simple example
    though, we have been calculating the result as the query progressed, so we
    simply need to return the context value.
   </para>

Modified: phpdoc/en/trunk/reference/pdo_sqlite/PDO/sqliteCreateFunction.xml
===================================================================
--- phpdoc/en/trunk/reference/pdo_sqlite/PDO/sqliteCreateFunction.xml	2018-09-22 \
                10:12:36 UTC (rev 345678)
+++ phpdoc/en/trunk/reference/pdo_sqlite/PDO/sqliteCreateFunction.xml	2018-09-22 \
10:40:40 UTC (rev 345679) @@ -54,6 +54,32 @@
         <link linkend="language.types.intro">scalar type</link>).
        </simpara>
       </note>
+      <para>
+       This function need to be defined as:
+       <methodsynopsis>
+        <type>mixed</type><methodname><replaceable>callback</replaceable></methodname>
 +        <methodparam><type>mixed</type><parameter>value1</parameter></methodparam>
+        <methodparam \
choice="opt"><type>mixed</type><parameter>...</parameter></methodparam> +       \
</methodsynopsis> +       <variablelist>
+        <varlistentry>
+         <term><parameter>value1</parameter></term>
+         <listitem>
+          <para>
+           The first argument passed to the SQL function.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>...</parameter></term>
+         <listitem>
+          <para>
+           Further arguments passed to the SQL function.
+          </para>
+         </listitem>
+        </varlistentry>
+       </variablelist>
+      </para>
      </listitem>
     </varlistentry>
     <varlistentry>
@@ -135,7 +161,7 @@
    In this example, we have a function that calculates the md5 sum of a
    string, and then reverses it.  When the SQL statement executes, it
    returns the value of the filename transformed by our function.  The data
-   returned in <parameter>$rows</parameter> contains the processed result.
+   returned in <literal>$rows</literal> contains the processed result.
   </para>
   <para>
    The beauty of this technique is that you do not need to process the

Modified: phpdoc/en/trunk/reference/sqlite3/sqlite3/createaggregate.xml
===================================================================
--- phpdoc/en/trunk/reference/sqlite3/sqlite3/createaggregate.xml	2018-09-22 10:12:36 \
                UTC (rev 345678)
+++ phpdoc/en/trunk/reference/sqlite3/sqlite3/createaggregate.xml	2018-09-22 10:40:40 \
UTC (rev 345679) @@ -38,9 +38,59 @@
      <term><parameter>step_callback</parameter></term>
      <listitem>
       <para>
-       The name of a PHP function or user-defined function to apply as a
-       callback for every item in the aggregate.
+       Callback function called for each row of the result set. Your PHP
+       function should accumulate the result and store it in the aggregation
+       context.
       </para>
+      <para>
+       This function need to be defined as:
+       <methodsynopsis>
+        <type>mixed</type><methodname><replaceable>step</replaceable></methodname>
+        <methodparam><type>mixed</type><parameter>context</parameter></methodparam>
+        <methodparam><type>int</type><parameter>rownumber</parameter></methodparam>
+        <methodparam><type>mixed</type><parameter>value1</parameter></methodparam>
+        <methodparam \
choice="opt"><type>mixed</type><parameter>...</parameter></methodparam> +       \
</methodsynopsis> +       <variablelist>
+        <varlistentry>
+         <term><parameter>context</parameter></term>
+         <listitem>
+          <para>
+           &null; for the first row; on subsequent rows it will have the value
+           that was previously returned from the step function; you should use
+           this to maintain the aggregate state.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>rownumber</parameter></term>
+         <listitem>
+          <para>
+           The current row number.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>value1</parameter></term>
+         <listitem>
+          <para>
+           The first argument passed to the aggregate.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>...</parameter></term>
+         <listitem>
+          <para>
+           Further arguments passed to the aggregate.
+          </para>
+         </listitem>
+        </varlistentry>
+       </variablelist>
+       The return value of this function will be used as the
+       <parameter>context</parameter> argument in the next call of the step or
+       finalize functions.
+      </para>
      </listitem>
     </varlistentry>
     <varlistentry>
@@ -47,9 +97,41 @@
      <term><parameter>final_callback</parameter></term>
      <listitem>
       <para>
-       The name of a PHP function or user-defined function to apply as a
-       callback at the end of the aggregate data.
+       Callback function to aggregate the "stepped" data from each row.
+       Once all the rows have been processed, this function will be called
+       and it should then take the data from the aggregation context and
+       return the result. This callback function should return a type understood
+       by SQLite (i.e. <link
+       linkend="language.types.intro">scalar type</link>).
       </para>
+      <para>
+       This function need to be defined as:
+       <methodsynopsis>
+        <type>mixed</type><methodname><replaceable>fini</replaceable></methodname>
+        <methodparam><type>mixed</type><parameter>context</parameter></methodparam>
+        <methodparam><type>int</type><parameter>rownumber</parameter></methodparam>
+       </methodsynopsis>
+       <variablelist>
+        <varlistentry>
+         <term><parameter>context</parameter></term>
+         <listitem>
+          <para>
+           Holds the return value from the very last call to the step function.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>rownumber</parameter></term>
+         <listitem>
+          <para>
+           Always <literal>0</literal>.
+          </para>
+         </listitem>
+        </varlistentry>
+       </variablelist>
+       The return value of this function will be used as the return value for
+       the aggregate.
+      </para>
      </listitem>
     </varlistentry>
     <varlistentry>
@@ -64,7 +146,6 @@
     </varlistentry>
    </variablelist>
   </para>
-
  </refsect1>

  <refsect1 role="returnvalues">
@@ -75,6 +156,98 @@
   </para>
  </refsect1>

+ <refsect1 role="examples">
+  &reftitle.examples;
+  <para>
+   <example>
+    <title>max_length aggregation function example</title>
+    <programlisting role="php">
+<![CDATA[
+<?php
+$data = array(
+   'one',
+   'two',
+   'three',
+   'four',
+   'five',
+   'six',
+   'seven',
+   'eight',
+   'nine',
+   'ten',
+   );
+$db = new SQLite3(':memory:');
+$db->exec("CREATE TABLE strings(a)");
+$insert = $db->prepare('INSERT INTO strings VALUES (?)');
+foreach ($data as $str) {
+    $insert->bindValue(1, $str);
+    $insert->execute();
+}
+$insert = null;
+
+function max_len_step($context, $rownumber, $string)
+{
+    if (strlen($string) > $context) {
+        $context = strlen($string);
+    }
+    return $context;
+}
+
+function max_len_finalize($context, $rownumber)
+{
+    return $context === null ? 0 : $context;
+}
+
+$db->createAggregate('max_len', 'max_len_step', 'max_len_finalize');
+
+var_dump($db->querySingle('SELECT max_len(a) from strings'));
+?>
+]]>
+    </programlisting>
+    &example.outputs;
+    <screen role="php">
+<![CDATA[
+int(5)
+]]>
+    </screen>
+   </example>
+  </para>
+  <para>
+   In this example, we are creating an aggregating function that will
+   calculate the length of the longest string in one of the columns of the
+   table.  For each row, the <literal>max_len_step</literal> function is
+   called and passed a <literal>context</literal> parameter.  The context
+   parameter is just like any other PHP variable and be set to hold an array
+   or even an object value.  In this example, we are simply using it to hold
+   the maximum length we have seen so far; if the
+   <literal>string</literal> has a length longer than the current
+   maximum, we update the context to hold this new maximum length.
+  </para>
+  <para>
+   After all of the rows have been processed, SQLite calls the
+   <literal>max_len_finalize</literal> function to determine the aggregate
+   result.  Here, we could perform some kind of calculation based on the
+   data found in the <literal>context</literal>.  In our simple example
+   though, we have been calculating the result as the query progressed, so we
+   simply need to return the context value.
+  </para>
+  <tip>
+   <para>
+    It is NOT recommended for you to store a copy of the values in the context
+    and then process them at the end, as you would cause SQLite to use a lot of
+    memory to process the query - just think of how much memory you would need
+    if a million rows were stored in memory, each containing a string 32 bytes
+    in length.
+   </para>
+  </tip>
+  <tip>
+   <para>
+    You can use <methodname>SQLite3::createAggregate</methodname> to override SQLite
+    native SQL functions.
+   </para>
+  </tip>
+ </refsect1>
+
 </refentry>

 <!-- Keep this comment at the end of the file

Modified: phpdoc/en/trunk/reference/sqlite3/sqlite3/createcollation.xml
===================================================================
--- phpdoc/en/trunk/reference/sqlite3/sqlite3/createcollation.xml	2018-09-22 10:12:36 \
                UTC (rev 345678)
+++ phpdoc/en/trunk/reference/sqlite3/sqlite3/createcollation.xml	2018-09-22 10:40:40 \
UTC (rev 345679) @@ -37,10 +37,18 @@
      <para>
       The name of a PHP function or user-defined function to apply as a
       callback, defining the behavior of the collation.  It should accept two
-      strings and return as <function>strcmp</function> does, i.e. it should
+      values and return as <function>strcmp</function> does, i.e. it should
       return -1, 1, or 0 if the first string sorts before, sorts after, or is
       equal to the second.
      </para>
+      <para>
+       This function need to be defined as:
+       <methodsynopsis>
+        <type>int</type><methodname><replaceable>collation</replaceable></methodname>
 +        <methodparam><type>mixed</type><parameter>value1</parameter></methodparam>
+        <methodparam><type>mixed</type><parameter>value2</parameter></methodparam>
+       </methodsynopsis>
+      </para>
     </listitem>
    </varlistentry>
   </variablelist>

Modified: phpdoc/en/trunk/reference/sqlite3/sqlite3/createfunction.xml
===================================================================
--- phpdoc/en/trunk/reference/sqlite3/sqlite3/createfunction.xml	2018-09-22 10:12:36 \
                UTC (rev 345678)
+++ phpdoc/en/trunk/reference/sqlite3/sqlite3/createfunction.xml	2018-09-22 10:40:40 \
UTC (rev 345679) @@ -41,6 +41,32 @@
        The name of a PHP function or user-defined function to apply as a
        callback, defining the behavior of the SQL function.
       </para>
+      <para>
+       This function need to be defined as:
+       <methodsynopsis>
+        <type>mixed</type><methodname><replaceable>callback</replaceable></methodname>
 +        <methodparam><type>mixed</type><parameter>value1</parameter></methodparam>
+        <methodparam \
choice="opt"><type>mixed</type><parameter>...</parameter></methodparam> +       \
</methodsynopsis> +       <variablelist>
+        <varlistentry>
+         <term><parameter>value1</parameter></term>
+         <listitem>
+          <para>
+           The first argument passed to the SQL function.
+          </para>
+         </listitem>
+        </varlistentry>
+        <varlistentry>
+         <term><parameter>...</parameter></term>
+         <listitem>
+          <para>
+           Further arguments passed to the SQL function.
+          </para>
+         </listitem>
+        </varlistentry>
+       </variablelist>
+      </para>
      </listitem>
     </varlistentry>
     <varlistentry>



-- 
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic