File: mysql_fetch_row.xml

package info (click to toggle)
scilab-scimysql 0.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 988 kB
  • ctags: 105
  • sloc: xml: 7,315; ansic: 2,573; sql: 143; makefile: 19; sh: 6
file content (140 lines) | stat: -rw-r--r-- 4,433 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?xml version="1.0" encoding="UTF-8"?>
<refentry version="5.0-subset Scilab" xml:id="mysql_fetch_row" xml:lang="en"
          xmlns="http://docbook.org/ns/docbook"
          xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg"
          xmlns:ns3="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:db="http://docbook.org/ns/docbook">
  <refnamediv>
    <refname>mysql_fetch_row</refname>

    <refpurpose>Retrieves the next row of a result set.</refpurpose>
  </refnamediv>

  <refsynopsisdiv>
    <title>Calling Sequence</title>

    <synopsis>rows = mysql_fetch_rows(mysql_res)</synopsis>
  </refsynopsisdiv>

  <refsection>
    <title>Description</title>

    <para>Retrieves the next row of a result set.</para>
    <para>When used after <literal>mysql_store_result</literal>, 
      <literal>mysql_fetch_row</literal> returns empty when there 
      are no more rows to retrieve.</para>
    <para>When used after <literal>mysql_use_result</literal>, 
      <literal>mysql_fetch_row</literal> returns empty when 
      there are no more rows to retrieve or if an error occurred.</para>
    <para>The number of values in the row is given by 
      <literal>mysql_num_fields(result)</literal>.</para>
    <para>If row holds the return value from a call to 
      <literal>mysql_fetch_row</literal>, pointers to the values
      are accessed as <literal>row[1]</literal> to 
      <literal>row[mysql_num_fields(result)]</literal>.</para>
    <para>The lengths of the field values in the row may be 
      obtained by calling <literal>mysql_fetch_lengths</literal>.</para>
  </refsection>

  <refsection>
    <title>Parameters</title>

    <variablelist>
      <varlistentry>
        <term>mysql_res</term>

        <listitem>
          <para>a MySQL_RES pointer</para>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term>rows</term>

        <listitem>
          <para>A matrix of strings for the next row. Empty if there are no more rows
	    to retrieve or if an error occurred.</para>
	  <itemizedlist>
	    <listitem><para>CR_SERVER_LOST The connection to the server was lost during the query.</para></listitem>
	    <listitem><para>CR_UNKNOWN_ERROR An unknown error occurred.</para></listitem>
	  </itemizedlist>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsection>

  <refsection>
    <title>Examples</title>

    <programlisting role="example"><![CDATA[ 
username = 'glpk'; // Put your username
password = 'gnu';  // Put your password
database = 'glpk'; 
port     = 3306;   // use netstat -a | grep mysql to locate the mysql port
                   // or ps -elf | grep mysql and locate --port
myhost   = 'localhost'; // localhost most of the time

sql_ptr = mysql_init();
status  = mysql_real_connect(sql_ptr, myhost, username, password, database, port);

timer();

if (status) then
  printf('Error message: %s, error number: %d\n', mysql_error(sql_ptr), mysql_errno(sql_ptr));
end

// For sudoku
step       = 1.0;
start_step = 0.0;
end_step   = 7.0;
res        = 0.0;
row        = [];

for var=start_step:step:end_step do
  sql = sprintf("select val from sudoku where val>=%f and val<%f;\n", var, end_step);

  printf('query: ' + sql + ' -> ');
  status = mysql_real_query(sql_ptr, sql);
  disp(mysql_error(sql_ptr));
  rs   = mysql_store_result(sql_ptr);
  _row = mysql_fetch_row(rs);
  for i=1:length(_row)
    printf('%s ', _row(i));
  end
  printf('\n');
  res = res + sum(evstr(_row));
  mysql_free_result(rs);
end

disp(timer());

printf('Cumulated sum for the selected items: %f\n',res);

printf('Number of affected rows: %d\n', mysql_affected_rows(sql_ptr));

mysql_close(sql_ptr);
 ]]></programlisting>
  </refsection>

  <refsection>
    <title>See Also</title>

    <simplelist type="inline">
      <member><link linkend="mysql_init">mysql_init</link></member>
      <member><link linkend="mysql_real_query">mysql_real_query</link></member>
      <member><link linkend="mysql_real_connect">mysql_real_connect</link></member>
      <member><link linkend="mysql_close">mysql_close</link></member>
      <member><link linkend="mysql_store_result">mysql_store_result</link></member>
    </simplelist>
  </refsection>

  <refsection>
    <title>Authors</title>

    <simplelist type="vert">
      <member>Yann COLLETTE</member>
    </simplelist>
  </refsection>
</refentry>