From: Tim G. <ti...@of...> - 2001-08-06 09:33:58
|
I only just downloaded and installed libdbi, i took the exmaple program from the PDF and compiled, it seg faulted, i added some error handling and it still seg faults, can anyone offer some suggestions ? Compile line is gcc test.c -o test -ldl -ldbi Code is NOTE: the printf("1\n"); works and then it seg faults, all the testing i have done points to the connect. Tim #include <stdio.h> #include <dlfcn.h> #include <dbi/dbi.h> int main() { dbi_driver driver; dbi_result result; double threshold = 4.333333; unsigned int idnumber; const char *fullname; if (dbi_initialize(NULL) == -1) { printf(" dbi_initialize Failed... Aborting\n"); exit(0); } if ((driver = dbi_driver_open("mysql")) == NULL) { printf(" dbi_driver_open Failed... Aborting\n"); exit(0); } dbi_driver_set_option(driver, "host", "localhost"); dbi_driver_set_option(driver, "username", "username"); dbi_driver_set_option(driver, "password", "password"); dbi_driver_set_option(driver, "database", "database"); dbi_driver_set_option_numeric(driver, "efficient-queries", 1); printf("1\n"); if (dbi_driver_connect(driver) == -1) { printf("2a\n"); printf(" Driver Connection Failed....Aborting\n"); exit(0); } printf("2b\n"); result = dbi_driver_query(driver, "SELECT id, name FROM coders" "WHERE hours_of_sleep > %0.2f", threshold); while (dbi_result_next_row(result)) { idnumber = dbi_result_get_long(result, "id"); fullname = dbi_result_get_string(result, "name"); printf("%i. %s\n", idnumber, fullname); } dbi_result_free(result); dbi_driver_close(driver); dbi_shutdown(); return 0; } |