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 evsql_trans_done_cb done_fn; |
|
79 void *cb_arg; |
|
80 |
|
81 // the transaction type |
|
82 enum evsql_trans_type type; |
|
83 |
|
84 // has evsql_trans_commit be called? |
|
85 int has_commit : 1; |
|
86 |
|
87 // our current query |
|
88 struct evsql_query *query; |
|
89 |
|
90 }; |
|
91 |
|
92 /* |
|
93 * A single query. |
|
94 * |
|
95 * Has the info needed to exec the query (as these may be queued), and the callback/result info. |
|
96 */ |
|
97 struct evsql_query { |
|
98 // the actual SQL query, this may or may not be ours, see _evsql_query_exec |
|
99 char *command; |
|
100 |
|
101 // possible query params |
|
102 struct evsql_query_param_info { |
|
103 int count; |
|
104 |
|
105 Oid *types; |
|
106 const char **values; |
|
107 int *lengths; |
|
108 int *formats; |
|
109 |
|
110 int result_format; |
|
111 } params; |
|
112 |
|
113 // our callback |
|
114 evsql_query_cb cb_fn; |
|
115 void *cb_arg; |
|
116 |
|
117 // our position in the query list |
|
118 TAILQ_ENTRY(evsql_query) entry; |
|
119 |
|
120 // the result |
|
121 union { |
|
122 PGresult *evpq; |
|
123 } result; |
|
124 }; |
|
125 |
|
126 // maximum length for a 'BEGIN TRANSACTION ...' query |
|
127 #define EVSQL_QUERY_BEGIN_BUF 512 |
|
128 |
|
129 #endif /* EVSQL_INTERNAL_H */ |
|