src/evsql.h
branchnew-evsql
changeset 54 7dc8ff496da1
parent 53 0d6e07f4c9a1
child 55 0b92d553400a
equal deleted inserted replaced
53:0d6e07f4c9a1 54:7dc8ff496da1
    11  * underlying implementation, there is no guarantee that the same API will actually work with other databases' interface
    11  * underlying implementation, there is no guarantee that the same API will actually work with other databases' interface
    12  * libraries...
    12  * libraries...
    13  *
    13  *
    14  * The order of function calls and callbacks goes something like this:
    14  * The order of function calls and callbacks goes something like this:
    15  *
    15  *
    16  *  -   evsql_new_pq 
    16  *  -   evsql_new_pq()
    17  *
    17  *
    18  *  -   evsql_trans 
    18  *  -   evsql_trans()
    19  *      -   evsql_trans_abort
    19  *      -   evsql_trans_abort()
    20  *      -   evsql_trans_error_cb
    20  *      -   evsql_trans_error_cb()
    21  *      -   evsql_trans_ready_cb
    21  *      -   evsql_trans_ready_cb()
    22  *
    22  *
    23  *  -   evsql_query, evsql_params_* + evsql_query_params, evsql_query_exec 
    23  *  -   evsql_query(), \ref evsql_param_* + evsql_query_params(), evsql_query_exec()
    24  *      -   evsql_query_abort
    24  *      -   evsql_query_abort()
    25  *      -   evsql_query_cb
    25  *      -   evsql_query_cb()
    26  *          -   evsql_result_*
    26  *          -   \ref evsql_result_*
    27  *          -   evsql_result_free
    27  *          -   evsql_result_free()
    28  *
    28  *
    29  *  -   evsql_trans_commit
    29  *  -   evsql_trans_commit()
    30  *      -   evsql_trans_done_cb
    30  *      -   evsql_trans_done_cb()
    31  *
    31  *
    32  */
    32  */
    33 
    33 
    34 /**
    34 /**
    35  * System includes
    35  * System includes
    42  * For err_t.
    42  * For err_t.
    43  */
    43  */
    44 #include "lib/err.h"
    44 #include "lib/err.h"
    45 
    45 
    46 /**
    46 /**
    47  * The generic context handle used to manage a single "database connector" with multiple queries/transactions.
    47  * @struct evsql
       
    48  *
       
    49  * The generic session handle used to manage a single "database connector" with multiple queries/transactions.
       
    50  *
       
    51  * @see \ref evsql_
    48  */
    52  */
    49 struct evsql;
    53 struct evsql;
    50 
    54 
    51 /**
    55 /**
    52  * Opaque transaction handle
    56  * @struct evsql_trans
       
    57  *
       
    58  * Opaque transaction handle returned by evsql_trans() and used for the \ref evsql_query_ functions
       
    59  *
       
    60  * @see \ref evsql_trans_
    53  */
    61  */
    54 struct evsql_trans;
    62 struct evsql_trans;
    55 
    63 
    56 /**
    64 /**
    57  * Opaque query handle
    65  * @struct evsql_query
       
    66  *
       
    67  * Opaque query handle returned by the \ref evsql_query_ functions and used for evsql_query_abort()
       
    68  *
       
    69  * @see \ref evsql_query_
    58  */
    70  */
    59 struct evsql_query;
    71 struct evsql_query;
    60 
    72 
    61 /**
    73 /**
    62  * Opaque result handle
    74  * @struct evsql_result
       
    75  *
       
    76  * Opaque result handle received by evsql_query_cb(), and used with the \ref evsql_result_ functions
       
    77  *
       
    78  * @see evsql_query_cb()
       
    79  * @see \ref evsql_result_
    63  */
    80  */
    64 struct evsql_result;
    81 struct evsql_result;
    65 
    82 
    66 /**
    83 /**
    67  * Various transaction isolation levels for conveniance
    84  * Various transaction isolation levels for conveniance
   299 
   316 
   300 /**
   317 /**
   301  * Callback definitions
   318  * Callback definitions
   302  *
   319  *
   303  * @name evsql_*_cb
   320  * @name evsql_*_cb
   304  *
       
   305  * @{
   321  * @{
   306  */
   322  */
   307 
   323 
   308 /**
   324 /**
   309  * Callback for handling query results.
   325  * Callback for handling query results.
   310  *
   326  *
   311  * The query has completed, either succesfully or unsuccesfully.
   327  * The query has completed, either succesfully or unsuccesfully.
   312  *
   328  *
   313  * Use the evsql_result_* functions to manipulate the results, and call evsql_result_free (or equivalent) once done.
   329  * Use the \ref evsql_result_* functions to manipulate the results, and call evsql_result_free() (or equivalent) once done.
   314  *
   330  *
   315  * @param res The result handle that must be result_free'd after use
   331  * @param res The result handle that must be result_free'd after use
   316  * @param arg The void* passed to evsql_query_*
   332  * @param arg The void* passed to \ref evsql_query_*
   317  *
   333  *
   318  * @see evsql_query
   334  * @see evsql_query
   319  */
   335  */
   320 typedef void (*evsql_query_cb)(struct evsql_result *res, void *arg);
   336 typedef void (*evsql_query_cb)(struct evsql_result *res, void *arg);
   321 
   337 
   330  */
   346  */
   331 typedef void (*evsql_error_cb)(struct evsql *evsql, void *arg);
   347 typedef void (*evsql_error_cb)(struct evsql *evsql, void *arg);
   332 
   348 
   333 /**
   349 /**
   334  * Callback for handling transaction-level errors. This may be called at any time during a transaction's lifetime,
   350  * Callback for handling transaction-level errors. This may be called at any time during a transaction's lifetime,
   335  * including from within the evsql_query_* functions (but not always).
   351  * including from within the \ref evsql_query_* functions (but not always).
   336  *
   352  *
   337  * The transaction is not useable anymore.
   353  * The transaction is not useable anymore.
   338  *
   354  *
   339  * @param trans the transaction in question
   355  * @param trans the transaction in question
   340  * @param arg the void* passed to evsql_trans
   356  * @param arg the void* passed to evsql_trans
   342  * @see evsql_trans
   358  * @see evsql_trans
   343  */
   359  */
   344 typedef void (*evsql_trans_error_cb)(struct evsql_trans *trans, void *arg);
   360 typedef void (*evsql_trans_error_cb)(struct evsql_trans *trans, void *arg);
   345 
   361 
   346 /**
   362 /**
   347  * Callback for handling evsql_trans/evsql_query_abort completion. The transaction is ready for use with evsql_query_*.
   363  * Callback for handling evsql_trans/evsql_query_abort completion. The transaction is ready for use with \ref evsql_query_*.
   348  *
   364  *
   349  * @param trans the transaction in question
   365  * @param trans the transaction in question
   350  * @param arg the void* passed to evsql_trans
   366  * @param arg the void* passed to evsql_trans
   351  *
   367  *
   352  * @see evsql_trans
   368  * @see evsql_trans
   368 // @}
   384 // @}
   369 
   385 
   370 /**
   386 /**
   371  * Session functions
   387  * Session functions
   372  *
   388  *
   373  * @name evsql_*
   389  * @defgroup evsql_* Session interface
       
   390  * @see evsql.h
       
   391  * @{
       
   392  */
       
   393 
       
   394 /**
       
   395  * Session creation functions
       
   396  *
       
   397  * @defgroup evsql_new_* Session creation interface
       
   398  * @see evsql.h
   374  * @{
   399  * @{
   375  */
   400  */
   376 
   401 
   377 /**
   402 /**
   378  * Create a new PostgreSQL/libpq (evpq) -based evsql using the given conninfo.
   403  * Create a new PostgreSQL/libpq (evpq) -based evsql using the given conninfo.
   390 struct evsql *evsql_new_pq (struct event_base *ev_base, const char *pq_conninfo, 
   415 struct evsql *evsql_new_pq (struct event_base *ev_base, const char *pq_conninfo, 
   391     evsql_error_cb error_fn, 
   416     evsql_error_cb error_fn, 
   392     void *cb_arg
   417     void *cb_arg
   393 );
   418 );
   394 
   419 
       
   420 // @}
       
   421 
   395 /**
   422 /**
   396  * Close a connection. Callbacks for waiting queries will not be run.
   423  * Close a connection. Callbacks for waiting queries will not be run.
   397  *
   424  *
   398  * XXX: not implemented yet.
   425  * XXX: not implemented yet.
   399  *
   426  *
   400  * @ingroup evsql_*
   427  * @param evsql the context handle from \ref evsql_new_*
   401  * @param evsql the context handle from evsql_new_*
       
   402  */
   428  */
   403 void evsql_close (struct evsql *evsql);
   429 void evsql_close (struct evsql *evsql);
   404 
   430 
   405 // @}
   431 // @}
   406 
   432 
   407 /**
   433 /**
   408  * Query API
   434  * Query API
   409  *
   435  *
   410  * @name evsql_query_*
   436  * @defgroup evsql_query_* Query interface
       
   437  * @see evsql.h
   411  * @{
   438  * @{
   412  */
   439  */
   413 
   440 
   414 /**
   441 /**
   415  * Queue the given query for execution.
   442  * Queue the given query for execution.
   416  *
   443  *
   417  * If a trans is given (i.e. not NULL), then the transaction must be idle, and the query will be executed in that
   444  * If a trans is given (i.e. not NULL), then the transaction must be idle, and the query will be executed in that
   418  * transaction's context. Otherwise, the query will be executed without a transaction using an idle connection, or
   445  * transaction's context. Otherwise, the query will be executed without a transaction using an idle connection, or
   419  * enqueued for later execution.
   446  * enqueued for later execution.
   420  *
   447  *
   421  * Once the query is complete (got a result, got an error, the connection failed), then the query_cb will be called.
   448  * Once the query is complete (got a result, got an error, the connection failed), then the evsql_query_cb() will be called.
   422  * The callback can use the evsql_result_* functions to manipulate it.
   449  * The callback can use the \ref evsql_result_* functions to manipulate it.
   423  *
   450  *
   424  * The returned evsql_query handle can be passed to evsql_query_abort at any point before query_fn being called. 
   451  * The returned evsql_query handle can be passed to evsql_query_abort at any point before query_fn being called. 
   425  *
   452  *
   426  * @param evsql the context handle from evsql_new_*
   453  * @param evsql the context handle from \ref evsql_new_*
   427  * @param trans the optional transaction handle from evsql_trans
   454  * @param trans the optional transaction handle from evsql_trans
   428  * @param command the raw SQL command itself
   455  * @param command the raw SQL command itself
   429  * @param query_fn the query_cb to call once the query is complete
   456  * @param query_fn the evsql_query_cb() to call once the query is complete
   430  * @param cb_arg the void* passed to the above
   457  * @param cb_arg the void* passed to the above
   431  * @return the evsql_query handle that can be used to abort the query
   458  * @return the evsql_query handle that can be used to abort the query
   432  */
   459  */
   433 struct evsql_query *evsql_query (struct evsql *evsql, struct evsql_trans *trans, const char *command, evsql_query_cb query_fn, void *cb_arg);
   460 struct evsql_query *evsql_query (struct evsql *evsql, struct evsql_trans *trans, const char *command, evsql_query_cb query_fn, void *cb_arg);
   434 
   461 
   435 /**
   462 /**
   436  * Execute the given SQL query using the list of parameter types/values given via evsql_query_params.
   463  * Execute the given SQL query using the list of parameter types/values given via evsql_query_params.
   437  *
   464  *
   438  * Use the EVSQL_PARAMS macros to declare the struct, and the evsql_param_* functions to populate the values.
   465  * Use the EVSQL_PARAMS macros to declare the struct, and the \ref evsql_param_* functions to populate the values.
   439  *
   466  *
   440  * See evsql_query for more info about behaviour.
   467  * See evsql_query for more info about behaviour.
   441  *
   468  *
   442  * XXX: explain SQL param syntax...
   469  * XXX: explain SQL param syntax...
   443  *
   470  *
   444  * @param evsql the context handle from evsql_new_*
   471  * @param evsql the context handle from \ref evsql_new_*
   445  * @param trans the optional transaction handle from evsql_trans
   472  * @param trans the optional transaction handle from evsql_trans
   446  * @param command the SQL command to bind the parameters to
   473  * @param command the SQL command to bind the parameters to
   447  * @param params the parameter types and values
   474  * @param params the parameter types and values
   448  * @param query_fn the query_cb to call once the query is complete
   475  * @param query_fn the evsql_query_cb() to call once the query is complete
   449  * @param cb_arg the void* passed to the above
   476  * @param cb_arg the void* passed to the above
   450  * @see evsql_query
   477  * @see evsql_query
   451  */
   478  */
   452 struct evsql_query *evsql_query_params (struct evsql *evsql, struct evsql_trans *trans, 
   479 struct evsql_query *evsql_query_params (struct evsql *evsql, struct evsql_trans *trans, 
   453     const char *command, const struct evsql_query_params *params, 
   480     const char *command, const struct evsql_query_params *params, 
   458  * Execute the given query_info's SQL query with the values given as variable arguments, using the evsql_query_info to
   485  * Execute the given query_info's SQL query with the values given as variable arguments, using the evsql_query_info to
   459  * resolve the types.
   486  * resolve the types.
   460  *
   487  *
   461  * See evsql_query for more info about behaviour.
   488  * See evsql_query for more info about behaviour.
   462  *
   489  *
   463  * @param evsql the context handle from evsql_new_*
   490  * @param evsql the context handle from \ref evsql_new_*
   464  * @param trans the optional transaction handle from evsql_trans
   491  * @param trans the optional transaction handle from evsql_trans
   465  * @param query_info the SQL query information
   492  * @param query_info the SQL query information
   466  * @param query_fn the query_cb to call once the query is complete
   493  * @param query_fn the evsql_query_cb() to call once the query is complete
   467  * @param cb_arg the void* passed to the above
   494  * @param cb_arg the void* passed to the above
   468  * @see evsql_query
   495  * @see evsql_query
   469  */
   496  */
   470 struct evsql_query *evsql_query_exec (struct evsql *evsql, struct evsql_trans *trans, 
   497 struct evsql_query *evsql_query_exec (struct evsql *evsql, struct evsql_trans *trans, 
   471     const struct evsql_query_info *query_info,
   498     const struct evsql_query_info *query_info,
   472     evsql_query_cb query_fn, void *cb_arg,
   499     evsql_query_cb query_fn, void *cb_arg,
   473     ...
   500     ...
   474 );
   501 );
   475 
   502 
   476 /**
   503 /**
   477  * Abort a query returned by evsql_query_* that has not yet completed (query_fn has not been called yet).
   504  * Abort a query returned by \ref evsql_query_* that has not yet completed (query_fn has not been called yet).
   478  *
   505  *
   479  * The actual query itself may or may not be aborted (and hence may or may not be executed on the server), but query_fn
   506  * The actual query itself may or may not be aborted (and hence may or may not be executed on the server), but query_fn
   480  * will not be called anymore, and the query will dispose of itself and any results returned.
   507  * will not be called anymore, and the query will dispose of itself and any results returned.
   481  *
   508  *
   482  * If the query is part of a transaction, then trans must be given, and the query must be the query that is currently
   509  * If the query is part of a transaction, then trans must be given, and the query must be the query that is currently
   499 // @}
   526 // @}
   500 
   527 
   501 /**
   528 /**
   502  * Transaction API
   529  * Transaction API
   503  *
   530  *
   504  * @name evsql_trans_*
   531  * @defgroup evsql_trans_* Transaction interface
       
   532  * @see evsql.h
   505  * @{
   533  * @{
   506  */
   534  */
   507 
   535 
   508 /**
   536 /**
   509  * Create a new transaction.
   537  * Create a new transaction.
   510  *
   538  *
   511  * A transaction will be allocated its own connection, and the "BEGIN TRANSACTION ..." query will be sent (use the
   539  * A transaction will be allocated its own connection, and the "BEGIN TRANSACTION ..." query will be sent (use the
   512  * trans_type argument to specify this). 
   540  * trans_type argument to specify this). 
   513  *
   541  *
   514  * Once the transaction has been opened, the given trans_ready_cb will be triggered, and the transaction can then
   542  * Once the transaction has been opened, the given evsql_trans_ready_cb() will be triggered, and the transaction can then
   515  * be used (see evsql_query_*).
   543  * be used (see \ref evsql_query_*).
   516  *
   544  *
   517  * If, at any point, the transaction-connection fails, any pending query will be forgotten (i.e. the query callback
   545  * If, at any point, the transaction-connection fails, any pending query will be forgotten (i.e. the query callback
   518  * will NOT be called), and the given trans_error_cb will be called. Note that this includes some, but not all,
   546  * will NOT be called), and the given evsql_trans_error_cb() will be called. Note that this includes some, but not all,
   519  * cases where evsql_query_* returns an error.
   547  * cases where \ref evsql_query_* returns an error.
   520  *
   548  *
   521  * Once you are done with the transaction, call either evsql_trans_commit or evsql_trans_abort.
   549  * Once you are done with the transaction, call either evsql_trans_commit() or evsql_trans_abort().
   522  *
   550  *
   523  * @ingroup evsql_trans_*
   551  * @param evsql the context handle from \ref evsql_new_*
   524  * @param evsql the context handle from evsql_new_*
       
   525  * @param type the type of transaction to create
   552  * @param type the type of transaction to create
   526  * @param error_fn the trans_error_cb to call if this transaction fails
   553  * @param error_fn the evsql_trans_error_cb() to call if this transaction fails
   527  * @param ready_fn the trans_ready_cb to call once this transaction is ready for use
   554  * @param ready_fn the evsql_trans_ready_cb() to call once this transaction is ready for use
   528  * @param done_fn the trans_done_cb to call once this transaction has been commmited
   555  * @param done_fn the evsql_trans_done_cb() to call once this transaction has been commmited
   529  * @param cb_arg the void* to pass to the above
   556  * @param cb_arg the void* to pass to the above
   530  * @return the evsql_trans handle for use with other functions
   557  * @return the evsql_trans handle for use with other functions
   531  */
   558  */
   532 struct evsql_trans *evsql_trans (struct evsql *evsql, enum evsql_trans_type type, 
   559 struct evsql_trans *evsql_trans (struct evsql *evsql, enum evsql_trans_type type, 
   533     evsql_trans_error_cb error_fn, 
   560     evsql_trans_error_cb error_fn, 
   557  * No more transaction callbacks will be called. If there was a query running, it will be aborted, and the transaction
   584  * No more transaction callbacks will be called. If there was a query running, it will be aborted, and the transaction
   558  * then rollback'd.
   585  * then rollback'd.
   559  *
   586  *
   560  * You cannot abort a COMMIT, calling trans_abort on trans after a call to trans_commit is an error.
   587  * You cannot abort a COMMIT, calling trans_abort on trans after a call to trans_commit is an error.
   561  * 
   588  * 
   562  * Do not call evsql_trans_abort from within evsql_trans_error_cb!
   589  * Do not call evsql_trans_abort from within evsql_trans_error_cb()!
   563  *
   590  *
   564  * @param trans the transaction from evsql_trans to abort
   591  * @param trans the transaction from evsql_trans to abort
   565  * @see evsql_trans
   592  * @see evsql_trans
   566  */
   593  */
   567 void evsql_trans_abort (struct evsql_trans *trans);
   594 void evsql_trans_abort (struct evsql_trans *trans);
   568 
   595 
   569 /** 
   596 /** 
   570  * Retrieve the transaction-specific error message from the underlying engine.
   597  * Retrieve the transaction-specific error message from the underlying engine.
   571  *
   598  *
   572  * Intended to be called from trans_error_cb
   599  * Intended to be called from evsql_trans_error_cb()
   573  */
   600  */
   574 const char *evsql_trans_error (struct evsql_trans *trans);
   601 const char *evsql_trans_error (struct evsql_trans *trans);
   575 
   602 
   576 // @}
   603 // @}
   577 
   604 
   578 /**
   605 /**
   579  * Parameter-building functions.
   606  * Parameter-building functions.
   580  *
   607  *
   581  * These manipulate the value of the given parameter index.
   608  * These manipulate the value of the given parameter index.
   582  *
   609  *
   583  * @name evsql_param_*
   610  * @defgroup evsql_param_* Parameter interface
       
   611  * @see evsql.h
   584  * @{
   612  * @{
   585  */
   613  */
       
   614 
       
   615 /**
       
   616  * Sets the value of the parameter at the given index
       
   617  *
       
   618  * @param params the evsql_query_params struct
       
   619  * @param param the parameter index
       
   620  * @param ptr pointer to the binary data
       
   621  * @param len size of the binary data in bytes
       
   622  * @return zero on success, <0 on error
       
   623  */
   586 int evsql_param_binary (struct evsql_query_params *params, size_t param, const char *ptr, size_t len);
   624 int evsql_param_binary (struct evsql_query_params *params, size_t param, const char *ptr, size_t len);
       
   625 
       
   626 /** @see evsql_param_binary */
   587 int evsql_param_string (struct evsql_query_params *params, size_t param, const char *ptr);
   627 int evsql_param_string (struct evsql_query_params *params, size_t param, const char *ptr);
       
   628 
       
   629 /** @see evsql_param_binary */
   588 int evsql_param_uint16 (struct evsql_query_params *params, size_t param, uint16_t uval);
   630 int evsql_param_uint16 (struct evsql_query_params *params, size_t param, uint16_t uval);
       
   631 
       
   632 /** @see evsql_param_binary */
   589 int evsql_param_uint32 (struct evsql_query_params *params, size_t param, uint32_t uval);
   633 int evsql_param_uint32 (struct evsql_query_params *params, size_t param, uint32_t uval);
   590 int evsql_param_null   (struct evsql_query_params *params, size_t param);
   634 
       
   635 /**
       
   636  * Sets the given parameter to NULL
       
   637  *
       
   638  * @param params the evsql_query_params struct
       
   639  * @param param the parameter index
       
   640  * @return zero on success, <0 on error
       
   641  */
       
   642 int evsql_param_null (struct evsql_query_params *params, size_t param);
       
   643 
       
   644 /**
       
   645  * Clears all the parameter values (sets them to NULL)
       
   646  *
       
   647  * @param params the evsql_query_params struct
       
   648  * @return zero on success, <0 on error
       
   649  */
   591 int evsql_params_clear (struct evsql_query_params *params);
   650 int evsql_params_clear (struct evsql_query_params *params);
   592 
   651 
   593 // @}
   652 // @}
   594 
   653 
   595 /**
   654 /**
   596  * Result-handling functions
   655  * Result-handling functions
   597  *
   656  *
   598  * @name evsql_result_*
   657  * @defgroup evsql_result_* Result interface
       
   658  * @see evsql.h
       
   659  * @see evsql_result
   599  * @{
   660  * @{
   600  */
   661  */
   601 
   662 
   602 /**
   663 /**
   603  * Check the result for errors. Intended for use with non-data queries, i.e. CREATE, etc.
   664  * Check the result for errors. Intended for use with non-data queries, i.e. CREATE, etc.
   604  *
   665  *
   605  * Returns zero if the query was OK, err otherwise. EIO indicates an SQL error, the error message can be retrived
   666  * Returns zero if the query was OK, err otherwise. EIO indicates an SQL error, the error message can be retrived
   606  * using evsql_result_error.
   667  * using evsql_result_error.
   607  *
   668  *
   608  * @param res the result handle passed to query_cb
   669  * @param res the result handle passed to evsql_query_cb()
   609  * @return zero on success, EIO on SQL error, positive error code otherwise
   670  * @return zero on success, EIO on SQL error, positive error code otherwise
   610  */
   671  */
   611 err_t evsql_result_check (struct evsql_result *res);
   672 err_t evsql_result_check (struct evsql_result *res);
   612 
   673 
   613 /**
   674 /**
   622  * message can be retreived using evsql_result_error. The result must be released in both cases.
   683  * message can be retreived using evsql_result_error. The result must be released in both cases.
   623  *
   684  *
   624  * Note: currently the iterator state is simply stored in evsql_result, so only one iterator at a time per evsql_result.
   685  * Note: currently the iterator state is simply stored in evsql_result, so only one iterator at a time per evsql_result.
   625  *
   686  *
   626  * @param info the metadata to use to handle the result row columns
   687  * @param info the metadata to use to handle the result row columns
   627  * @param res the result handle passed to query_cb
   688  * @param res the result handle passed to evsql_query_cb()
   628  * @return zero on success, +err on error
   689  * @return zero on success, +err on error
   629  */
   690  */
   630 err_t evsql_result_begin (struct evsql_result_info *info, struct evsql_result *res);
   691 err_t evsql_result_begin (struct evsql_result_info *info, struct evsql_result *res);
   631 
   692 
   632 /**
   693 /**
   645  * The result should not be iterated or accessed anymore.
   706  * The result should not be iterated or accessed anymore.
   646  *
   707  *
   647  * Note: this does the same thing as evsql_result_free, and works regardless of evsql_result_begin returning
   708  * Note: this does the same thing as evsql_result_free, and works regardless of evsql_result_begin returning
   648  * succesfully or not.
   709  * succesfully or not.
   649  *
   710  *
   650  * @param res the result handle passed to query_cb
   711  * @param res the result handle passed to evsql_query_cb()
   651  * @see evsql_result_free
   712  * @see evsql_result_free
   652  */
   713  */
   653 void evsql_result_end (struct evsql_result *res);
   714 void evsql_result_end (struct evsql_result *res);
   654 
   715 
   655 /**
   716 /**
   656  * Get the error message associated with the result, intended for use after evsql_result_check/begin return an error
   717  * Get the error message associated with the result, intended for use after evsql_result_check/begin return an error
   657  * code.
   718  * code.
   658  * 
   719  * 
   659  * @param res the result handle passed to query_cb
   720  * @param res the result handle passed to evsql_query_cb()
   660  * @return a char* containing the NUL-terminated error string. Valid until evsql_result_free is called.
   721  * @return a char* containing the NUL-terminated error string. Valid until evsql_result_free is called.
   661  */
   722  */
   662 const char *evsql_result_error (const struct evsql_result *res);
   723 const char *evsql_result_error (const struct evsql_result *res);
   663 
   724 
   664 /**
   725 /**
   665  * Get the number of data rows returned by the query
   726  * Get the number of data rows returned by the query
   666  *
   727  *
   667  * @param res the result handle passed to query_cb
   728  * @param res the result handle passed to evsql_query_cb()
   668  * @return the number of rows, >= 0
   729  * @return the number of rows, >= 0
   669  */
   730  */
   670 size_t evsql_result_rows (const struct evsql_result *res);
   731 size_t evsql_result_rows (const struct evsql_result *res);
   671 
   732 
   672 /**
   733 /**
   673  * Get the number of columns in the data results from the query
   734  * Get the number of columns in the data results from the query
   674  *
   735  *
   675  * @param res the result handle passed to query_cb
   736  * @param res the result handle passed to evsql_query_cb()
   676  * @return the number of columns. XXX: zero if no data?
   737  * @return the number of columns. XXX: zero if no data?
   677  */
   738  */
   678 size_t evsql_result_cols (const struct evsql_result *res);
   739 size_t evsql_result_cols (const struct evsql_result *res);
   679 
   740 
   680 /**
   741 /**
   681  * Get the number of rows affected by an UPDATE/INSERT/etc query.
   742  * Get the number of rows affected by an UPDATE/INSERT/etc query.
   682  *
   743  *
   683  * @param res the result handle passed to query_cb
   744  * @param res the result handle passed to evsql_query_cb()
   684  * @return the number of rows affected, >= 0
   745  * @return the number of rows affected, >= 0
   685  */
   746  */
   686 size_t evsql_result_affected (const struct evsql_result *res);
   747 size_t evsql_result_affected (const struct evsql_result *res);
   687 
   748 
   688 /**
   749 /**
   690  *
   751  *
   691  * The given row/col must be within bounds as returned by evsql_result_rows/cols.
   752  * The given row/col must be within bounds as returned by evsql_result_rows/cols.
   692  *
   753  *
   693  * *ptr will point to *size bytes of read-only memory allocated internally.
   754  * *ptr will point to *size bytes of read-only memory allocated internally.
   694  *
   755  *
   695  * @param res the result handle passed to query_cb
   756  * @param res the result handle passed to evsql_query_cb()
   696  * @param row the row index to access
   757  * @param row the row index to access
   697  * @param col the column index to access
   758  * @param col the column index to access
   698  * @param ptr where to store a pointer to the read-only field data, free'd upon evsql_result_free
   759  * @param ptr where to store a pointer to the read-only field data, free'd upon evsql_result_free
   699  * @param size updated to the size of the field value pointed to by ptr
   760  * @param size updated to the size of the field value pointed to by ptr
   700  * @param nullok when true and the field value is NULL, *ptr and *size are not modified, otherwise NULL means an error
   761  * @param nullok when true and the field value is NULL, *ptr and *size are not modified, otherwise NULL means an error
   707  *
   768  *
   708  * The given row/col must be within bounds as returned by evsql_result_rows/cols.
   769  * The given row/col must be within bounds as returned by evsql_result_rows/cols.
   709  *
   770  *
   710  * *ptr will point to a NUL-terminated string allocated internally.
   771  * *ptr will point to a NUL-terminated string allocated internally.
   711  *
   772  *
   712  * @param res the result handle passed to query_cb
   773  * @param res the result handle passed to evsql_query_cb()
   713  * @param row the row index to access
   774  * @param row the row index to access
   714  * @param col the column index to access
   775  * @param col the column index to access
   715  * @param ptr where to store a pointer to the read-only field data, free'd upon evsql_result_free
   776  * @param ptr where to store a pointer to the read-only field data, free'd upon evsql_result_free
   716  * @param nullok when true and the field value is NULL, *ptr and *size are not modified, otherwise NULL means an error
   777  * @param nullok when true and the field value is NULL, *ptr and *size are not modified, otherwise NULL means an error
   717  * @return zero on success, <0 on error
   778  * @return zero on success, <0 on error
   722  * Use evsql_result_binary to read a binary field value, and then convert it using ntoh[slq], storing the value in
   783  * Use evsql_result_binary to read a binary field value, and then convert it using ntoh[slq], storing the value in
   723  * *val.
   784  * *val.
   724  *
   785  *
   725  * The given row/col must be within bounds as returned by evsql_result_rows/cols.
   786  * The given row/col must be within bounds as returned by evsql_result_rows/cols.
   726  *
   787  *
   727  * @param res the result handle passed to query_cb
   788  * @param res the result handle passed to evsql_query_cb()
   728  * @param row the row index to access
   789  * @param row the row index to access
   729  * @param col the column index to access
   790  * @param col the column index to access
   730  * @param uval where to store the decoded value
   791  * @param uval where to store the decoded value
   731  * @param nullok when true and the field value is NULL, *ptr and *size are not modified, otherwise NULL means an error
   792  * @param nullok when true and the field value is NULL, *ptr and *size are not modified, otherwise NULL means an error
   732  * @return zero on success, <0 on error
   793  * @return zero on success, <0 on error
   733  */
   794  */
   734 int evsql_result_uint16 (const struct evsql_result *res, size_t row, size_t col, uint16_t *uval, int nullok);
   795 int evsql_result_uint16 (const struct evsql_result *res, size_t row, size_t col, uint16_t *uval, int nullok);
       
   796 
       
   797 /** @see evsql_result_uint16 */
   735 int evsql_result_uint32 (const struct evsql_result *res, size_t row, size_t col, uint32_t *uval, int nullok);
   798 int evsql_result_uint32 (const struct evsql_result *res, size_t row, size_t col, uint32_t *uval, int nullok);
       
   799 
       
   800 /** @see evsql_result_uint16 */
   736 int evsql_result_uint64 (const struct evsql_result *res, size_t row, size_t col, uint64_t *uval, int nullok);
   801 int evsql_result_uint64 (const struct evsql_result *res, size_t row, size_t col, uint64_t *uval, int nullok);
   737 
   802 
   738 /**
   803 /**
   739  * Every result handle passed to query_cb MUST be released by the user, using this function.
   804  * Every result handle passed to evsql_query_cb() MUST be released by the user, using this function.
   740  *
   805  *
   741  * @param res the result handle passed to query_cb
   806  * @param res the result handle passed to evsql_query_cb()
   742  */
   807  */
   743 void evsql_result_free (struct evsql_result *res);
   808 void evsql_result_free (struct evsql_result *res);
   744 
   809 
   745 // @}
   810 // @}
   746 
   811