src/evsql.h
changeset 26 61668c57f4bb
parent 25 99a41f48e29b
child 27 461be4cd34a3
equal deleted inserted replaced
25:99a41f48e29b 26:61668c57f4bb
   134  * The transaction is ready for use.
   134  * The transaction is ready for use.
   135  */
   135  */
   136 typedef void (*evsql_trans_ready_cb)(struct evsql_trans *trans, void *arg);
   136 typedef void (*evsql_trans_ready_cb)(struct evsql_trans *trans, void *arg);
   137 
   137 
   138 /*
   138 /*
       
   139  * The transaction was commited, and should not be used anymore.
       
   140  */
       
   141 typedef void (*evsql_trans_done_cb)(struct evsql_trans *trans, void *arg);
       
   142 
       
   143 /*
   139  * Create a new PostgreSQL/libpq(evpq) -based evsql using the given conninfo.
   144  * Create a new PostgreSQL/libpq(evpq) -based evsql using the given conninfo.
   140  *
   145  *
   141  * The given conninfo must stay valid for the duration of the evsql's lifetime.
   146  * The given conninfo must stay valid for the duration of the evsql's lifetime.
   142  */
   147  */
   143 struct evsql *evsql_new_pq (struct event_base *ev_base, const char *pq_conninfo, evsql_error_cb error_fn, void *cb_arg);
   148 struct evsql *evsql_new_pq (struct event_base *ev_base, const char *pq_conninfo, evsql_error_cb error_fn, void *cb_arg);
   145 /*
   150 /*
   146  * Create a new transaction.
   151  * Create a new transaction.
   147  *
   152  *
   148  * Transactions are separate connections that provide transaction-isolation.
   153  * Transactions are separate connections that provide transaction-isolation.
   149  *
   154  *
   150  * Once the transaction is ready for use, ready_fn will be called. If the transaction fails, any pending query will be forgotten, and error_fn called.
   155  * Once the transaction is ready for use, ready_fn will be called. If the transaction fails, any pending query will be
   151  */
   156  * forgotten, and error_fn called. This also includes some (but not all) cases where evsql_query returns nonzero.
   152 struct evsql_trans *evsql_trans (struct evsql *evsql, enum evsql_trans_type type, evsql_trans_error_cb error_fn, evsql_trans_ready_cb ready_fn, void *cb_arg);
   157  *
       
   158  */
       
   159 struct evsql_trans *evsql_trans (struct evsql *evsql, enum evsql_trans_type type, evsql_trans_error_cb error_fn, evsql_trans_ready_cb ready_fn, evsql_trans_done_cb done_fn, void *cb_arg);
   153 
   160 
   154 /*
   161 /*
   155  * Queue the given query for execution.
   162  * Queue the given query for execution.
   156  *
   163  *
   157  * If trans is specified (not NULL), then the transaction must be idle, and the query will be executed in that
   164  * If trans is specified (not NULL), then the transaction must be idle, and the query will be executed in that
   164 
   171 
   165 /*
   172 /*
   166  * Same as evsql_query, but uses the SQL-level support for binding parameters.
   173  * Same as evsql_query, but uses the SQL-level support for binding parameters.
   167  */
   174  */
   168 struct evsql_query *evsql_query_params (struct evsql *evsql, struct evsql_trans *trans, const char *command, const struct evsql_query_params *params, evsql_query_cb query_fn, void *cb_arg);
   175 struct evsql_query *evsql_query_params (struct evsql *evsql, struct evsql_trans *trans, const char *command, const struct evsql_query_params *params, evsql_query_cb query_fn, void *cb_arg);
       
   176 
       
   177 /*
       
   178  * Commit a transaction, calling done_fn if it was succesfull (error_fn otherwise).
       
   179  */
       
   180 int evsql_trans_commit (struct evsql_trans *trans);
       
   181 
       
   182 /*
       
   183  * Abort a transaction, rolling it back. No callbacks will be called, unless this function returns nonzero, in which
       
   184  * case error_fn might be called.
       
   185  */
       
   186 int evsql_trans_abort (struct evsql_trans *trans);
       
   187 
       
   188 /*
       
   189  * Transaction-handling functions
       
   190  */
       
   191 
       
   192 // error string, meant to be called from evsql_trans_error_cb
       
   193 const char *evsql_trans_error (struct evsql_trans *trans);
       
   194 
       
   195 // commit the transaction, calling 
   169 
   196 
   170 /*
   197 /*
   171  * Param-building functions
   198  * Param-building functions
   172  */
   199  */
   173 int evsql_param_string (struct evsql_query_params *params, size_t param, const char *ptr);
   200 int evsql_param_string (struct evsql_query_params *params, size_t param, const char *ptr);