Hi,

I just finished writing the `dbi' plugin for collectd, which uses the
`dbi' library for database access.

Now I have some suggestions towards your interface, but before I get to
work I'd like to get some feedback to know if it's worth investing the
time.


Here it goes. It's in no particular order, just the way it came to mind:

- Error handling is very inconsistent. Especially the functions that
  return 1 (one) on success are *very* uncommon. I'd change that so that
  *all* functions (that return a status message) return 0 (zero) on
  success and less than zero upon failure.

- The `dbi_conn_error' function is weird to use. I'd add a function
  similar to the `strerror_r' function (with GNU extension):
    char *dbi_strerror (dbi_conn c, char *buffer, size_t buffer_size);
  The function will write the error message to the memory pointed to by
  `buffer' (not writing more than `buffer_size' bytes and assuring null-
  termination) and return the `buffer' pointer. This way, error
  reporting is easy and thread-safe (should that ever become an issue):

    status = dbi_foobar (...);
    if (status != 0)
    {
      char errbuf[1024];
      fprintf (stderr, "Function dbi_foobar failed: %s.\n",
          dbi_strerror (conn, errbuf, sizeof (errbuf)));
      return (-1);
    }

- Make `dbi_conn_set_option' return an error if it is passed an unknown
  option. That error should be well defined, so that applications may
  chose to ignore it.

- Add two functions, `dbi_result_get_string_buffer' and
  `dbi_result_get_string_buffer_idx', with the following signatures:

    int dbi_result_get_string_buffer (dbi_result res, const char *name,
        char *buffer, ssize_t *buffer_size);
    int dbi_result_get_string_buffer_idx (dbi_result res, int index,
        char *buffer, ssize_t *buffer_size);

  The functions return 0 (zero) upon success, non-zero otherwise. They
  will write at most `*buffer_size' bytes into `buffer' and will assure
  null-termination of the buffer. The total number of bytes that have
  been written to `buffer' will be stored in `*buffer_size'. If the
  field is NULL, `buffer' will not be touched and a negative value will
  be stored in `*buffer_size'. If anything other than zero is returned,
  neither memory location will be touched.

- Add code to cast data of the DBI_TYPE_INTEGER, DBI_TYPE_DECIMAL and
  DBI_TYPE_STRING types into each other type. The `dbi_result_get_*'
  should be extended to use that functionality.

  In my case I don't care what format the values are in in the database
  and I can live with losing a bit of precision. People who care about
  precision can still check for the type of each column (they need to do
  that now, too, so this doesn't make their situation any worse), but we
  could also introduce a flag that's passed to the `dbi_result_get_*' or
  a configuration option that's associated with the connection or
  something.


Any comments and suggestions are very welcome, of course :)

Regards,
-octo
-- 
Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D
http://verplant.org/

Attachment: signature.asc
Description: Digital signature

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
libdbi-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libdbi-devel

Reply via email to