wrong character in the GSM 03.38 table (ç for Ç)
[gammu.git] / smsd / services / sql-core.h
blob204c7ad95d62161fe4bc6f584d184444a9d2f40f
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_BUG /* Internal error */
90 } SQL_Error;
92 /* types passed to NamedQuery */
93 typedef enum {
94 SQL_TYPE_NONE, /* used at end of array */
95 SQL_TYPE_INT, /* argument is type int */
96 SQL_TYPE_STRING /* argument is pointer to char */
97 } SQL_Type;
99 /* NamedQuery SQL parameter value as part of SQL_Var */
100 typedef union {
101 const char *s;
102 int i;
103 } SQL_Val;
105 /* NamedQuery SQL parameter passed by caller function */
106 typedef struct {
107 SQL_Type type;
108 SQL_Val v;
109 } SQL_Var;
111 /* configurable queries
112 * NOTE: parameter sequence in select queries are mandatory !!!
114 enum {
115 SQL_QUERY_DELETE_PHONE, /* after-initialization phone deleting */
116 SQL_QUERY_INSERT_PHONE, /* insert phone */
117 SQL_QUERY_SAVE_INBOX_SMS_SELECT,
118 SQL_QUERY_SAVE_INBOX_SMS_UPDATE_DELIVERED,
119 SQL_QUERY_SAVE_INBOX_SMS_UPDATE,
120 SQL_QUERY_SAVE_INBOX_SMS_INSERT,
121 SQL_QUERY_UPDATE_RECEIVED,
122 SQL_QUERY_REFRESH_SEND_STATUS,
123 SQL_QUERY_FIND_OUTBOX_SMS_ID,
124 SQL_QUERY_FIND_OUTBOX_BODY,
125 SQL_QUERY_FIND_OUTBOX_MULTIPART,
126 SQL_QUERY_DELETE_OUTBOX,
127 SQL_QUERY_DELETE_OUTBOX_MULTIPART,
128 SQL_QUERY_CREATE_OUTBOX,
129 SQL_QUERY_CREATE_OUTBOX_MULTIPART,
130 SQL_QUERY_ADD_SENT_INFO,
131 SQL_QUERY_UPDATE_SENT,
132 SQL_QUERY_REFRESH_PHONE_STATUS,
133 SQL_QUERY_LAST_NO
136 /* incomplete declaration - cyclic occurence of GSM_SMSDConfig */
137 struct GSM_SMSDConfig;
140 struct GSM_SMSDdbobj {
141 SQL_Error (* Connect)(GSM_SMSDConfig *);
142 SQL_Error (* Query)(GSM_SMSDConfig *, const char *, SQL_result *);
143 void (* Free)(GSM_SMSDConfig *); /* = close() */
144 void (* FreeResult)(GSM_SMSDConfig *, SQL_result *);
145 int (* NextRow)(GSM_SMSDConfig *, SQL_result *);
146 unsigned long long (* SeqID)(GSM_SMSDConfig *, const char *);
147 unsigned long (* AffectedRows)(GSM_SMSDConfig *, SQL_result *);
148 const char * (* GetString)(GSM_SMSDConfig *, SQL_result *, unsigned int);
149 long long (* GetNumber)(GSM_SMSDConfig *, SQL_result *, unsigned int);
150 time_t (* GetDate)(GSM_SMSDConfig *, SQL_result *, unsigned int);
151 gboolean (* GetBool)(GSM_SMSDConfig *, SQL_result *, unsigned int);
152 char * (* QuoteString)(GSM_SMSDConfig *, const char *);
155 /* database backends */
156 #ifdef HAVE_POSTGRESQL_LIBPQ_FE_H
157 extern struct GSM_SMSDdbobj SMSDPgSQL;
158 #endif
160 #ifdef HAVE_MYSQL_MYSQL_H
161 extern struct GSM_SMSDdbobj SMSDMySQL;
162 #endif
164 #ifdef LIBDBI_FOUND
165 extern struct GSM_SMSDdbobj SMSDDBI;
166 #endif
168 #ifdef ODBC_FOUND
169 extern struct GSM_SMSDdbobj SMSDODBC;
170 #endif
171 #endif
173 /* How should editor hadle tabs in this file? Add editor commands here.
174 * vim: noexpandtab sw=8 ts=8 sts=8: