Re: [libdbi-users] Use dynamic dbi_result_bind_* functions
Yes, this functions solve my needs and the others users too. On Thu, Apr 17, 2008 at 8:19 AM, Markus Hoenicka [EMAIL PROTECTED] wrote: Markus Hoenicka writes: char* dbi_result_fget_string_copy(dbi_result Result, const char* fieldname); char* dbi_result_fget_string_copy_idx(dbi_result Result, unsigned int fieldidx); int dbi_result_fbind_string_copy(dbi_result Result, const char* fieldname, char** bindto); Come to think of it, the following names may be more appropriate: dbi_result_get_as_string_copy() dbi_result_get_as_string_copy_idx() dbi_result_bind_as_string_copy() dbi_result_get_as_longlong() dbi_result_get_as_longlong_idx() dbi_result_bind_as_longlong() The dbi_result_get_string* can get all values string, integers, datetime, all type will be return as string (char *). And the function caller need to free the results appropriately. Ex.: char * v; v = dbi_result_fget_string_copy(result, my_date); printf(This is a date: %s, v); - This is a date: 2008-04-17 10:38:00 v = dbi_result_fget_string_copy(result, my_bignumber); printf(This is a bignumber: %s, v); - This is a date: 109456135 How we will automatically convert the types into strings formats, inside dbi_result_fget_string*? Meanwhile, the dbi_result_get_as_longlong* return integers. What will be the retur If this get a string? regards, Markus -- Markus Hoenicka [EMAIL PROTECTED] (Spam-protected email: replace the quadrupeds with mhoenicka) http://www.mhoenicka.de -- --- 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 libdbi-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-users
[libdbi-users] libdbi and bind functions, testing
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 libdbi-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-users
Re: [libdbi-users] postgresql and copy command
Ok, I will try: // mdb-db is dbi_conn *db dbi_conn_t *myconn = (dbi_conn_t *)(mdb-db); // the key is use typedef. The function need be typedef typedef int (*custom_function_t)(void*, const char*, int); typedef char* (*custom_function_error_t)(void*); // function pointers int (*custom_function)(void*, const char*, int) = NULL; char* (*custom_function_error)(void*) = NULL; // How to use. Attention to typedef custom_function_t if ((custom_function = (custom_function_t)dbi_driver_specific_function(dbi_conn_get_driver(mdb-db), PQputCopyData)) != NULL) { do { res = (*custom_function)(myconn-connection, mdb-cmd, len); } while (res == 0 --count 0); // You can get a error, in postgresql. But not necessary direct from postgresql custom_function_error = (custom_function_error_t)dbi_driver_specific_function(dbi_conn_get_driver(mdb-db), PQerrorMessage); printf(my_dbi_batch_insert failed\n PQerrorMessage: %s, (*custom_function_error)(myconn-connection)); In weekend, I will try to do a complete example with g++. But the key is use typedef (see http://www.newty.de/fpt/functor.html) Thanks. On Fri, Mar 28, 2008 at 6:14 PM, Markus Hoenicka [EMAIL PROTECTED] wrote: João Henrique Freitas writes: Ok, Multiple parameters works well too. I am using g++ and need a typedef (typedef int (*custom_function)(void*, int);) to works. With gcc it works without the need of typedef Do you have a few lines of example code handy which show how to define the type and how to retrieve and call a custom function properly with g++? I'd like to add this to the programmer's guide. thanks Markus -- Markus Hoenicka [EMAIL PROTECTED] (Spam-protected email: replace the quadrupeds with mhoenicka) http://www.mhoenicka.de -- --- João Henrique Freitas - joaohf_at_gmail.com Campinas-SP-Brasil BSD051283 LPI 1 http://joaohf.pbwiki.com http://www.livejournal.com/users/joaohf/ - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace ___ libdbi-users mailing list libdbi-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-users
Re: [libdbi-users] postgresql and copy command
Oh, it's works. Great! Test 2: Run driver-specific function: mysql_get_proto_info returned: 10 I did a quick test and make check works. I will do more tests and report then. Thanks On Thu, Mar 27, 2008 at 4:44 PM, Markus Hoenicka [EMAIL PROTECTED] wrote: João Henrique Freitas writes: It's realy works? Could you please try the latest cvs version? I've discovered a portability issue of dlsym on at least FreeBSD and Linux. This does apparently not affect the symbols which are directly loaded by dlopen() (i.e. the driver functions), but those symbols which are defined in the shared libraries that drivers are linked against. On Linux, dlsym() will find the latter symbols just fine when using the handle returned by dlopen(), but this fails on FreeBSD. On that platform I have to use the special handle RTLD_NEXT to make it work. This trick in turn does not work on Linux. I had to resort to a hack in configure.in which sets a flag appropriately based on $host. If anyone knows how to handle this in a simpler fashion, please let me know. Also, if you have access to a platform other than FreeBSD and Linux, please build and install the cvs version of libdbi and run make check in libdbi-drivers to see whether custom functions work. If not, fiddle with the conditional in configure.in which sets dlsym_handle, and let me know the results. regards, Markus -- Markus Hoenicka [EMAIL PROTECTED] (Spam-protected email: replace the quadrupeds with mhoenicka) http://www.mhoenicka.de -- --- João Henrique Freitas - joaohf_at_gmail.com Campinas-SP-Brasil BSD051283 LPI 1 http://joaohf.pbwiki.com http://www.livejournal.com/users/joaohf/ - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace ___ libdbi-users mailing list libdbi-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-users