modules_k/db_sqlite/dbase.h

00001 /*
00002  * $Id$
00003  *
00004  * SQlite module core functions
00005  *
00006  * Copyright (C) 2010 Timo Teräs
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 
00025 
00026 #ifndef DBASE_H
00027 #define DBASE_H
00028 
00029 #include <sqlite3.h>
00030 
00031 #include "../../lib/srdb1/db_pool.h"
00032 #include "../../lib/srdb1/db_con.h"
00033 #include "../../lib/srdb1/db_res.h"
00034 #include "../../lib/srdb1/db_key.h"
00035 #include "../../lib/srdb1/db_op.h"
00036 #include "../../lib/srdb1/db_val.h"
00037 
00038 #define DB_SQLITE_MAX_BINDS 64
00039 
00040 struct sqlite_connection {
00041         struct pool_con hdr;
00042 
00043         sqlite3 *conn;
00044         int bindpos;
00045 
00046         sqlite3_stmt *stmt;
00047         const db_val_t *bindarg[DB_SQLITE_MAX_BINDS];
00048 };
00049 
00050 #define CON_SQLITE(db_con)      ((struct sqlite_connection *) db_con->tail)
00051 
00052 db1_con_t* db_sqlite_init(const str* _sqlurl);
00053 void db_sqlite_close(db1_con_t* _h);
00054 
00055 int db_sqlite_free_result(db1_con_t* _h, db1_res_t* _r);
00056 
00057 int db_sqlite_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op,
00058                 const db_val_t* _v, const db_key_t* _c, int _n, int _nc,
00059                 const db_key_t _o, db1_res_t** _r);
00060 int db_sqlite_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
00061                 int _n);
00062 int db_sqlite_delete(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o,
00063                 const db_val_t* _v, int _n);
00064 int db_sqlite_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o,
00065                 const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv,
00066                 int _n, int _un);
00067 int db_sqlite_raw_query(const db1_con_t* _h, const str* _s, db1_res_t** _r);
00068 
00069 int db_sqlite_use_table(db1_con_t* _h, const str* _t);
00070 
00071 
00072 #endif /* DBASE_H */