File: db.h

package info (click to toggle)
openser 1.1.0-9etch1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,828 kB
  • ctags: 11,809
  • sloc: ansic: 120,528; sh: 5,249; yacc: 1,716; makefile: 1,261; php: 656; perl: 205; sql: 190
file content (173 lines) | stat: -rw-r--r-- 4,802 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
 * $Id: db.h,v 1.2 2005/06/16 12:07:08 miconda Exp $
 *
 * Copyright (C) 2001-2003 FhG Fokus
 *
 * This file is part of ser, a free SIP server.
 *
 * ser is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version
 *
 * For a license to use the ser software under conditions
 * other than those described here, or to purchase support for this
 * software, please contact iptel.org by e-mail at the following addresses:
 *    info@iptel.org
 *
 * ser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
/*
 * History:
 * --------
 *  2004-06-06  removed db_* macros and global dbf (andrei)
 */


#ifndef DB_H
#define DB_H

#include "db_key.h"
#include "db_op.h"
#include "db_val.h"
#include "db_con.h"
#include "db_row.h"
#include "db_res.h"
#include "db_cap.h"


/*
 * Specify table name that will be used for
 * subsequent operations
 */
typedef int (*db_use_table_f)(db_con_t* _h, const char* _t);


/*
 * Initialize database connection and
 * obtain the connection handle
 */
typedef db_con_t* (*db_init_f) (const char* _sqlurl);


/*
 * Close a database connection and free
 * all memory used
 */
typedef void (*db_close_f) (db_con_t* _h); 


/*
 * Query table for specified rows
 * _h: structure representing database connection
 * _k: key names
 * _op: conditions
 * _v: values of the keys that must match
 * _c: column names to return
 * _n: nmber of key=values pairs to compare
 * _nc: number of columns to return
 * _o: order by the specified column
 * _r: Result will be stored in this variable
 *     NULL if there is no result
 */
typedef int (*db_query_f) (db_con_t* _h, db_key_t* _k, 
			   db_op_t* _op, db_val_t* _v, 
			   db_key_t* _c, int _n, int _nc,
			   db_key_t _o, db_res_t** _r);


/*
 * Raw SQL query, database specific !
 */
typedef int (*db_raw_query_f) (db_con_t* _h, char* _s, db_res_t** _r);


/*
 * Free a result allocated by db_query
 * _h: structure representing database connection
 * _r: db_res structure
 */
typedef int (*db_free_result_f) (db_con_t* _h, db_res_t* _r);


/*
 * Insert a row into specified table
 * _h: structure representing database connection
 * _k: key names
 * _v: values of the keys
 * _n: number of key=value pairs
 */
typedef int (*db_insert_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);


/*
 * Delete a row from the specified table
 * _h: structure representing database connection
 * _k: key names
 * _o: operators
 * _v: values of the keys that must match
 * _n: number of key=value pairs
 */
typedef int (*db_delete_f) (db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n);


/*
 * Update some rows in the specified table
 * _h: structure representing database connection
 * _k: key names
 * _o: operators
 * _v: values of the keys that must match
 * _uk: updated columns
 * _uv: updated values of the columns
 * _n: number of key=value pairs
 * _un: number of columns to update
 */
typedef int (*db_update_f) (db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
			    db_key_t* _uk, db_val_t* _uv, int _n, int _un);

/*
 * Insert a row and replace if one already 
 */
typedef int (*db_replace_f) (db_con_t* handle, db_key_t* keys, db_val_t* vals, int n);


typedef struct db_func {
	unsigned int     cap;          /* Capability vector of the database transport */
	db_use_table_f   use_table;    /* Specify table name */
	db_init_f        init;         /* Initialize database connection */
	db_close_f       close;        /* Close database connection */
	db_query_f       query;        /* query a table */
	db_raw_query_f   raw_query;    /* Raw query - SQL */
	db_free_result_f free_result;  /* Free a query result */
	db_insert_f      insert;       /* Insert into table */
	db_delete_f      delete;       /* Delete from table */ 
	db_update_f      update;       /* Update table */
	db_replace_f     replace;      /* Replace row in a table */
} db_func_t;



/*
 * Bind database module functions
 * returns TRUE if everything went OK
 * FALSE otherwise
 */
int bind_dbmod(char* mod, db_func_t* dbf);


/*
 * Get the version of the given table. If there is
 * no row for the table then the function returns
 * version 0. -1 is returned on error.
 */
int table_version(db_func_t* dbf, db_con_t* con, const str* table);


#endif /* DB_H */