annotate src/lib-sql/sql-api-private.h @ 5496:72ee0521dfaf HEAD

Added sql_result_setup_fetch() which makes it easier to fetch rows into structures. Added sql_result_get_field_value_binary(), which is currently not implemented for MySQL.
author Timo Sirainen <tss@iki.fi>
date Tue, 03 Apr 2007 08:34:50 +0300
parents 3e196acd60b7
children e4eb71ae8e96
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 #ifndef __SQL_API_PRIVATE_H
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2 #define __SQL_API_PRIVATE_H
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "sql-api.h"
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 struct sql_db {
3736
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
7 const char *name;
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
8
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 struct sql_db *(*init)(const char *connect_string);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 void (*deinit)(struct sql_db *db);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11
3162
5d6787582410 Added sql_get_flags() function, currently returning only
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
12 enum sql_db_flags (*get_flags)(struct sql_db *db);
5d6787582410 Added sql_get_flags() function, currently returning only
Timo Sirainen <tss@iki.fi>
parents: 2754
diff changeset
13
3421
c624ffa9e6f0 Added sql_connect() to do explicit connecting. sql_init() no longer does.
Timo Sirainen <tss@iki.fi>
parents: 3162
diff changeset
14 int (*connect)(struct sql_db *db);
4458
3e196acd60b7 sql_escape_string() should return const char *, not char *.
Timo Sirainen <tss@iki.fi>
parents: 4451
diff changeset
15 const char *(*escape_string)(struct sql_db *db, const char *string);
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 void (*exec)(struct sql_db *db, const char *query);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 void (*query)(struct sql_db *db, const char *query,
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 sql_query_callback_t *callback, void *context);
3736
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
19 struct sql_result *(*query_s)(struct sql_db *db, const char *query);
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
20
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
21 struct sql_transaction_context *(*transaction_begin)(struct sql_db *db);
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
22 void (*transaction_commit)(struct sql_transaction_context *ctx,
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
23 sql_commit_callback_t *callback,
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
24 void *context);
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
25 int (*transaction_commit_s)(struct sql_transaction_context *ctx,
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
26 const char **error_r);
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
27 void (*transaction_rollback)(struct sql_transaction_context *ctx);
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
28
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
29 void (*update)(struct sql_transaction_context *ctx, const char *query);
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 };
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
5496
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
32 struct sql_result_vfuncs {
3736
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
33 void (*free)(struct sql_result *result);
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 int (*next_row)(struct sql_result *result);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 unsigned int (*get_fields_count)(struct sql_result *result);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 const char *(*get_field_name)(struct sql_result *result,
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 unsigned int idx);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 int (*find_field)(struct sql_result *result, const char *field_name);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 const char *(*get_field_value)(struct sql_result *result,
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 unsigned int idx);
5496
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
43 const unsigned char *
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
44 (*get_field_value_binary)(struct sql_result *result,
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
45 unsigned int idx,
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
46 size_t *size_r);
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 const char *(*find_field_value)(struct sql_result *result,
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 const char *field_name);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 const char *const *(*get_values)(struct sql_result *result);
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 const char *(*get_error)(struct sql_result *result);
5496
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
52 };
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
53
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
54 struct sql_field_map {
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
55 enum sql_field_type type;
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
56 size_t offset;
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
57 };
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
58
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
59 struct sql_result {
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
60 struct sql_result_vfuncs v;
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
61
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
62 struct sql_db *db;
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
63 const struct sql_field_def *fields;
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
64
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
65 unsigned int map_size;
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
66 struct sql_field_map *map;
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
67 void *fetch_dest;
72ee0521dfaf Added sql_result_setup_fetch() which makes it easier to fetch rows into
Timo Sirainen <tss@iki.fi>
parents: 4458
diff changeset
68 size_t fetch_dest_size;
3736
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
69
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
70 unsigned int callback:1;
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
71 };
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
72
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
73 struct sql_transaction_context {
3dd0ab18d8da Added support for transactions and synchronous SQL queries.
Timo Sirainen <tss@iki.fi>
parents: 3421
diff changeset
74 struct sql_db *db;
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 };
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4294
diff changeset
77 ARRAY_DEFINE_TYPE(sql_drivers, const struct sql_db *);
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4294
diff changeset
78
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4294
diff changeset
79 extern ARRAY_TYPE(sql_drivers) sql_drivers;
2754
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 extern struct sql_result sql_not_connected_result;
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81
3c3ac12be307 Created generic asynchronous SQL API and implemented MySQL and PostgreSQL
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 #endif