src/evsql_internal.h
changeset 25 99a41f48e29b
child 26 61668c57f4bb
equal deleted inserted replaced
24:82cfdb6680d1 25:99a41f48e29b
       
     1 #ifndef EVSQL_INTERNAL_H
       
     2 #define EVSQL_INTERNAL_H
       
     3 
       
     4 #include <sys/queue.h>
       
     5 
       
     6 #include "evsql.h"
       
     7 
       
     8 /*
       
     9  * The engine type
       
    10  */
       
    11 enum evsql_type {
       
    12     EVSQL_EVPQ,     // evpq
       
    13 };
       
    14 
       
    15 /*
       
    16  * Contains the type, engine configuration, list of connections and waiting query queue.
       
    17  */
       
    18 struct evsql {
       
    19     // what event_base to use
       
    20     struct event_base *ev_base;
       
    21 
       
    22     // what engine we use
       
    23     enum evsql_type type;
       
    24 
       
    25     // callbacks
       
    26     evsql_error_cb error_fn;
       
    27     void *cb_arg;
       
    28     
       
    29     // engine-specific connection configuration
       
    30     union {
       
    31         const char *evpq;
       
    32     } engine_conf;
       
    33 
       
    34     // list of connections that are open
       
    35     LIST_HEAD(evsql_conn_list, evsql_conn) conn_list;
       
    36    
       
    37     // list of queries running or waiting to run
       
    38     TAILQ_HEAD(evsql_query_queue, evsql_query) query_queue;
       
    39 };
       
    40 
       
    41 /*
       
    42  * A single connection to the server.
       
    43  *
       
    44  * Contains the engine connection, may have a transaction associated, and may have a query associated.
       
    45  */
       
    46 struct evsql_conn {
       
    47     // evsql we belong to
       
    48     struct evsql *evsql;
       
    49 
       
    50     // engine-specific connection info
       
    51     union {
       
    52         struct evpq_conn *evpq;
       
    53     } engine;
       
    54 
       
    55     // our position in the conn list
       
    56     LIST_ENTRY(evsql_conn) entry;
       
    57 
       
    58     // are we running a transaction?
       
    59     struct evsql_trans *trans;
       
    60 
       
    61     // are we running a transactionless query?
       
    62     struct evsql_query *query;
       
    63 };
       
    64 
       
    65 /*
       
    66  * A single transaction.
       
    67  *
       
    68  * Has a connection associated and possibly a query (which will also be associated with the connection)
       
    69  */
       
    70 struct evsql_trans {
       
    71     // our evsql_conn/evsql
       
    72     //struct evsql *evsql;
       
    73     struct evsql_conn *conn;
       
    74     
       
    75     // callbacks
       
    76     evsql_trans_error_cb error_fn;
       
    77     evsql_trans_ready_cb ready_fn;
       
    78     void *cb_arg;
       
    79 
       
    80     // the transaction type
       
    81     enum evsql_trans_type type;
       
    82 
       
    83     // our current query
       
    84     struct evsql_query *query;
       
    85 
       
    86 };
       
    87 
       
    88 /*
       
    89  * A single query.
       
    90  *
       
    91  * Has the info needed to exec the query (as these may be queued), and the callback/result info.
       
    92  */
       
    93 struct evsql_query {
       
    94     // the actual SQL query, this may or may not be ours, see _evsql_query_exec
       
    95     char *command;
       
    96     
       
    97     // possible query params
       
    98     struct evsql_query_param_info {
       
    99         int count;
       
   100 
       
   101         Oid *types;
       
   102         const char **values;
       
   103         int *lengths;
       
   104         int *formats;
       
   105 
       
   106         int result_format;
       
   107     } params;
       
   108 
       
   109     // our callback
       
   110     evsql_query_cb cb_fn;
       
   111     void *cb_arg;
       
   112 
       
   113     // our position in the query list
       
   114     TAILQ_ENTRY(evsql_query) entry;
       
   115 
       
   116     // the result
       
   117     union {
       
   118         PGresult *evpq;
       
   119     } result;
       
   120 };
       
   121 
       
   122 // maximum length for a 'BEGIN TRANSACTION ...' query
       
   123 #define EVSQL_QUERY_BEGIN_BUF 512
       
   124 
       
   125 #endif /* EVSQL_INTERNAL_H */