1 /*
2  * Copyright (C) 2002,2003,2005 Dizzy
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18 
19 #ifndef INCLUDED_SQL_COMMON_TYPES
20 #define INCLUDED_SQL_COMMON_TYPES
21 
22 typedef unsigned int t_sql_info;
23 
24 /* used as a pointer to it */
25 #define t_sql_res void
26 
27 typedef char * t_sql_row;
28 
29 typedef char * t_sql_field;
30 
31 typedef struct {
32     char quote;	/* quote character for column names, depending on backend */
33     int (*init)(const char *host, const char *port, const char *socket, const char *name, const char *user, const char *pass);
34     int (*close)(void);
35     t_sql_res * (*query_res)(const char *);
36     int (*query)(const char *);
37     t_sql_row * (*fetch_row)(t_sql_res *);
38     void (*free_result)(t_sql_res *);
39     unsigned int (*num_rows)(t_sql_res *);
40     unsigned int (*num_fields)(t_sql_res *);
41     unsigned int (*affected_rows)(void);
42     t_sql_field * (*fetch_fields)(t_sql_res *);
43     int (*free_fields)(t_sql_field *);
44     void (*escape_string)(char *, const char *, int);
45 } t_sql_engine;
46 
47 #endif /* INCLUDED_SQL_COMMON_TYPES */
48 
49 #ifndef JUST_NEED_TYPES
50 #ifndef INCLUDED_SQL_COMMON_PROTOS
51 #define INCLUDED_SQL_COMMON_PROTOS
52 
53 #include "storage.h"
54 
55 extern t_storage storage_sql;
56 
57 #ifdef SQL_INTERNAL
58 
59 #define CURRENT_DB_VERSION 150
60 
61 #define DB_MAX_ATTRKEY	128
62 #define DB_MAX_ATTRVAL  180
63 #define DB_MAX_TAB	64
64 
65 #define SQL_UID_FIELD		"uid"
66 #define STORAGE_SQL_DEFAULT_UID	0
67 #define SQL_DEFAULT_PREFIX	""
68 
69 #define SQL_ON_DEMAND	1
70 
71 extern t_sql_engine *sql;
72 extern unsigned int sql_defacct;
73 extern const char* tab_prefix;
74 
75 #ifndef SQL_ON_DEMAND
76 extern char *sql_tables[];
77 #endif /* SQL_ON_DEMAND */
78 
79 extern int sql_init(const char *);
80 extern int sql_close(void);
81 extern unsigned sql_read_maxuserid(void);
82 extern int sql_read_accounts(int flag,t_read_accounts_func cb, void *data);
83 extern int sql_cmp_info(t_storage_info * info1, t_storage_info * info2);
84 extern int sql_free_info(t_storage_info * info);
85 extern t_storage_info *sql_get_defacct(void);
86 extern int sql_load_clans(t_load_clans_func cb);
87 extern int sql_write_clan(void *data);
88 extern int sql_remove_clan(int clantag);
89 extern int sql_remove_clanmember(int uid);
90 extern int sql_load_teams(t_load_teams_func cb);
91 extern int sql_write_team(void *data);
92 extern int sql_remove_team(unsigned int teamid);
93 
94 #endif /* SQL_INTERNAL */
95 
96 #endif /* INCLUDED_SQL_COMMON_PROTOS */
97 #endif /* JUST_NEED_TYPES */
98