95 struct evsql_query *query; |
95 struct evsql_query *query; |
96 |
96 |
97 }; |
97 }; |
98 |
98 |
99 /* |
99 /* |
|
100 * Backend result handle |
|
101 */ |
|
102 union evsql_result_handle { |
|
103 PGresult *pq; |
|
104 }; |
|
105 |
|
106 /* |
100 * A single query. |
107 * A single query. |
101 * |
108 * |
102 * Has the info needed to exec the query (as these may be queued), and the callback/result info. |
109 * Has the info needed to exec the query (as these may be queued), and the callback/result info. |
103 */ |
110 */ |
104 struct evsql_query { |
111 struct evsql_query { |
105 // the actual SQL query, this may or may not be ours, see _evsql_query_exec |
112 // the actual SQL query, this may or may not be ours, see _evsql_query_exec |
106 char *command; |
113 char *command; |
107 |
114 |
108 // possible query params |
115 // possible query params |
109 struct evsql_query_param_info { |
116 struct evsql_query_params_pq { |
110 int count; |
117 int count; |
111 |
118 |
112 Oid *types; |
119 Oid *types; |
113 const char **values; |
120 const char **values; |
114 int *lengths; |
121 int *lengths; |
115 int *formats; |
122 int *formats; |
116 |
123 |
|
124 // storage for numeric values |
|
125 union evsql_item_value *item_vals; |
|
126 |
117 int result_format; |
127 int result_format; |
118 } params; |
128 } params; |
119 |
129 |
120 // our callback |
130 // our callback |
121 evsql_query_cb cb_fn; |
131 evsql_query_cb cb_fn; |
122 void *cb_arg; |
132 void *cb_arg; |
|
133 |
|
134 // the result we get |
|
135 union evsql_result_handle result; |
123 |
136 |
124 // our position in the query list |
137 // our position in the query list |
125 TAILQ_ENTRY(evsql_query) entry; |
138 TAILQ_ENTRY(evsql_query) entry; |
|
139 }; |
126 |
140 |
127 // the result |
141 // the result |
128 union { |
142 struct evsql_result { |
129 PGresult *evpq; |
143 struct evsql *evsql; |
130 } result; |
144 |
|
145 // possible error code |
|
146 int error; |
|
147 |
|
148 // the actual result |
|
149 union evsql_result_handle result; |
|
150 |
|
151 // result_* state |
|
152 struct evsql_result_info *info; |
|
153 size_t row_offset; |
131 }; |
154 }; |
|
155 |
132 |
156 |
133 // maximum length for a 'BEGIN TRANSACTION ...' query |
157 // maximum length for a 'BEGIN TRANSACTION ...' query |
134 #define EVSQL_QUERY_BEGIN_BUF 512 |
158 #define EVSQL_QUERY_BEGIN_BUF 512 |
135 |
159 |
136 // the should the OID of some valid psql type... *ANY* valid psql type, doesn't matter, only used for NULLs |
160 // 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 |
161 // 16 = bool in 8.3 |
138 #define EVSQL_PQ_ARBITRARY_TYPE_OID 16 |
162 #define EVSQL_PQ_ARBITRARY_TYPE_OID 16 |
139 |
163 |
|
164 /* |
|
165 * Core query-submission interface. |
|
166 * |
|
167 * This performs some error-checking on the trans, allocates the evsql_query and does some basic initialization. |
|
168 * |
|
169 * This does not actually enqueue the query anywhere, no reference is stored anywhere. |
|
170 * |
|
171 * Returns the new evsql_query on success, NULL on failure. |
|
172 */ |
|
173 struct evsql_query *_evsql_query_new (struct evsql *evsql, struct evsql_trans *trans, evsql_query_cb query_fn, void *cb_arg); |
|
174 |
|
175 /* |
|
176 * Begin processing the given query, which should now be fully filled out. |
|
177 * |
|
178 * If trans is given, it MUST be idle, and the query will be executed. Otherwise, it will either be executed directly |
|
179 * or enqueued for future execution. |
|
180 * |
|
181 * Returns zero on success, nonzero on failure. |
|
182 */ |
|
183 int _evsql_query_enqueue (struct evsql *evsql, struct evsql_trans *trans, struct evsql_query *query, const char *command); |
|
184 |
|
185 /* |
|
186 * Free the query and related resources, doesn't trigger any callbacks or remove from any queues. |
|
187 * |
|
188 * The command should already be taken care of (NULL). |
|
189 */ |
|
190 void _evsql_query_free (struct evsql_query *query); |
|
191 |
140 #endif /* EVSQL_INTERNAL_H */ |
192 #endif /* EVSQL_INTERNAL_H */ |