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

Reply via email to