author | Tero Marttila <terom@fixme.fi> |
Sat, 29 Nov 2008 01:50:32 +0200 | |
branch | new-evsql |
changeset 50 | 881de320e483 |
parent 48 | 8b019d191353 |
child 51 | c65d0f4c3bff |
permissions | -rw-r--r-- |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
#ifndef EVSQL_H |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
#define EVSQL_H |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
/* |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
* An event-based (Postgre)SQL client API using libevent |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
*/ |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
|
28
e944453ca924
split off dbfs components into a separate dir, improve dirop docs, error handling, etc
Tero Marttila <terom@fixme.fi>
parents:
27
diff
changeset
|
8 |
#include <stdint.h> |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
#include <event2/event.h> |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
11 |
#include "lib/err.h" |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
12 |
|
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
/* |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
* The generic context handle |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
*/ |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
struct evsql; |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
/* |
43 | 19 |
* Transaction handle |
20 |
*/ |
|
21 |
struct evsql_trans; |
|
22 |
||
23 |
/* |
|
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
24 |
* A query handle |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
*/ |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
struct evsql_query; |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
/* |
43 | 29 |
* A result handle |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
30 |
*/ |
43 | 31 |
struct evsql_result; |
32 |
||
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
33 |
|
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
34 |
/* |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
35 |
* Transaction type |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
36 |
*/ |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
37 |
enum evsql_trans_type { |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
38 |
EVSQL_TRANS_DEFAULT, |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
39 |
EVSQL_TRANS_SERIALIZABLE, |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
40 |
EVSQL_TRANS_REPEATABLE_READ, |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
41 |
EVSQL_TRANS_READ_COMMITTED, |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
42 |
EVSQL_TRANS_READ_UNCOMMITTED, |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
43 |
}; |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
44 |
|
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
45 |
/* |
43 | 46 |
* Parameters and Result fields are both items |
24 | 47 |
*/ |
43 | 48 |
enum evsql_item_format { |
24 | 49 |
EVSQL_FMT_TEXT, |
50 |
EVSQL_FMT_BINARY, |
|
51 |
}; |
|
52 |
||
43 | 53 |
enum evsql_item_type { |
54 |
EVSQL_TYPE_INVALID, |
|
24 | 55 |
|
43 | 56 |
EVSQL_TYPE_NULL_, |
31 | 57 |
|
43 | 58 |
EVSQL_TYPE_BINARY, |
59 |
EVSQL_TYPE_STRING, |
|
60 |
EVSQL_TYPE_UINT16, |
|
61 |
EVSQL_TYPE_UINT32, |
|
62 |
EVSQL_TYPE_UINT64, |
|
63 |
}; |
|
64 |
||
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
65 |
struct evsql_item_binary { |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
66 |
const char *ptr; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
67 |
size_t len; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
68 |
}; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
69 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
70 |
/* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
71 |
* Metadata about the type of an item |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
72 |
*/ |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
73 |
struct evsql_item_info { |
43 | 74 |
// format |
75 |
enum evsql_item_format format; |
|
76 |
||
77 |
// type |
|
78 |
enum evsql_item_type type; |
|
79 |
||
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
80 |
// flags |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
81 |
struct evsql_item_flags { |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
82 |
uint8_t null_ok : 1; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
83 |
} flags; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
84 |
}; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
85 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
86 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
87 |
* Storage for various scalar values |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
88 |
*/ |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
89 |
union evsql_item_value { |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
90 |
uint16_t uint16; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
91 |
uint32_t uint32; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
92 |
uint64_t uint64; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
93 |
}; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
94 |
|
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
95 |
/* |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
96 |
* The type and value of an item |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
97 |
*/ |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
98 |
struct evsql_item { |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
99 |
// "header" |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
100 |
struct evsql_item_info info; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
101 |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
102 |
// pointer to the raw databytes. Set to NULL to indicate SQL-NULL, &value, or an external buf |
43 | 103 |
const char *bytes; |
104 |
||
105 |
// size of byte array pointed to by bytes, zero for text |
|
106 |
size_t length; |
|
107 |
||
108 |
// the decoded value |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
109 |
union evsql_item_value value; |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
110 |
|
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
111 |
// (internal) flags |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
112 |
struct { |
48
8b019d191353
update dbfs code to work with new evsql
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
113 |
uint8_t has_value : 1; |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
114 |
} flags; |
24 | 115 |
}; |
116 |
||
117 |
/* |
|
43 | 118 |
* Query info, similar to prepared statements |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
119 |
* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
120 |
* Contains the literal SQL query and the types of the arguments |
23
1dee73ae4ad0
evsql_query_params compiles...
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
121 |
*/ |
43 | 122 |
struct evsql_query_info { |
123 |
// the SQL query itself |
|
124 |
const char *sql; |
|
23
1dee73ae4ad0
evsql_query_params compiles...
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
125 |
|
43 | 126 |
// the list of items |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
127 |
struct evsql_item_info params[]; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
128 |
}; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
129 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
130 |
/* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
131 |
* Contains the query parameter types and their values |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
132 |
*/ |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
133 |
struct evsql_query_params { |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
134 |
// result format |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
135 |
enum evsql_item_format result_format; |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
136 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
137 |
// list of params |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
138 |
struct evsql_item list[]; |
23
1dee73ae4ad0
evsql_query_params compiles...
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
139 |
}; |
1dee73ae4ad0
evsql_query_params compiles...
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
140 |
|
43 | 141 |
/* |
142 |
* Result info |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
143 |
* |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
144 |
* Contains the types of the result columns |
43 | 145 |
*/ |
146 |
struct evsql_result_info { |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
147 |
// XXX: put something useful here? |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
148 |
int _unused; |
43 | 149 |
|
150 |
// the list of fields |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
151 |
struct evsql_item_info columns[]; |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
152 |
}; |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
153 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
154 |
/* |
48
8b019d191353
update dbfs code to work with new evsql
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
155 |
* Macros for defining param/result infos/lists |
8b019d191353
update dbfs code to work with new evsql
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
156 |
*/ |
8b019d191353
update dbfs code to work with new evsql
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
157 |
#define EVSQL_PARAMS(result_fmt) { result_fmt, |
50 | 158 |
#define EVSQL_PARAM(typenam) { EVSQL_TYPE(typenam) } |
159 |
#define EVSQL_PARAMS_END { EVSQL_TYPE_END } \ |
|
48
8b019d191353
update dbfs code to work with new evsql
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
160 |
} // <<< |
8b019d191353
update dbfs code to work with new evsql
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
161 |
|
50 | 162 |
#define EVSQL_TYPE(typenam) { EVSQL_FMT_BINARY, EVSQL_TYPE_ ## typenam } |
163 |
#define EVSQL_TYPE_END { EVSQL_FMT_BINARY, EVSQL_TYPE_INVALID } |
|
164 |
||
48
8b019d191353
update dbfs code to work with new evsql
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
165 |
|
8b019d191353
update dbfs code to work with new evsql
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
166 |
/* |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
167 |
* Callback for handling query results. |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
168 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
169 |
* The query has completed, either succesfully or unsuccesfully. |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
170 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
171 |
* Use the evsql_result_* functions to manipulate the results, and call evsql_result_free (or equivalent) once done. |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
172 |
*/ |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
173 |
typedef void (*evsql_query_cb)(struct evsql_result *res, void *arg); |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
174 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
175 |
/* |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
176 |
* Callback for handling global-level errors. |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
177 |
* |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
178 |
* The evsql is not useable anymore. |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
179 |
* |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
180 |
* XXX: this is not actually called yet, no retry logic implemented. |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
181 |
*/ |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
182 |
typedef void (*evsql_error_cb)(struct evsql *evsql, void *arg); |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
183 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
184 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
185 |
* Callback for handling transaction-level errors. This may be called at any time during a transaction's lifetime, |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
186 |
* including from within the evsql_query_* functions. |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
187 |
* |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
188 |
* The transaction is not useable anymore. |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
189 |
*/ |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
190 |
typedef void (*evsql_trans_error_cb)(struct evsql_trans *trans, void *arg); |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
191 |
|
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
192 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
193 |
* Callback for handling evsql_trans/evsql_query_abort completion. The transaction is ready for use with evsql_query_*. |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
194 |
*/ |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
195 |
typedef void (*evsql_trans_ready_cb)(struct evsql_trans *trans, void *arg); |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
196 |
|
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
197 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
198 |
* Callback for handling evsql_trans_commit completion. The transaction was commited, and should not be used anymore. |
26
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
199 |
*/ |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
200 |
typedef void (*evsql_trans_done_cb)(struct evsql_trans *trans, void *arg); |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
201 |
|
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
202 |
/* |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
203 |
* Create a new PostgreSQL/libpq(evpq) -based evsql using the given conninfo. |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
204 |
* |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
205 |
* The given conninfo must stay valid for the duration of the evsql's lifetime. |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
206 |
*/ |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
207 |
struct evsql *evsql_new_pq (struct event_base *ev_base, const char *pq_conninfo, |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
208 |
evsql_error_cb error_fn, |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
209 |
void *cb_arg |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
210 |
); |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
211 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
212 |
/* |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
213 |
* Create a new transaction. |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
214 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
215 |
* A transaction will be allocated its own connection, and the "BEGIN TRANSACTION ..." query will be sent (use the |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
216 |
* evsql_trans_type argument to specify this). |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
217 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
218 |
* Once the transaction has been opened, the given evsql_trans_ready_cb will be triggered, and the transaction can then |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
219 |
* be used (see evsql_query_*). |
26
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
220 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
221 |
* If, at any point, the transaction-connection fails, and pending query will be forgotten (i.e. the query callback |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
222 |
* will NOT be called), and the given evsql_trans_error_cb will be called. Note that this includes some, but not all, |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
223 |
* cases where evsql_query_* returns an error. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
224 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
225 |
* Once you are done with the transaction, call either evsql_trans_commit or evsql_trans_abort. |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
226 |
*/ |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
227 |
struct evsql_trans *evsql_trans (struct evsql *evsql, enum evsql_trans_type type, |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
228 |
evsql_trans_error_cb error_fn, |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
229 |
evsql_trans_ready_cb ready_fn, |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
230 |
evsql_trans_done_cb done_fn, |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
231 |
void *cb_arg |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
232 |
); |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
233 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
234 |
/* |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
235 |
* Queue the given query for execution. |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
236 |
* |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
237 |
* If trans is specified (not NULL), then the transaction must be idle, and the query will be executed in that |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
238 |
* transaction's context. Otherwise, the query will be executed without a transaction using an idle connection, or |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
239 |
* enqueued for later execution. |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
240 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
241 |
* Once the query is complete (got a result, got an error, the connection failed), then the query_cb will be called. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
242 |
* The callback can used the evsql_result_* functions to manipulate it. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
243 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
244 |
* The returned evsql_query handle can be passed to evsql_query_abort at any point before query_fn being called. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
245 |
* |
23
1dee73ae4ad0
evsql_query_params compiles...
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
246 |
*/ |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
247 |
struct evsql_query *evsql_query (struct evsql *evsql, struct evsql_trans *trans, const char *command, evsql_query_cb query_fn, void *cb_arg); |
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
248 |
|
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
249 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
250 |
* Execute the given SQL query using the list of parameter types/values given via evsql_query_params. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
251 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
252 |
* See evsql_query for more info about behaviour. |
25
99a41f48e29b
evsql transactions, it compiles...
Tero Marttila <terom@fixme.fi>
parents:
24
diff
changeset
|
253 |
*/ |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
254 |
struct evsql_query *evsql_query_params (struct evsql *evsql, struct evsql_trans *trans, |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
255 |
const char *command, const struct evsql_query_params *params, |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
256 |
evsql_query_cb query_fn, void *cb_arg |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
257 |
); |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
258 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
259 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
260 |
* Execute the given query_info's SQL query using the values given as variable arguments, using the evsql_query_info to |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
261 |
* resolve the types. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
262 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
263 |
* See evsql_query for more info about behaviour. |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
264 |
*/ |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
265 |
struct evsql_query *evsql_query_exec (struct evsql *evsql, struct evsql_trans *trans, |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
266 |
const struct evsql_query_info *query_info, |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
267 |
evsql_query_cb query_fn, void *cb_arg, |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
268 |
... |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
269 |
); |
24 | 270 |
|
271 |
/* |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
272 |
* Abort a query returned by evsql_query_* that has not yet completed (query_fn has not been called yet). |
27 | 273 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
274 |
* The actual query itself may or may not be aborted (and hence may or may not be executed on the server), but query_fn |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
275 |
* will not be called anymore, and the query will dispose of itself and any results returned. |
27 | 276 |
* |
277 |
* If the query is part of a transaction, then trans must be given, and the query must be the query that is currently |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
278 |
* executing on that trans. The transaction's ready_fn will be called once the query has been aborted and the |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
279 |
* transaction is now idle again. |
27 | 280 |
*/ |
281 |
void evsql_query_abort (struct evsql_trans *trans, struct evsql_query *query); |
|
282 |
||
283 |
/* |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
284 |
* Commit a transaction using "COMMIT TRANSACTION". |
27 | 285 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
286 |
* The transaction must be idle, just like for evsql_query. Once the transaction has been commited, the transaction's |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
287 |
* done_fn will be called, after which the transaction must not be used. |
28
e944453ca924
split off dbfs components into a separate dir, improve dirop docs, error handling, etc
Tero Marttila <terom@fixme.fi>
parents:
27
diff
changeset
|
288 |
* |
27 | 289 |
* You cannot abort a COMMIT, calling trans_abort on trans after a succesful trans_commit is a FATAL error. |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
290 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
291 |
* Note that done_fn will never be called directly, always indirectly via the event loop. |
26
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
292 |
*/ |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
293 |
int evsql_trans_commit (struct evsql_trans *trans); |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
294 |
|
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
295 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
296 |
* Abort a transaction, using "ROLLBACK TRANSACTION". |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
297 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
298 |
* No more transaction callbacks will be called, if there was a query running, it will be aborted, and the transaction |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
299 |
* then rollback'd. |
27 | 300 |
* |
301 |
* You cannot abort a COMMIT, calling trans_abort on trans after a succesful trans_commit is a FATAL error. |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
302 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
303 |
* Do not call evsql_trans_abort from within evsql_trans_error_cb! |
26
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
304 |
*/ |
27 | 305 |
void evsql_trans_abort (struct evsql_trans *trans); |
26
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
306 |
|
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
307 |
/* |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
308 |
* Transaction-handling functions |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
309 |
*/ |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
310 |
|
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
311 |
// error string, meant to be called from evsql_trans_error_cb |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
312 |
const char *evsql_trans_error (struct evsql_trans *trans); |
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
313 |
|
61668c57f4bb
preliminary *dir implementation
Tero Marttila <terom@fixme.fi>
parents:
25
diff
changeset
|
314 |
/* |
24 | 315 |
* Param-building functions |
316 |
*/ |
|
31 | 317 |
int evsql_param_binary (struct evsql_query_params *params, size_t param, const char *ptr, size_t len); |
24 | 318 |
int evsql_param_string (struct evsql_query_params *params, size_t param, const char *ptr); |
31 | 319 |
int evsql_param_uint16 (struct evsql_query_params *params, size_t param, uint16_t uval); |
24 | 320 |
int evsql_param_uint32 (struct evsql_query_params *params, size_t param, uint32_t uval); |
38
1fd4da071575
rework/hack parent to be a FOREIGN KEY (add a dir_ino col), implement dbfs_link
Tero Marttila <terom@fixme.fi>
parents:
34
diff
changeset
|
321 |
int evsql_param_null (struct evsql_query_params *params, size_t param); |
31 | 322 |
int evsql_params_clear (struct evsql_query_params *params); |
323 |
||
324 |
/* |
|
325 |
* Query-handling functions |
|
326 |
*/ |
|
327 |
||
328 |
// print out a textual repr of the given query/params via DEBUG |
|
329 |
void evsql_query_debug (const char *sql, const struct evsql_query_params *params); |
|
24 | 330 |
|
331 |
/* |
|
332 |
* Result-handling functions |
|
333 |
*/ |
|
334 |
||
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
335 |
/* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
336 |
* Check the result for errors. Intended for use with non-data queries, i.e. CREATE, etc. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
337 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
338 |
* Returns zero if the query was OK, err otherwise. EIO indicates an SQL error, the error message can be retrived |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
339 |
* using evsql_result_error. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
340 |
*/ |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
341 |
err_t evsql_result_check (struct evsql_result *res); |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
342 |
|
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
343 |
/* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
344 |
* The iterator-based interface results interface. |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
345 |
* |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
346 |
* Define an evsql_result_info struct that describes the columns returned by the query, and call evsql_result_begin on |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
347 |
* the evsql_result. This verifies the query result, and then prepares it for iteration using evsql_result_next. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
348 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
349 |
* Call evsql_result_end once you've stopped iteration. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
350 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
351 |
* Returns zero if the evsql_result is ready for iteration, err otherwise. EIO indicates an SQL error, the error |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
352 |
* message can be retreived using evsql_result_error. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
353 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
354 |
* Note: currently the iterator state is simply stored in evsql_result, so only one iterator at a time per evsql_result. |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
355 |
*/ |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
356 |
err_t evsql_result_begin (struct evsql_result_info *info, struct evsql_result *res); |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
357 |
|
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
358 |
/* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
359 |
* Reads the next result row, storing the field values into the pointer arguments given. The types are resolved using |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
360 |
* the evsql_result_info given to evsql_result_begin. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
361 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
362 |
* Returns >0 when a row was read, 0 when there are no more rows, and -err if there was an error. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
363 |
*/ |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
364 |
int evsql_result_next (struct evsql_result *res, ...); |
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
365 |
|
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
366 |
/* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
367 |
* Ends the result iteration, releasing any associated resources and the result itself. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
368 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
369 |
* The result should not be iterated or accessed anymore. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
370 |
* |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
371 |
* Note: this does the same thing as evsql_result_free, and works regardless of evsql_result_begin returning |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
372 |
* succesfully or not. |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
373 |
*/ |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
374 |
void evsql_result_end (struct evsql_result *res); |
24 | 375 |
|
45
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
376 |
|
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
377 |
// get error message associated with function |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
378 |
const char *evsql_result_error (const struct evsql_result *res); |
424ce5ab82fd
compiles + some basic evsql_test
Tero Marttila <terom@fixme.fi>
parents:
44
diff
changeset
|
379 |
|
24 | 380 |
// number of rows in the result |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
381 |
size_t evsql_result_rows (const struct evsql_result *res); |
24 | 382 |
|
383 |
// number of columns in the result |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
384 |
size_t evsql_result_cols (const struct evsql_result *res); |
24 | 385 |
|
34
460f995d3769
fix readdir to use ORDER BY, rename
Tero Marttila <terom@fixme.fi>
parents:
31
diff
changeset
|
386 |
// number of affected rows for UPDATE/INSERT |
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
387 |
size_t evsql_result_affected (const struct evsql_result *res); |
34
460f995d3769
fix readdir to use ORDER BY, rename
Tero Marttila <terom@fixme.fi>
parents:
31
diff
changeset
|
388 |
|
24 | 389 |
// fetch the raw binary value from a result set, and return it via ptr |
390 |
// if size is nonzero, check that the size of the field data matches |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
391 |
int evsql_result_binary (const struct evsql_result *res, size_t row, size_t col, const char **ptr, size_t *size, int nullok); |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
392 |
int evsql_result_string (const struct evsql_result *res, size_t row, size_t col, const char **ptr, int nullok); |
24 | 393 |
|
394 |
// fetch certain kinds of values from a binary result set |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
395 |
int evsql_result_uint16 (const struct evsql_result *res, size_t row, size_t col, uint16_t *uval, int nullok); |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
396 |
int evsql_result_uint32 (const struct evsql_result *res, size_t row, size_t col, uint32_t *uval, int nullok); |
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
397 |
int evsql_result_uint64 (const struct evsql_result *res, size_t row, size_t col, uint64_t *uval, int nullok); |
24 | 398 |
|
399 |
// release the result set, freeing its memory |
|
44
9e76ee9729b6
more work on the new evsql interface
Tero Marttila <terom@fixme.fi>
parents:
43
diff
changeset
|
400 |
void evsql_result_free (struct evsql_result *res); |
24 | 401 |
|
23
1dee73ae4ad0
evsql_query_params compiles...
Tero Marttila <terom@fixme.fi>
parents:
21
diff
changeset
|
402 |
/* |
21
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
403 |
* Close a connection. Callbacks for waiting queries will not be run. |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
404 |
* |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
405 |
* XXX: not implemented yet. |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
406 |
*/ |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
407 |
void evsql_close (struct evsql *evsql); |
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
408 |
|
e5da1d428e3e
new evsql for queueing SQL queries
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
409 |
#endif /* EVSQL_H */ |