00001 /* 00002 * $Id: db_query.h 4878 2008-09-10 17:00:49Z henningw $ 00003 * 00004 * Copyright (C) 2007-2008 1&1 Internet AG 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 */ 00023 00024 /** 00025 * \file db/db_query.h 00026 * \brief Query helper for database drivers 00027 * \ingroup db 00028 * 00029 * This helper methods for database queries are used from the database 00030 * SQL driver to do the actual work. Each function uses some functions from 00031 * the actual driver with function pointers to the concrete, specific 00032 * implementation. 00033 */ 00034 00035 #ifndef DB_QUERY_H 00036 #define DB_QUERY_H 00037 00038 #include "db_key.h" 00039 #include "db_op.h" 00040 #include "db_val.h" 00041 #include "db_con.h" 00042 #include "db_row.h" 00043 #include "db_res.h" 00044 #include "db_cap.h" 00045 00046 00047 /** 00048 * \brief Helper function for db queries 00049 * 00050 * This method evaluates the actual arguments for the database query and 00051 * setups the string that is used for the query in the db module. 00052 * Then its submit the query and stores the result if necessary. It uses for 00053 * its work the implementation in the concrete database module. 00054 * 00055 * \param _h structure representing database connection 00056 * \param _k key names, if not present the whole table will be returned 00057 * \param _op operators 00058 * \param _v values of the keys that must match 00059 * \param _c column names that should be returned 00060 * \param _n number of key/value pairs that are compared, if zero then no comparison is done 00061 * \param _nc number of colums that should be returned 00062 * \param _o order by the specificied column, optional 00063 * \param _r the result that is returned, set to NULL if you want to use fetch_result later 00064 * \param (*val2str) function pointer to the db specific val conversion function 00065 * \param (*submit_query) function pointer to the db specific query submit function 00066 * \param (*store_result) function pointer to the db specific store result function 00067 * \return zero on success, negative on errors 00068 */ 00069 int db_do_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op, 00070 const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, 00071 const db_key_t _o, db_res_t** _r, int (*val2str) (const db_con_t*, 00072 const db_val_t*, char*, int*), int (*submit_query)(const db_con_t* _h, 00073 const str* _c), int (*store_result)(const db_con_t* _h, db_res_t** _r)); 00074 00075 00076 /** 00077 * \brief Helper function for raw db queries 00078 * 00079 * This method evaluates the actual arguments for the database raw query 00080 * and setups the string that is used for the query in the db module. 00081 * Then its submit the query and stores the result if necessary. 00082 * It uses for its work the implementation in the concrete database module. 00083 * 00084 * \param _h structure representing database connection 00085 * \param _s char holding the raw query 00086 * \param _r the result that is returned 00087 * \param (*submit_query) function pointer to the db specific query submit function 00088 * \param (*store_result) function pointer to the db specific store result function 00089 * \return zero on success, negative on errors 00090 */ 00091 int db_do_raw_query(const db_con_t* _h, const str* _s, db_res_t** _r, 00092 int (*submit_query)(const db_con_t* _h, const str* _c), 00093 int (*store_result)(const db_con_t* _h, db_res_t** _r)); 00094 00095 00096 /** 00097 * \brief Helper function for db insert operations 00098 * 00099 * This method evaluates the actual arguments for the database operation 00100 * and setups the string that is used for the insert operation in the db 00101 * module. Then its submit the query for the operation. It uses for its work 00102 * the implementation in the concrete database module. 00103 * 00104 * \param _h structure representing database connection 00105 * \param _k key names 00106 * \param _v values of the keys 00107 * \param _n number of key/value pairs 00108 * \param (*val2str) function pointer to the db specific val conversion function 00109 * \param (*submit_query) function pointer to the db specific query submit function 00110 * \return zero on success, negative on errors 00111 */ 00112 int db_do_insert(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v, 00113 const int _n, int (*val2str) (const db_con_t*, const db_val_t*, char*, int*), 00114 int (*submit_query)(const db_con_t* _h, const str* _c)); 00115 00116 00117 /** 00118 * \brief Helper function for db delete operations 00119 * 00120 * This method evaluates the actual arguments for the database operation 00121 * and setups the string that is used for the delete operation in the db 00122 * module. Then its submit the query for the operation. It uses for its work 00123 * the implementation in the concrete database module. 00124 * 00125 * \param _h structure representing database connection 00126 * \param _k key names 00127 * \param _o operators 00128 * \param _v values of the keys that must match 00129 * \param _n number of key/value pairs that are compared, if zero then the whole table is deleted 00130 * \param (*val2str) function pointer to the db specific val conversion function 00131 * \param (*submit_query) function pointer to the db specific query submit function 00132 * \return zero on success, negative on errors 00133 */ 00134 int db_do_delete(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o, 00135 const db_val_t* _v, const int _n, int (*val2str) (const db_con_t*, 00136 const db_val_t*, char*, int*), int (*submit_query)(const db_con_t* _h, 00137 const str* _c)); 00138 00139 00140 /** 00141 * \brief Helper function for db update operations 00142 * 00143 * This method evaluates the actual arguments for the database operation 00144 * and setups the string that is used for the update operation in the db 00145 * module. Then its submit the query for the operation. It uses for its work 00146 * the implementation in the concrete database module. 00147 * 00148 * \param _h structure representing database connection 00149 * \param _k key names, if not present the whole table will be returned 00150 * \param _o operators 00151 * \param _v values of the keys that must match 00152 * \param _uk: updated columns 00153 * \param _uv: updated values of the columns 00154 * \param _n number of key/value pairs that are compared, if zero then no comparison is done 00155 * \param _un: number of columns that should be updated 00156 * \param (*val2str) function pointer to the db specific val conversion function 00157 * \param (*submit_query) function pointer to the db specific query submit function 00158 * \return zero on success, negative on errors 00159 */ 00160 int db_do_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o, 00161 const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n, 00162 const int _un, int (*val2str) (const db_con_t*, const db_val_t*, char*, int*), 00163 int (*submit_query)(const db_con_t* _h, const str* _c)); 00164 00165 00166 /** 00167 * \brief Helper function for db delete operations 00168 * 00169 * This helper method evaluates the actual arguments for the database operation 00170 * and setups the string that is used for the replace operation in the db 00171 * module. Then its submit the query for the operation. It uses for its work the 00172 * implementation in the concrete database module. 00173 * 00174 * \param _h structure representing database connection 00175 * \param _k key names, if not present the whole table will be returned 00176 * \param _v values of the keys that must match 00177 * \param _n number of key/value pairs that are compared, if zero then no comparison is done 00178 * \param (*val2str) function pointer to the db specific val conversion function 00179 * \param (*submit_query) function pointer to the db specific query submit function 00180 * \return zero on success, negative on errors 00181 */ 00182 int db_do_replace(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v, 00183 const int _n, int (*val2str) (const db_con_t*, const db_val_t*, char*, 00184 int*), int (*submit_query)(const db_con_t* _h, const str* _c)); 00185 00186 00187 #endif
1.5.6