diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-07-10 15:16:05 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-07-12 11:50:07 +0300 |
commit | 8afb551c895d6870b0d4f427fa8205ae45ad0bf9 (patch) | |
tree | 6e208d7a54d2845035b366a906b35b390ccce96a /src/dbrw.h | |
download | vmod-dbrw-8afb551c895d6870b0d4f427fa8205ae45ad0bf9.tar.gz vmod-dbrw-8afb551c895d6870b0d4f427fa8205ae45ad0bf9.tar.bz2 |
Initial commit
Diffstat (limited to 'src/dbrw.h')
-rw-r--r-- | src/dbrw.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/dbrw.h b/src/dbrw.h new file mode 100644 index 0000000..beebc5e --- /dev/null +++ b/src/dbrw.h | |||
@@ -0,0 +1,70 @@ | |||
1 | #include <config.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include <errno.h> | ||
5 | #include <syslog.h> | ||
6 | |||
7 | struct dbrw_connection; | ||
8 | |||
9 | struct dbrw_backend { | ||
10 | char *name; | ||
11 | |||
12 | int (*sql_init) (struct dbrw_connection *); | ||
13 | void (*sql_destroy) (struct dbrw_connection *); | ||
14 | int (*sql_connect) (struct dbrw_connection *); | ||
15 | int (*sql_disconnect) (struct dbrw_connection *); | ||
16 | char *(*sql_escape) (struct dbrw_connection *, const char *); | ||
17 | int (*sql_query) (struct dbrw_connection *, const char *); | ||
18 | unsigned (*sql_num_tuples) (struct dbrw_connection *); | ||
19 | unsigned (*sql_num_fields) (struct dbrw_connection *); | ||
20 | int (*sql_free_result) (struct dbrw_connection *); | ||
21 | const char *(*sql_get_column)(struct dbrw_connection *, unsigned, | ||
22 | unsigned); | ||
23 | }; | ||
24 | |||
25 | enum { | ||
26 | state_init, | ||
27 | state_connected, | ||
28 | state_result, | ||
29 | state_error, | ||
30 | state_disabled | ||
31 | }; | ||
32 | |||
33 | struct dbrw_config { | ||
34 | int debug_level; | ||
35 | struct dbrw_backend *backend; | ||
36 | char **param; | ||
37 | char *query; | ||
38 | }; | ||
39 | |||
40 | struct dbrw_connection { | ||
41 | int state; | ||
42 | struct dbrw_config *conf; | ||
43 | void *data; | ||
44 | }; | ||
45 | |||
46 | void dbrw_debug(const char *fmt, ...); | ||
47 | void dbrw_error(const char *fmt, ...); | ||
48 | |||
49 | #define debug(c,n,a) do { if ((c)->debug_level>=(n)) dbrw_debug a; } while (0) | ||
50 | |||
51 | #ifdef USE_SQL_MYSQL | ||
52 | struct dbrw_backend mysql_backend; | ||
53 | #endif | ||
54 | #ifdef USE_SQL_PGSQL | ||
55 | struct dbrw_backend pgsql_backend; | ||
56 | #endif | ||
57 | |||
58 | char *findparam(char **params, char *name); | ||
59 | |||
60 | int sql_init(struct dbrw_connection *); | ||
61 | int sql_connect(struct dbrw_connection *pd); | ||
62 | void sql_disconnect(struct dbrw_connection *pd); | ||
63 | char *sql_escape(struct dbrw_connection *pd, const char *input); | ||
64 | int sql_query(struct dbrw_connection *pd, const char *input); | ||
65 | unsigned sql_num_tuples(struct dbrw_connection *pd); | ||
66 | unsigned sql_num_fields(struct dbrw_connection *pd); | ||
67 | void sql_free_result(struct dbrw_connection *pd); | ||
68 | void sql_destroy(struct dbrw_connection *pd); | ||
69 | const char *sql_get_column(struct dbrw_connection *pd, unsigned row, unsigned col); | ||
70 | |||