Translation update done using Pootle.
[gammu.git] / smsd / services / sql-core.h
blobd2551dc23a7351b9dd10bf1861e702974c6b3c14
1 /* drivers for sql service
3 * MySQL (C) 2004 by Marcin Wiacek
4 * PostgreSQL (C) 2006 by Andrea Riciputi
5 * DBI (C) 2009 by Michal Čihař
7 */
9 #ifndef __sql_core_h_
10 #define __sql_core_h_
12 #ifdef WIN32
13 # include <winsock2.h>
14 #endif
16 #ifdef HAVE_MYSQL_MYSQL_H
17 #include <mysql.h>
18 #include <mysqld_error.h>
19 #endif
21 #ifdef HAVE_POSTGRESQL_LIBPQ_FE_H
22 # include <libpq-fe.h>
23 #endif
25 #ifdef LIBDBI_FOUND
26 #include <dbi/dbi.h>
27 #endif
29 #ifdef HAVE_SHM
30 #include <sys/types.h>
31 #endif
33 #ifdef ODBC_FOUND
34 #include <sql.h>
35 #include <sqlext.h>
36 #endif
38 /* sql result structures */
39 typedef union {
40 #ifdef LIBDBI_FOUND
41 dbi_result dbi;
42 #endif
43 #ifdef HAVE_MYSQL_MYSQL_H
44 struct __mysql {
45 MYSQL_RES *res;
46 MYSQL_ROW row; /* keep in memory actual row */
47 MYSQL * con;
48 } my;
49 #endif
50 #ifdef HAVE_POSTGRESQL_LIBPQ_FE_H
51 struct __pg {
52 PGresult *res;
53 int iter; /* libpq does not have nexrow .. */
54 } pg;
55 #endif
56 #ifdef ODBC_FOUND
57 SQLHSTMT odbc; /* Statement being executed */
58 #endif
59 } SQL_result;
61 #define SMSD_ODBC_MAX_RETURN_STRINGS 30
63 /* sql connection structures */
64 typedef union __sql_conn {
65 #ifdef LIBDBI_FOUND
66 dbi_conn dbi; /* dbi driver */
67 #endif
68 #ifdef HAVE_MYSQL_MYSQL_H
69 MYSQL *my; /* mysql driver */
70 #endif
71 #ifdef HAVE_POSTGRESQL_LIBPQ_FE_H
72 PGconn *pg; /* pgsql driver */
73 #endif
74 #ifdef ODBC_FOUND
75 struct {
76 SQLHENV env; /* Environment */
77 SQLHDBC dbc; /* DBC */
78 char * retstr[SMSD_ODBC_MAX_RETURN_STRINGS]; /* Retrun strings */
79 } odbc;
80 #endif
81 } SQL_conn;
83 /* SQL errors */
84 typedef enum {
85 SQL_OK, /* all ok */
86 SQL_TIMEOUT, /* query or connection timeout */
87 SQL_FAIL, /* query failed */
88 SQL_LOCKED /* locked table - currently unused */
89 } SQL_Error;
91 /* types passed to NamedQuery */
92 typedef enum {
93 SQL_TYPE_NONE, /* used at end of array */
94 SQL_TYPE_INT, /* argument is type int */
95 SQL_TYPE_STRING /* argument is pointer to char */
96 } SQL_Type;
98 /* NamedQuery SQL parameter value as part of SQL_Var */
99 typedef union {
100 const char *s;
101 int i;
102 } SQL_Val;
104 /* NamedQuery SQL parameter passed by caller function */
105 typedef struct {
106 SQL_Type type;
107 SQL_Val v;
108 } SQL_Var;
110 /* configurable queries
111 * NOTE: parameter sequence in select queries are mandatory !!!
113 enum {
114 SQL_QUERY_DELETE_PHONE, /* after-initialization phone deleting */
115 SQL_QUERY_INSERT_PHONE, /* insert phone */
116 SQL_QUERY_SAVE_INBOX_SMS_SELECT,
117 SQL_QUERY_SAVE_INBOX_SMS_UPDATE_DELIVERED,
118 SQL_QUERY_SAVE_INBOX_SMS_UPDATE,
119 SQL_QUERY_SAVE_INBOX_SMS_INSERT,
120 SQL_QUERY_UPDATE_RECEIVED,
121 SQL_QUERY_REFRESH_SEND_STATUS,
122 SQL_QUERY_FIND_OUTBOX_SMS_ID,
123 SQL_QUERY_FIND_OUTBOX_BODY,
124 SQL_QUERY_FIND_OUTBOX_MULTIPART,
125 SQL_QUERY_DELETE_OUTBOX,
126 SQL_QUERY_DELETE_OUTBOX_MULTIPART,
127 SQL_QUERY_CREATE_OUTBOX,
128 SQL_QUERY_CREATE_OUTBOX_MULTIPART,
129 SQL_QUERY_ADD_SENT_INFO,
130 SQL_QUERY_UPDATE_SENT,
131 SQL_QUERY_REFRESH_PHONE_STATUS,
132 SQL_QUERY_LAST_NO
135 /* incomplete declaration - cyclic occurence of GSM_SMSDConfig */
136 struct GSM_SMSDConfig;
139 struct GSM_SMSDdbobj {
140 SQL_Error (* Connect)(GSM_SMSDConfig *);
141 SQL_Error (* Query)(GSM_SMSDConfig *, const char *, SQL_result *);
142 void (* Free)(GSM_SMSDConfig *); /* = close() */
143 void (* FreeResult)(GSM_SMSDConfig *, SQL_result *);
144 int (* NextRow)(GSM_SMSDConfig *, SQL_result *);
145 unsigned long long (* SeqID)(GSM_SMSDConfig *, const char *);
146 unsigned long (* AffectedRows)(GSM_SMSDConfig *, SQL_result *);
147 const char * (* GetString)(GSM_SMSDConfig *, SQL_result *, unsigned int);
148 long long (* GetNumber)(GSM_SMSDConfig *, SQL_result *, unsigned int);
149 time_t (* GetDate)(GSM_SMSDConfig *, SQL_result *, unsigned int);
150 gboolean (* GetBool)(GSM_SMSDConfig *, SQL_result *, unsigned int);
151 char * (* QuoteString)(GSM_SMSDConfig *, const char *);
154 /* database backends */
155 #ifdef HAVE_POSTGRESQL_LIBPQ_FE_H
156 extern struct GSM_SMSDdbobj SMSDPgSQL;
157 #endif
159 #ifdef HAVE_MYSQL_MYSQL_H
160 extern struct GSM_SMSDdbobj SMSDMySQL;
161 #endif
163 #ifdef LIBDBI_FOUND
164 extern struct GSM_SMSDdbobj SMSDDBI;
165 #endif
167 #ifdef ODBC_FOUND
168 extern struct GSM_SMSDdbobj SMSDODBC;
169 #endif
170 #endif
172 /* How should editor hadle tabs in this file? Add editor commands here.
173 * vim: noexpandtab sw=8 ts=8 sts=8: