~drizzle-trunk/libdrizzle/jenkins-Libdrizzle-43

« back to all changes in this revision

Viewing changes to docs/examples/statement.rst

  • Committer: Continuous Integration
  • Date: 2013-01-04 21:00:11 UTC
  • mfrom: (78.1.2 5.1-docs)
  • Revision ID: ci@drizzle.org-20130104210011-go6x67u8nprtkj40
Merge lp:~linuxjedi/libdrizzle/5.1-docs Build: jenkins-Libdrizzle-32

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
:c:func:`drizzle_stmt_prepare` and we can get the number of parameters the
13
13
server is expecting with :c:func:`drizzle_stmt_param_count`.  In this example
14
14
we know that there is only one parameter required so we send one INT type
15
 
parameter using :c:func:`drizzle_stmt_bind_param` stating that this is
16
 
parameter 0 and it is 4 bytes long (standard for an INT type).
 
15
parameter using :c:func:`drizzle_stmt_set_int` stating that this is
 
16
parameter 0 and a signed value.
17
17
 
18
18
Once the parameters have been provided the statement is executed using
19
19
:c:func:`drizzle_stmt_execute` and the results buffered using
22
22
 
23
23
Finally we get the result data.  A call to :c:func:`drizzle_stmt_fetch` gets
24
24
the next row from either the network or the buffer (the buffer in this case).
25
 
The data can be retreived using :c:func:`drizzle_stmt_item_data`, a call for
26
 
each column in the row (in example the table only has one column).
27
 
 
28
 
It is also possible to get the data type and length of data using the other
29
 
``drizzle_stmt_item_`` functions.
 
25
The int data is retreived using :c:func:`drizzle_stmt_get_int`, a call for
 
26
each column in the row (in example the table only has one column) is made using
 
27
the ``drizzle_stmt_get_`` functions.
30
28
 
31
29
When we are done the statement is closed and cleaned up using
32
30
:c:func:`drizzle_stmt_close`.  It can also be reused with
45
43
  printf("Params: %" PRIu16 "\n", drizzle_stmt_param_count(stmt));
46
44
 
47
45
  uint32_t val= 1;
48
 
  ret = drizzle_stmt_bind_param(stmt, 0, DRIZZLE_COLUMN_TYPE_LONG, &val, 4, DRIZZLE_BIND_OPTION_NONE);
 
46
  ret = drizzle_stmt_set_int(stmt, 0, val, false);
49
47
 
50
48
  ret = drizzle_stmt_execute(stmt);
51
49
 
54
52
  printf("Rows found: %" PRIu64 "\n", drizzle_stmt_row_count(stmt));
55
53
  while (drizzle_stmt_fetch(stmt) != DRIZZLE_RETURN_ROW_END)
56
54
  {
57
 
    uint32_t *res_val;
58
 
    res_val= (uint32_t*)drizzle_stmt_item_data(stmt, 0);
 
55
    uint32_t res_val;
 
56
    res_val= drizzle_stmt_get_int(stmt, 0, &ret);
59
57
    printf("Got value: %" PRIu32 "\n", *res_val);
60
58
  }
61
59
  ret = drizzle_stmt_close(stmt);