src/evsql/evsql.h
branchnew-evsql
changeset 44 9e76ee9729b6
parent 40 03017f5f0087
child 45 424ce5ab82fd
equal deleted inserted replaced
43:5776ace903b5 44:9e76ee9729b6
   104 struct evsql_query {
   104 struct evsql_query {
   105     // the actual SQL query, this may or may not be ours, see _evsql_query_exec
   105     // the actual SQL query, this may or may not be ours, see _evsql_query_exec
   106     char *command;
   106     char *command;
   107     
   107     
   108     // possible query params
   108     // possible query params
   109     struct evsql_query_param_info {
   109     struct evsql_query_params_pq {
   110         int count;
   110         int count;
   111 
   111 
   112         Oid *types;
   112         Oid *types;
   113         const char **values;
   113         const char **values;
   114         int *lengths;
   114         int *lengths;
   121     evsql_query_cb cb_fn;
   121     evsql_query_cb cb_fn;
   122     void *cb_arg;
   122     void *cb_arg;
   123 
   123 
   124     // our position in the query list
   124     // our position in the query list
   125     TAILQ_ENTRY(evsql_query) entry;
   125     TAILQ_ENTRY(evsql_query) entry;
       
   126 };
   126 
   127 
   127     // the result
   128 // the result
       
   129 struct evsql_result {
       
   130     int error;
       
   131 
   128     union {
   132     union {
   129         PGresult *evpq;
   133         PGresult *pq;
   130     } result;
   134     } result;
       
   135 
       
   136     // result_* state
       
   137     struct evsql_result_info *info;
       
   138     size_t row_offset;
   131 };
   139 };
       
   140 
   132 
   141 
   133 // maximum length for a 'BEGIN TRANSACTION ...' query
   142 // maximum length for a 'BEGIN TRANSACTION ...' query
   134 #define EVSQL_QUERY_BEGIN_BUF 512
   143 #define EVSQL_QUERY_BEGIN_BUF 512
   135 
   144 
   136 // the should the OID of some valid psql type... *ANY* valid psql type, doesn't matter, only used for NULLs
   145 // the should the OID of some valid psql type... *ANY* valid psql type, doesn't matter, only used for NULLs
   137 // 16 = bool in 8.3
   146 // 16 = bool in 8.3
   138 #define EVSQL_PQ_ARBITRARY_TYPE_OID 16
   147 #define EVSQL_PQ_ARBITRARY_TYPE_OID 16
   139 
   148 
       
   149 /*
       
   150  * Core query-submission interface.
       
   151  *
       
   152  * This performs some error-checking on the trans, allocates the evsql_query and does some basic initialization.
       
   153  *
       
   154  * This does not actually enqueue the query anywhere, no reference is stored anywhere.
       
   155  *
       
   156  * Returns the new evsql_query on success, NULL on failure.
       
   157  */
       
   158 static struct evsql_query *_evsql_query_new (struct evsql *evsql, struct evsql_trans *trans, evsql_query_cb query_fn, void *cb_arg);
       
   159 
       
   160 /*
       
   161  * Begin processing the given query, which should now be fully filled out.
       
   162  *
       
   163  * If trans is given, it MUST be idle, and the query will be executed. Otherwise, it will either be executed directly
       
   164  * or enqueued for future execution.
       
   165  *
       
   166  * Returns zero on success, nonzero on failure.
       
   167  */
       
   168 static int _evsql_query_enqueue (struct evsql *evsql, struct evsql_trans *trans, struct evsql_query *query, const char *command);
       
   169 
       
   170 /*
       
   171  * Validate and allocate the basic stuff for a new query.
       
   172  */
       
   173 
       
   174 
   140 #endif /* EVSQL_INTERNAL_H */
   175 #endif /* EVSQL_INTERNAL_H */