Author: paul
Date: 2007-07-17 21:45:30 +0200 (Tue, 17 Jul 2007)
New Revision: 7129
Log:
r27693@polar: paul | 2007-07-17 13:15:43 -0500
C API: Describe how to get result set data lengths prior to calling
mysql_stmt_fetch(). (Info from Konstantin)
Modified:
trunk/refman-4.1/apis-c.xml
trunk/refman-5.0/apis-c.xml
trunk/refman-5.1/apis-c.xml
trunk/refman-5.2/apis-c.xml
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 4767c598-dc10-0410-bea0-d01b485662eb:/mysqldoc-local/mysqldoc/trunk:27692
7d8d2c4e-af1d-0410-ab9f-b038ce55645b:/mysqldoc-local/mysqldoc:22722
b5ec3a16-e900-0410-9ad2-d183a3acac99:/mysqldoc-local/mysqldoc/trunk:14218
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/mysqldoc/trunk:18941
+ 4767c598-dc10-0410-bea0-d01b485662eb:/mysqldoc-local/mysqldoc/trunk:27693
7d8d2c4e-af1d-0410-ab9f-b038ce55645b:/mysqldoc-local/mysqldoc:22722
b5ec3a16-e900-0410-9ad2-d183a3acac99:/mysqldoc-local/mysqldoc/trunk:14218
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/mysqldoc/trunk:18941
Modified: trunk/refman-4.1/apis-c.xml
===================================================================
--- trunk/refman-4.1/apis-c.xml 2007-07-17 19:25:21 UTC (rev 7128)
+++ trunk/refman-4.1/apis-c.xml 2007-07-17 19:45:30 UTC (rev 7129)
Changed blocks: 2, Lines Added: 65, Lines Deleted: 0; 2799 bytes
@@ -8300,6 +8300,13 @@
temporal data types because the length of the data value
is determined by the <literal>buffer_type</literal> value.
</para>
+
+ <para>
+ If you need to be able to determine the length of a
+ returned value before fetching it with
+ <literal>mysql_stmt_fetch()</literal>, see
+ <xref linkend="mysql-stmt-fetch"/>, for some strategies.
+ </para>
</listitem>
<listitem>
@@ -10855,6 +10862,64 @@
}
</programlisting>
+ <para>
+ In some cases you might want to determine the length of a column
+ value before fetching it with
+ <literal>mysql_stmt_fetch()</literal>. For example, the value
+ might be a long string or <literal>BLOB</literal> value for
+ which you want to know how much space must be allocated. To
+ accomplish this, you can use these strategies:
+ </para>
+
+ <itemizedlist>
+
+ <listitem>
+ <para>
+ Before invoking <literal>mysql_stmt_fetch()</literal> to
+ retrieve individual rows, invoke
+ <literal>mysql_stmt_store_result()</literal> to buffer the
+ entire result on the client side. Then the maximal length of
+ column values will be indicated by the
+ <literal>max_length</literal> member of the result set
+ metadata returned by
+ <literal>mysql_stmt_result_metadata()</literal>. This
+ strategy requires that you pass
+ <literal>STMT_ATTR_UPDATE_MAX_LENGTH</literal> to
+ <literal>mysql_stmt_attr_set()</literal> or the
+ <literal>max_length</literal> values will not be calculated.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Invoke <literal>mysql_stmt_fetch()</literal> with a
+ zero-length buffer for the column in question and a pointer
+ in which the real length can be stored. Then use the real
+ length with <literal>mysql_stmt_fetch_column()</literal>.
+ </para>
+
+<programlisting>
+real_length= 0;
+
+bind[0].buffer= 0;
+bind[0].buffer_length= 0;
+bind[0].length= &real_length
+mysql_stmt_bind_result(stmt, bind);
+
+mysql_stmt_fetch(stmt);
+if (real_length > 0)
+{
+ data= malloc(real_length);
+ bind[0].buffer= data;
+ bind[0].buffer_length= real_length;
+ mysql_stmt_fetch_column(stmt, 0, bind, 0);
+}
+</programlisting>
+
+ </listitem>
+
+ </itemizedlist>
+
</section>
<section id="mysql-stmt-fetch-column">
Modified: trunk/refman-5.0/apis-c.xml
===================================================================
--- trunk/refman-5.0/apis-c.xml 2007-07-17 19:25:21 UTC (rev 7128)
+++ trunk/refman-5.0/apis-c.xml 2007-07-17 19:45:30 UTC (rev 7129)
Changed blocks: 2, Lines Added: 65, Lines Deleted: 0; 2799 bytes
@@ -8412,6 +8412,13 @@
temporal data types because the length of the data value
is determined by the <literal>buffer_type</literal> value.
</para>
+
+ <para>
+ If you need to be able to determine the length of a
+ returned value before fetching it with
+ <literal>mysql_stmt_fetch()</literal>, see
+ <xref linkend="mysql-stmt-fetch"/>, for some strategies.
+ </para>
</listitem>
<listitem>
@@ -11042,6 +11049,64 @@
}
</programlisting>
+ <para>
+ In some cases you might want to determine the length of a column
+ value before fetching it with
+ <literal>mysql_stmt_fetch()</literal>. For example, the value
+ might be a long string or <literal>BLOB</literal> value for
+ which you want to know how much space must be allocated. To
+ accomplish this, you can use these strategies:
+ </para>
+
+ <itemizedlist>
+
+ <listitem>
+ <para>
+ Before invoking <literal>mysql_stmt_fetch()</literal> to
+ retrieve individual rows, invoke
+ <literal>mysql_stmt_store_result()</literal> to buffer the
+ entire result on the client side. Then the maximal length of
+ column values will be indicated by the
+ <literal>max_length</literal> member of the result set
+ metadata returned by
+ <literal>mysql_stmt_result_metadata()</literal>. This
+ strategy requires that you pass
+ <literal>STMT_ATTR_UPDATE_MAX_LENGTH</literal> to
+ <literal>mysql_stmt_attr_set()</literal> or the
+ <literal>max_length</literal> values will not be calculated.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Invoke <literal>mysql_stmt_fetch()</literal> with a
+ zero-length buffer for the column in question and a pointer
+ in which the real length can be stored. Then use the real
+ length with <literal>mysql_stmt_fetch_column()</literal>.
+ </para>
+
+<programlisting>
+real_length= 0;
+
+bind[0].buffer= 0;
+bind[0].buffer_length= 0;
+bind[0].length= &real_length
+mysql_stmt_bind_result(stmt, bind);
+
+mysql_stmt_fetch(stmt);
+if (real_length > 0)
+{
+ data= malloc(real_length);
+ bind[0].buffer= data;
+ bind[0].buffer_length= real_length;
+ mysql_stmt_fetch_column(stmt, 0, bind, 0);
+}
+</programlisting>
+
+ </listitem>
+
+ </itemizedlist>
+
</section>
<section id="mysql-stmt-fetch-column">
Modified: trunk/refman-5.1/apis-c.xml
===================================================================
--- trunk/refman-5.1/apis-c.xml 2007-07-17 19:25:21 UTC (rev 7128)
+++ trunk/refman-5.1/apis-c.xml 2007-07-17 19:45:30 UTC (rev 7129)
Changed blocks: 2, Lines Added: 65, Lines Deleted: 0; 2799 bytes
@@ -8525,6 +8525,13 @@
temporal data types because the length of the data value
is determined by the <literal>buffer_type</literal> value.
</para>
+
+ <para>
+ If you need to be able to determine the length of a
+ returned value before fetching it with
+ <literal>mysql_stmt_fetch()</literal>, see
+ <xref linkend="mysql-stmt-fetch"/>, for some strategies.
+ </para>
</listitem>
<listitem>
@@ -11087,6 +11094,64 @@
}
</programlisting>
+ <para>
+ In some cases you might want to determine the length of a column
+ value before fetching it with
+ <literal>mysql_stmt_fetch()</literal>. For example, the value
+ might be a long string or <literal>BLOB</literal> value for
+ which you want to know how much space must be allocated. To
+ accomplish this, you can use these strategies:
+ </para>
+
+ <itemizedlist>
+
+ <listitem>
+ <para>
+ Before invoking <literal>mysql_stmt_fetch()</literal> to
+ retrieve individual rows, invoke
+ <literal>mysql_stmt_store_result()</literal> to buffer the
+ entire result on the client side. Then the maximal length of
+ column values will be indicated by the
+ <literal>max_length</literal> member of the result set
+ metadata returned by
+ <literal>mysql_stmt_result_metadata()</literal>. This
+ strategy requires that you pass
+ <literal>STMT_ATTR_UPDATE_MAX_LENGTH</literal> to
+ <literal>mysql_stmt_attr_set()</literal> or the
+ <literal>max_length</literal> values will not be calculated.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Invoke <literal>mysql_stmt_fetch()</literal> with a
+ zero-length buffer for the column in question and a pointer
+ in which the real length can be stored. Then use the real
+ length with <literal>mysql_stmt_fetch_column()</literal>.
+ </para>
+
+<programlisting>
+real_length= 0;
+
+bind[0].buffer= 0;
+bind[0].buffer_length= 0;
+bind[0].length= &real_length
+mysql_stmt_bind_result(stmt, bind);
+
+mysql_stmt_fetch(stmt);
+if (real_length > 0)
+{
+ data= malloc(real_length);
+ bind[0].buffer= data;
+ bind[0].buffer_length= real_length;
+ mysql_stmt_fetch_column(stmt, 0, bind, 0);
+}
+</programlisting>
+
+ </listitem>
+
+ </itemizedlist>
+
</section>
<section id="mysql-stmt-fetch-column">
Modified: trunk/refman-5.2/apis-c.xml
===================================================================
--- trunk/refman-5.2/apis-c.xml 2007-07-17 19:25:21 UTC (rev 7128)
+++ trunk/refman-5.2/apis-c.xml 2007-07-17 19:45:30 UTC (rev 7129)
Changed blocks: 2, Lines Added: 65, Lines Deleted: 0; 2799 bytes
@@ -8512,6 +8512,13 @@
temporal data types because the length of the data value
is determined by the <literal>buffer_type</literal> value.
</para>
+
+ <para>
+ If you need to be able to determine the length of a
+ returned value before fetching it with
+ <literal>mysql_stmt_fetch()</literal>, see
+ <xref linkend="mysql-stmt-fetch"/>, for some strategies.
+ </para>
</listitem>
<listitem>
@@ -11074,6 +11081,64 @@
}
</programlisting>
+ <para>
+ In some cases you might want to determine the length of a column
+ value before fetching it with
+ <literal>mysql_stmt_fetch()</literal>. For example, the value
+ might be a long string or <literal>BLOB</literal> value for
+ which you want to know how much space must be allocated. To
+ accomplish this, you can use these strategies:
+ </para>
+
+ <itemizedlist>
+
+ <listitem>
+ <para>
+ Before invoking <literal>mysql_stmt_fetch()</literal> to
+ retrieve individual rows, invoke
+ <literal>mysql_stmt_store_result()</literal> to buffer the
+ entire result on the client side. Then the maximal length of
+ column values will be indicated by the
+ <literal>max_length</literal> member of the result set
+ metadata returned by
+ <literal>mysql_stmt_result_metadata()</literal>. This
+ strategy requires that you pass
+ <literal>STMT_ATTR_UPDATE_MAX_LENGTH</literal> to
+ <literal>mysql_stmt_attr_set()</literal> or the
+ <literal>max_length</literal> values will not be calculated.
+ </para>
+ </listitem>
+
+ <listitem>
+ <para>
+ Invoke <literal>mysql_stmt_fetch()</literal> with a
+ zero-length buffer for the column in question and a pointer
+ in which the real length can be stored. Then use the real
+ length with <literal>mysql_stmt_fetch_column()</literal>.
+ </para>
+
+<programlisting>
+real_length= 0;
+
+bind[0].buffer= 0;
+bind[0].buffer_length= 0;
+bind[0].length= &real_length
+mysql_stmt_bind_result(stmt, bind);
+
+mysql_stmt_fetch(stmt);
+if (real_length > 0)
+{
+ data= malloc(real_length);
+ bind[0].buffer= data;
+ bind[0].buffer_length= real_length;
+ mysql_stmt_fetch_column(stmt, 0, bind, 0);
+}
+</programlisting>
+
+ </listitem>
+
+ </itemizedlist>
+
</section>
<section id="mysql-stmt-fetch-column">
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r7129 - in trunk: . refman-4.1 refman-5.0 refman-5.1 refman-5.2 | paul | 17 Jul |