author | Tero Marttila <terom@fixme.fi> |
Sun, 08 Mar 2009 01:40:26 +0200 | |
changeset 59 | 54a2e6be81a7 |
parent 58 | 02e539965ef4 |
child 64 | 83d53afa2551 |
permissions | -rw-r--r-- |
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
#ifndef EVSQL_INTERNAL_H |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
#define EVSQL_INTERNAL_H |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
/* |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
* Internal interfaces |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
*/ |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
#include <sys/queue.h> |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
#include <event2/event.h> |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
|
59 | 12 |
#include "include/evsql.h" |
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
#include "evpq.h" |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
/* |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
* The engine type |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
*/ |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
enum evsql_type { |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
EVSQL_EVPQ, // evpq |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
}; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
22 |
/* |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
* Contains the type, engine configuration, list of connections and waiting query queue. |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
24 |
*/ |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
struct evsql { |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
// what event_base to use |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
struct event_base *ev_base; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
// what engine we use |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
enum evsql_type type; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
// callbacks |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
33 |
evsql_error_cb error_fn; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
34 |
void *cb_arg; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
36 |
// engine-specific connection configuration |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
37 |
union { |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
38 |
const char *evpq; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
39 |
} engine_conf; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
40 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
41 |
// list of connections that are open |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
42 |
LIST_HEAD(evsql_conn_list, evsql_conn) conn_list; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
43 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
// list of queries running or waiting to run |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
45 |
TAILQ_HEAD(evsql_query_queue, evsql_query) query_queue; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
46 |
}; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
47 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
48 |
/* |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
49 |
* A single connection to the server. |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
50 |
* |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
51 |
* Contains the engine connection, may have a transaction associated, and may have a query associated. |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
52 |
*/ |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
53 |
struct evsql_conn { |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
54 |
// evsql we belong to |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
struct evsql *evsql; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
57 |
// engine-specific connection info |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
58 |
union { |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
59 |
struct evpq_conn *evpq; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
60 |
} engine; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
61 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
62 |
// our position in the conn list |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
63 |
LIST_ENTRY(evsql_conn) entry; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
64 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
65 |
// are we running a transaction? |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
struct evsql_trans *trans; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
67 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
// are we running a transactionless query? |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
struct evsql_query *query; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
70 |
}; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
71 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
72 |
/* |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
73 |
* A single transaction. |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
* |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
* Has a connection associated and possibly a query (which will also be associated with the connection) |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
*/ |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
struct evsql_trans { |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
// our evsql_conn/evsql |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
struct evsql *evsql; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
struct evsql_conn *conn; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
// callbacks |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
83 |
evsql_trans_error_cb error_fn; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
84 |
evsql_trans_ready_cb ready_fn; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
evsql_trans_done_cb done_fn; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
86 |
void *cb_arg; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
87 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
88 |
// the transaction type |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
89 |
enum evsql_trans_type type; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
// has evsql_trans_commit be called? |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
92 |
int has_commit : 1; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
93 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
94 |
// our current query |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
struct evsql_query *query; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
97 |
}; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
98 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
99 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
100 |
* Backend result handle |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
101 |
*/ |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
102 |
union evsql_result_handle { |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
103 |
PGresult *pq; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
104 |
}; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
105 |
|
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
106 |
/* |
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
107 |
* A single query. |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
108 |
* |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
109 |
* Has the info needed to exec the query (as these may be queued), and the callback/result info. |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
110 |
*/ |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
111 |
struct evsql_query { |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
112 |
// the actual SQL query, this may or may not be ours, see _evsql_query_exec |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
113 |
char *command; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
114 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
115 |
// possible query params |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
116 |
struct evsql_query_params_pq { |
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
117 |
int count; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
118 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
119 |
Oid *types; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
120 |
const char **values; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
121 |
int *lengths; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
122 |
int *formats; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
123 |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
124 |
// storage for numeric values |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
125 |
union evsql_item_value *item_vals; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
126 |
|
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
127 |
int result_format; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
128 |
} params; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
129 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
130 |
// our callback |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
131 |
evsql_query_cb cb_fn; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
132 |
void *cb_arg; |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
133 |
|
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
134 |
// the result we get |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
135 |
union evsql_result_handle result; |
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
136 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
137 |
// our position in the query list |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
138 |
TAILQ_ENTRY(evsql_query) entry; |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
139 |
}; |
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
140 |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
141 |
// the result |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
142 |
struct evsql_result { |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
143 |
struct evsql *evsql; |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
144 |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
145 |
// possible error code |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
146 |
int error; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
147 |
|
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
148 |
// the actual result |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
149 |
union evsql_result_handle result; |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
150 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
151 |
// result_* state |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
152 |
struct evsql_result_info *info; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
153 |
size_t row_offset; |
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
154 |
}; |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
155 |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
156 |
|
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
157 |
// maximum length for a 'BEGIN TRANSACTION ...' query |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
158 |
#define EVSQL_QUERY_BEGIN_BUF 512 |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
159 |
|
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
160 |
// the should the OID of some valid psql type... *ANY* valid psql type, doesn't matter, only used for NULLs |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
161 |
// 16 = bool in 8.3 |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
162 |
#define EVSQL_PQ_ARBITRARY_TYPE_OID 16 |
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
163 |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
164 |
/* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
165 |
* Core query-submission interface. |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
166 |
* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
167 |
* This performs some error-checking on the trans, allocates the evsql_query and does some basic initialization. |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
168 |
* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
169 |
* This does not actually enqueue the query anywhere, no reference is stored anywhere. |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
170 |
* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
171 |
* Returns the new evsql_query on success, NULL on failure. |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
172 |
*/ |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
173 |
struct evsql_query *_evsql_query_new (struct evsql *evsql, struct evsql_trans *trans, evsql_query_cb query_fn, void *cb_arg); |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
174 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
175 |
/* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
176 |
* Begin processing the given query, which should now be fully filled out. |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
177 |
* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
178 |
* If trans is given, it MUST be idle, and the query will be executed. Otherwise, it will either be executed directly |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
179 |
* or enqueued for future execution. |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
180 |
* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
181 |
* Returns zero on success, nonzero on failure. |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
182 |
*/ |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
183 |
int _evsql_query_enqueue (struct evsql *evsql, struct evsql_trans *trans, struct evsql_query *query, const char *command); |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
184 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
185 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
186 |
* Free the query and related resources, doesn't trigger any callbacks or remove from any queues. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
187 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
188 |
* The command should already be taken care of (NULL). |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
189 |
*/ |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
190 |
void _evsql_query_free (struct evsql_query *query); |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
40
diff
changeset
|
191 |
|
56
9dfc861273e5
strip dbfs code away, and wrangle the code a bit
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
192 |
#endif /* EVSQL_INTERNAL_H */ |