Hello,
I need to work with some bind functions in libdbi. And I will test all
and put on dbi_test.c.
Before, a little test whit the code:
#include <stdio.h>
#include <dbi/dbi.h>
int main() {
dbi_conn conn;
dbi_result result;
dbi_inst instance;
double threshold = 1;
unsigned int idnumber;
const char *fullname = (char *)malloc(sizeof(char) * 30);
int error;
dbi_initialize_r(NULL, &instance);
conn = dbi_conn_new_r("pgsql", instance);
dbi_conn_set_option(conn, "host", "127.0.0.1");
dbi_conn_set_option(conn, "port", "5432");
dbi_conn_set_option(conn, "username", "regress");
//dbi_conn_set_option(conn, "password", "");
dbi_conn_set_option(conn, "dbname", "libdbitest");
dbi_conn_set_option(conn, "encoding", "UTF-8");
if (dbi_conn_connect(conn) < 0) {
printf("Could not connect. Please check the option settings\n");
}
else {
result = dbi_conn_queryf(conn, "SELECT id, name FROM authors "
"WHERE hours_of_sleep > %0.2f", threshold);
if (result) {
while (dbi_result_next_row(result)) {
error = dbi_result_bind_uint(result, "id", &idnumber);
dbi_result_bind_string(result, "name", &fullname);
printf("%i. %s\n", idnumber, fullname);
}
dbi_result_free(result);
}
dbi_conn_close(conn);
}
dbi_shutdown_r(instance);
return 0;
}
In database:
libdbitest=# select * from authors;
id | name | hours_of_sleep
----+-------+----------------
1 | joao | 2
2 | joao | 2
3 | joao | 20
40 | joao | 20
40 | jOO | 2
40 | Erika | 2
40 | Er | 2
(7 registros)
The result of program:
./dbi_bind_test
custom_functions went to 0x804bcb0
custom_functions went to 0x804d498
custom_functions went to 0x8051a88
134514196.
2. joao
3. joao
40. joao
40. jOO
40. Erika
40. Er
Two questions:
1. Is correct the use of bind functions?
2. Why the first result is 134514196. ?
Thanks.
--
-----------------------------------------------------------
João Henrique Freitas - joaohf_at_gmail.com
Campinas-SP-Brasil
BSD051283
LPI 1
http://joaohf.pbwiki.com
http://www.livejournal.com/users/joaohf/
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
libdbi-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libdbi-users