db_mysql.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "../../sr_module.h"
00045 #include "../../db/db.h"
00046 #include "dbase.h"
00047 #include "db_mysql.h"
00048
00049 #include <mysql/mysql.h>
00050
00051 unsigned int db_mysql_ping_interval = 5 * 60;
00052 unsigned int db_mysql_timeout_interval = 2;
00053 unsigned int db_mysql_auto_reconnect = 1;
00054
00055 static int mysql_mod_init(void);
00056
00057 MODULE_VERSION
00058
00059 int db_mysql_bind_api(db_func_t *dbb);
00060
00061
00062
00063
00064 static cmd_export_t cmds[] = {
00065 {"db_bind_api", (cmd_function)db_mysql_bind_api, 0, 0, 0, 0},
00066 {0, 0, 0, 0, 0, 0}
00067 };
00068
00069
00070
00071
00072
00073 static param_export_t params[] = {
00074 {"ping_interval", INT_PARAM, &db_mysql_ping_interval},
00075 {"timeout_interval", INT_PARAM, &db_mysql_timeout_interval},
00076 {"auto_reconnect", INT_PARAM, &db_mysql_auto_reconnect},
00077 {0, 0, 0}
00078 };
00079
00080
00081 struct module_exports exports = {
00082 "db_mysql",
00083 DEFAULT_DLFLAGS,
00084 cmds,
00085 params,
00086 0,
00087 0,
00088 0,
00089 0,
00090 mysql_mod_init,
00091 0,
00092 0,
00093 0
00094 };
00095
00096
00097 static int mysql_mod_init(void)
00098 {
00099 LM_DBG("MySQL client version is %s\n", mysql_get_client_info());
00100 return 0;
00101 }
00102
00103 int db_mysql_bind_api(db_func_t *dbb)
00104 {
00105 if(dbb==NULL)
00106 return -1;
00107
00108 memset(dbb, 0, sizeof(db_func_t));
00109
00110 dbb->use_table = db_mysql_use_table;
00111 dbb->init = db_mysql_init;
00112 dbb->close = db_mysql_close;
00113 dbb->query = db_mysql_query;
00114 dbb->fetch_result = db_mysql_fetch_result;
00115 dbb->raw_query = db_mysql_raw_query;
00116 dbb->free_result = db_mysql_free_result;
00117 dbb->insert = db_mysql_insert;
00118 dbb->delete = db_mysql_delete;
00119 dbb->update = db_mysql_update;
00120 dbb->replace = db_mysql_replace;
00121 dbb->last_inserted_id = db_last_inserted_id;
00122 dbb->insert_update = db_insert_update;
00123
00124 return 0;
00125 }
00126