|
@@ -1,4 +1,4 @@
|
|
|
-/*
|
|
|
+/*
|
|
|
* PostgreSQL Database Driver for Kamailio
|
|
|
*
|
|
|
* Portions Copyright (C) 2001-2003 FhG FOKUS
|
|
@@ -23,10 +23,10 @@
|
|
|
*/
|
|
|
|
|
|
/** \addtogroup postgres
|
|
|
- * @{
|
|
|
+ * @{
|
|
|
*/
|
|
|
|
|
|
-/** \file
|
|
|
+/** \file
|
|
|
* Postgres module interface.
|
|
|
*/
|
|
|
|
|
@@ -50,8 +50,9 @@ MODULE_VERSION
|
|
|
static int pg_mod_init(void);
|
|
|
static void pg_mod_destroy(void);
|
|
|
|
|
|
-int pg_connect_timeout = 0; /* Default is unlimited */
|
|
|
-int pg_retries = 2; /* How many times should the module try re-execute failed commands.
|
|
|
+int pg_connect_timeout = 0; /* Default is unlimited */
|
|
|
+int pg_retries =
|
|
|
+ 2; /* How many times should the module try re-execute failed commands.
|
|
|
* 0 disables reconnecting */
|
|
|
|
|
|
int pg_lockset = 4;
|
|
@@ -62,19 +63,19 @@ int pg_keepalive = 0;
|
|
|
* Postgres module interface
|
|
|
*/
|
|
|
static cmd_export_t cmds[] = {
|
|
|
- {"db_ctx", (cmd_function)NULL, 0, 0, 0},
|
|
|
- {"db_con", (cmd_function)pg_con, 0, 0, 0},
|
|
|
- {"db_uri", (cmd_function)pg_uri, 0, 0, 0},
|
|
|
- {"db_cmd", (cmd_function)pg_cmd, 0, 0, 0},
|
|
|
- {"db_put", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
- {"db_del", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
- {"db_get", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
- {"db_upd", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
- {"db_sql", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
- {"db_res", (cmd_function)pg_res, 0, 0, 0},
|
|
|
- {"db_fld", (cmd_function)pg_fld, 0, 0, 0},
|
|
|
- {"db_first", (cmd_function)pg_cmd_first, 0, 0, 0},
|
|
|
- {"db_next", (cmd_function)pg_cmd_next, 0, 0, 0},
|
|
|
+ {"db_ctx", (cmd_function)NULL, 0, 0, 0},
|
|
|
+ {"db_con", (cmd_function)pg_con, 0, 0, 0},
|
|
|
+ {"db_uri", (cmd_function)pg_uri, 0, 0, 0},
|
|
|
+ {"db_cmd", (cmd_function)pg_cmd, 0, 0, 0},
|
|
|
+ {"db_put", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
+ {"db_del", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
+ {"db_get", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
+ {"db_upd", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
+ {"db_sql", (cmd_function)pg_cmd_exec, 0, 0, 0},
|
|
|
+ {"db_res", (cmd_function)pg_res, 0, 0, 0},
|
|
|
+ {"db_fld", (cmd_function)pg_fld, 0, 0, 0},
|
|
|
+ {"db_first", (cmd_function)pg_cmd_first, 0, 0, 0},
|
|
|
+ {"db_next", (cmd_function)pg_cmd_next, 0, 0, 0},
|
|
|
{"db_setopt", (cmd_function)pg_setopt, 0, 0, 0},
|
|
|
{"db_getopt", (cmd_function)pg_getopt, 0, 0, 0},
|
|
|
{"db_bind_api", (cmd_function)db_postgres_bind_api, 0, 0, 0},
|
|
@@ -86,24 +87,22 @@ static cmd_export_t cmds[] = {
|
|
|
* Exported parameters
|
|
|
*/
|
|
|
static param_export_t params[] = {
|
|
|
- {"retries", PARAM_INT, &pg_retries },
|
|
|
- {"lockset", PARAM_INT, &pg_lockset },
|
|
|
- {"timeout", PARAM_INT, &pg_timeout },
|
|
|
- {"tcp_keepalive", PARAM_INT, &pg_keepalive },
|
|
|
+ {"retries", PARAM_INT, &pg_retries},
|
|
|
+ {"lockset", PARAM_INT, &pg_lockset},
|
|
|
+ {"timeout", PARAM_INT, &pg_timeout},
|
|
|
+ {"tcp_keepalive", PARAM_INT, &pg_keepalive},
|
|
|
{0, 0, 0}
|
|
|
};
|
|
|
|
|
|
|
|
|
struct module_exports exports = {
|
|
|
- "db_postgres",
|
|
|
- cmds,
|
|
|
- 0, /* RPC method */
|
|
|
- params, /* module parameters */
|
|
|
- pg_mod_init, /* module initialization function */
|
|
|
- 0, /* response function*/
|
|
|
- pg_mod_destroy, /* destroy function */
|
|
|
- 0, /* oncancel function */
|
|
|
- 0 /* per-child init function */
|
|
|
+ "db_postgres", cmds, 0, /* RPC method */
|
|
|
+ params, /* module parameters */
|
|
|
+ pg_mod_init, /* module initialization function */
|
|
|
+ 0, /* response function*/
|
|
|
+ pg_mod_destroy, /* destroy function */
|
|
|
+ 0, /* oncancel function */
|
|
|
+ 0 /* per-child init function */
|
|
|
};
|
|
|
|
|
|
/*
|
|
@@ -132,118 +131,95 @@ CREATE TABLE test (
|
|
|
int pg_test(void)
|
|
|
{
|
|
|
int i, row;
|
|
|
- db_ctx_t* db;
|
|
|
- db_cmd_t* put, *del, *get;
|
|
|
- db_res_t* result;
|
|
|
- db_rec_t* rec;
|
|
|
- char* times;
|
|
|
-
|
|
|
- db_fld_t int_vals[] = {
|
|
|
- {.name = "col_bool", .type = DB_INT},
|
|
|
- {.name = "col_int8", .type = DB_INT},
|
|
|
- {.name = "col_int4", .type = DB_INT},
|
|
|
- {.name = "col_inet", .type = DB_INT},
|
|
|
- {.name = "col_timestamp", .type = DB_INT},
|
|
|
- {.name = "col_timestamptz", .type = DB_INT},
|
|
|
- {.name = "col_bit", .type = DB_INT},
|
|
|
- {.name = "col_varbit", .type = DB_INT},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
-
|
|
|
- db_fld_t datetime_vals[] = {
|
|
|
- {.name = "col_int8", .type = DB_INT},
|
|
|
- {.name = "col_int4", .type = DB_INT},
|
|
|
- {.name = "col_timestamp", .type = DB_INT},
|
|
|
- {.name = "col_timestamptz", .type = DB_INT},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- db_fld_t bitmap_vals[] = {
|
|
|
- {.name = "col_int8", .type = DB_INT},
|
|
|
- {.name = "col_int4", .type = DB_INT},
|
|
|
- {.name = "col_bit", .type = DB_INT},
|
|
|
- {.name = "col_varbit", .type = DB_INT},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
-
|
|
|
- db_fld_t float_vals[] = {
|
|
|
- {.name = "col_float4", .type = DB_FLOAT},
|
|
|
- {.name = "col_float8", .type = DB_FLOAT},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
+ db_ctx_t *db;
|
|
|
+ db_cmd_t *put, *del, *get;
|
|
|
+ db_res_t *result;
|
|
|
+ db_rec_t *rec;
|
|
|
+ char *times;
|
|
|
+
|
|
|
+ db_fld_t int_vals[] = {{.name = "col_bool", .type = DB_INT},
|
|
|
+ {.name = "col_int8", .type = DB_INT},
|
|
|
+ {.name = "col_int4", .type = DB_INT},
|
|
|
+ {.name = "col_inet", .type = DB_INT},
|
|
|
+ {.name = "col_timestamp", .type = DB_INT},
|
|
|
+ {.name = "col_timestamptz", .type = DB_INT},
|
|
|
+ {.name = "col_bit", .type = DB_INT},
|
|
|
+ {.name = "col_varbit", .type = DB_INT}, {.name = NULL}};
|
|
|
+
|
|
|
+ db_fld_t datetime_vals[] = {{.name = "col_int8", .type = DB_INT},
|
|
|
+ {.name = "col_int4", .type = DB_INT},
|
|
|
+ {.name = "col_timestamp", .type = DB_INT},
|
|
|
+ {.name = "col_timestamptz", .type = DB_INT}, {.name = NULL}};
|
|
|
+
|
|
|
+
|
|
|
+ db_fld_t bitmap_vals[] = {{.name = "col_int8", .type = DB_INT},
|
|
|
+ {.name = "col_int4", .type = DB_INT},
|
|
|
+ {.name = "col_bit", .type = DB_INT},
|
|
|
+ {.name = "col_varbit", .type = DB_INT}, {.name = NULL}};
|
|
|
+
|
|
|
+ db_fld_t float_vals[] = {{.name = "col_float4", .type = DB_FLOAT},
|
|
|
+ {.name = "col_float8", .type = DB_FLOAT}, {.name = NULL}};
|
|
|
|
|
|
db_fld_t double_vals[] = {
|
|
|
- {.name = "col_float8", .type = DB_DOUBLE},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
-
|
|
|
- db_fld_t str_vals[] = {
|
|
|
- {.name = "col_varchar", .type = DB_STR},
|
|
|
- {.name = "col_bytea", .type = DB_STR},
|
|
|
- {.name = "col_text", .type = DB_STR},
|
|
|
- {.name = "col_bpchar", .type = DB_STR},
|
|
|
- {.name = "col_char", .type = DB_STR},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
-
|
|
|
- db_fld_t cstr_vals[] = {
|
|
|
- {.name = "col_varchar", .type = DB_CSTR},
|
|
|
- {.name = "col_bytea", .type = DB_CSTR},
|
|
|
- {.name = "col_text", .type = DB_CSTR},
|
|
|
- {.name = "col_bpchar", .type = DB_CSTR},
|
|
|
- {.name = "col_char", .type = DB_CSTR},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
+ {.name = "col_float8", .type = DB_DOUBLE}, {.name = NULL}};
|
|
|
+
|
|
|
+ db_fld_t str_vals[] = {{.name = "col_varchar", .type = DB_STR},
|
|
|
+ {.name = "col_bytea", .type = DB_STR},
|
|
|
+ {.name = "col_text", .type = DB_STR},
|
|
|
+ {.name = "col_bpchar", .type = DB_STR},
|
|
|
+ {.name = "col_char", .type = DB_STR}, {.name = NULL}};
|
|
|
+
|
|
|
+ db_fld_t cstr_vals[] = {{.name = "col_varchar", .type = DB_CSTR},
|
|
|
+ {.name = "col_bytea", .type = DB_CSTR},
|
|
|
+ {.name = "col_text", .type = DB_CSTR},
|
|
|
+ {.name = "col_bpchar", .type = DB_CSTR},
|
|
|
+ {.name = "col_char", .type = DB_CSTR}, {.name = NULL}};
|
|
|
|
|
|
db_fld_t blob_vals[] = {
|
|
|
- {.name = "col_bytea", .type = DB_BLOB},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- db_fld_t res[] = {
|
|
|
- {.name = "col_bool", .type = DB_INT},
|
|
|
- {.name = "col_bytea", .type = DB_BLOB},
|
|
|
- {.name = "col_char", .type = DB_STR},
|
|
|
- {.name = "col_int8", .type = DB_INT},
|
|
|
- {.name = "col_int4", .type = DB_INT},
|
|
|
- {.name = "col_int2", .type = DB_INT},
|
|
|
- {.name = "col_text", .type = DB_STR},
|
|
|
- {.name = "col_float4", .type = DB_FLOAT},
|
|
|
- {.name = "col_float8", .type = DB_DOUBLE},
|
|
|
- {.name = "col_inet", .type = DB_INT},
|
|
|
- {.name = "col_bpchar", .type = DB_STR},
|
|
|
- {.name = "col_varchar", .type = DB_STR},
|
|
|
- {.name = "col_timestamp", .type = DB_DATETIME},
|
|
|
- {.name = "col_timestamptz", .type = DB_DATETIME},
|
|
|
- {.name = "col_bit", .type = DB_BITMAP},
|
|
|
- {.name = "col_varbit", .type = DB_BITMAP},
|
|
|
- {.name = NULL}
|
|
|
- };
|
|
|
+ {.name = "col_bytea", .type = DB_BLOB}, {.name = NULL}};
|
|
|
+
|
|
|
+
|
|
|
+ db_fld_t res[] = {{.name = "col_bool", .type = DB_INT},
|
|
|
+ {.name = "col_bytea", .type = DB_BLOB},
|
|
|
+ {.name = "col_char", .type = DB_STR},
|
|
|
+ {.name = "col_int8", .type = DB_INT},
|
|
|
+ {.name = "col_int4", .type = DB_INT},
|
|
|
+ {.name = "col_int2", .type = DB_INT},
|
|
|
+ {.name = "col_text", .type = DB_STR},
|
|
|
+ {.name = "col_float4", .type = DB_FLOAT},
|
|
|
+ {.name = "col_float8", .type = DB_DOUBLE},
|
|
|
+ {.name = "col_inet", .type = DB_INT},
|
|
|
+ {.name = "col_bpchar", .type = DB_STR},
|
|
|
+ {.name = "col_varchar", .type = DB_STR},
|
|
|
+ {.name = "col_timestamp", .type = DB_DATETIME},
|
|
|
+ {.name = "col_timestamptz", .type = DB_DATETIME},
|
|
|
+ {.name = "col_bit", .type = DB_BITMAP},
|
|
|
+ {.name = "col_varbit", .type = DB_BITMAP}, {.name = NULL}};
|
|
|
|
|
|
|
|
|
db = db_ctx("postgres");
|
|
|
- if (db == NULL) {
|
|
|
+ if(db == NULL) {
|
|
|
ERR("Error while initializing database layer\n");
|
|
|
goto error;
|
|
|
}
|
|
|
- if (db_add_db(db, "postgres://janakj:heslo@localhost/ser") < 0) goto error;
|
|
|
- if (db_connect(db) < 0) goto error;
|
|
|
-
|
|
|
+ if(db_add_db(db, "postgres://janakj:heslo@localhost/ser") < 0)
|
|
|
+ goto error;
|
|
|
+ if(db_connect(db) < 0)
|
|
|
+ goto error;
|
|
|
+
|
|
|
del = db_cmd(DB_DEL, db, "test", NULL, NULL, NULL);
|
|
|
- if (del == NULL) {
|
|
|
+ if(del == NULL) {
|
|
|
ERR("Error while building delete * query\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
- put = db_cmd(DB_PUT, db, "test", NULL, NULL, int_vals);
|
|
|
- if (put == NULL) {
|
|
|
+ put = db_cmd(DB_PUT, db, "test", NULL, NULL, int_vals);
|
|
|
+ if(put == NULL) {
|
|
|
ERR("Error while building test query\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
- if (db_exec(NULL, del)) {
|
|
|
+ if(db_exec(NULL, del)) {
|
|
|
ERR("Error while deleting rows from test table\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -257,7 +233,7 @@ int pg_test(void)
|
|
|
put->vals[6].v.int4 = 0xffffffff;
|
|
|
put->vals[7].v.int4 = 0xffffffff;
|
|
|
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -271,7 +247,7 @@ int pg_test(void)
|
|
|
put->vals[6].v.int4 = 0;
|
|
|
put->vals[7].v.int4 = 0;
|
|
|
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -279,7 +255,7 @@ int pg_test(void)
|
|
|
db_cmd_free(put);
|
|
|
|
|
|
put = db_cmd(DB_PUT, db, "test", NULL, NULL, bitmap_vals);
|
|
|
- if (put == NULL) {
|
|
|
+ if(put == NULL) {
|
|
|
ERR("Error while building bitmap test query\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -289,7 +265,7 @@ int pg_test(void)
|
|
|
put->vals[2].v.int4 = 0xffffffff;
|
|
|
put->vals[3].v.int4 = 0xffffffff;
|
|
|
put->vals[4].v.int4 = 0xffffffff;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -299,7 +275,7 @@ int pg_test(void)
|
|
|
put->vals[2].v.int4 = 0;
|
|
|
put->vals[3].v.int4 = 0;
|
|
|
put->vals[4].v.int4 = 0;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -307,21 +283,21 @@ int pg_test(void)
|
|
|
db_cmd_free(put);
|
|
|
|
|
|
put = db_cmd(DB_PUT, db, "test", NULL, NULL, float_vals);
|
|
|
- if (put == NULL) {
|
|
|
+ if(put == NULL) {
|
|
|
ERR("Error while building float test query\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
put->vals[0].v.flt = FLT_MAX;
|
|
|
put->vals[1].v.flt = FLT_MAX;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
put->vals[0].v.flt = FLT_MIN;
|
|
|
put->vals[1].v.flt = FLT_MIN;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -329,19 +305,19 @@ int pg_test(void)
|
|
|
db_cmd_free(put);
|
|
|
|
|
|
put = db_cmd(DB_PUT, db, "test", NULL, NULL, double_vals);
|
|
|
- if (put == NULL) {
|
|
|
+ if(put == NULL) {
|
|
|
ERR("Error while building double test query\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
put->vals[0].v.dbl = DBL_MAX;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
put->vals[0].v.dbl = DBL_MIN;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -350,7 +326,7 @@ int pg_test(void)
|
|
|
db_cmd_free(put);
|
|
|
|
|
|
put = db_cmd(DB_PUT, db, "test", NULL, NULL, str_vals);
|
|
|
- if (put == NULL) {
|
|
|
+ if(put == NULL) {
|
|
|
ERR("Error while building str test query\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -365,7 +341,7 @@ int pg_test(void)
|
|
|
put->vals[3].v.lstr.len = 0;
|
|
|
put->vals[4].v.lstr.s = "";
|
|
|
put->vals[4].v.lstr.len = 0;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -380,7 +356,7 @@ int pg_test(void)
|
|
|
put->vals[3].v.lstr.len = 3;
|
|
|
put->vals[4].v.lstr.s = "a should not be there";
|
|
|
put->vals[4].v.lstr.len = 1;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -388,7 +364,7 @@ int pg_test(void)
|
|
|
db_cmd_free(put);
|
|
|
|
|
|
put = db_cmd(DB_PUT, db, "test", NULL, NULL, cstr_vals);
|
|
|
- if (put == NULL) {
|
|
|
+ if(put == NULL) {
|
|
|
ERR("Error while building cstr test query\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -398,7 +374,7 @@ int pg_test(void)
|
|
|
put->vals[2].v.cstr = "";
|
|
|
put->vals[3].v.cstr = "";
|
|
|
put->vals[4].v.cstr = "";
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -408,7 +384,7 @@ int pg_test(void)
|
|
|
put->vals[2].v.cstr = "def";
|
|
|
put->vals[3].v.cstr = "def";
|
|
|
put->vals[4].v.cstr = "d";
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -416,14 +392,14 @@ int pg_test(void)
|
|
|
db_cmd_free(put);
|
|
|
|
|
|
put = db_cmd(DB_PUT, db, "test", NULL, NULL, blob_vals);
|
|
|
- if (put == NULL) {
|
|
|
+ if(put == NULL) {
|
|
|
ERR("Error while building blob test query\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
put->vals[0].v.blob.s = "\0\0\0\0";
|
|
|
put->vals[0].v.blob.len = 4;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -432,7 +408,7 @@ int pg_test(void)
|
|
|
db_cmd_free(put);
|
|
|
|
|
|
put = db_cmd(DB_PUT, db, "test", NULL, NULL, datetime_vals);
|
|
|
- if (put == NULL) {
|
|
|
+ if(put == NULL) {
|
|
|
ERR("Error while building datetime test query\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -441,7 +417,7 @@ int pg_test(void)
|
|
|
put->vals[1].v.time = 0xffffffff;
|
|
|
put->vals[2].v.time = 0xffffffff;
|
|
|
put->vals[3].v.time = 0xffffffff;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -450,24 +426,26 @@ int pg_test(void)
|
|
|
put->vals[1].v.time = 0;
|
|
|
put->vals[2].v.time = 0;
|
|
|
put->vals[3].v.time = 0;
|
|
|
- if (db_exec(NULL, put)) {
|
|
|
+ if(db_exec(NULL, put)) {
|
|
|
ERR("Error while executing database command\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
- if (put) db_cmd_free(put);
|
|
|
- if (del) db_cmd_free(del);
|
|
|
+ if(put)
|
|
|
+ db_cmd_free(put);
|
|
|
+ if(del)
|
|
|
+ db_cmd_free(del);
|
|
|
put = NULL;
|
|
|
del = NULL;
|
|
|
|
|
|
|
|
|
get = db_cmd(DB_GET, db, "test", res, NULL, NULL);
|
|
|
- if (get == NULL) {
|
|
|
+ if(get == NULL) {
|
|
|
ERR("Error while building select query\n");
|
|
|
goto error;
|
|
|
}
|
|
|
|
|
|
- if (db_exec(&result, get)) {
|
|
|
+ if(db_exec(&result, get)) {
|
|
|
ERR("Error while executing select query\n");
|
|
|
goto error;
|
|
|
}
|
|
@@ -477,36 +455,38 @@ int pg_test(void)
|
|
|
while(rec) {
|
|
|
ERR("row: %d\n", row);
|
|
|
for(i = 0; !DB_FLD_LAST(rec->fld[i]); i++) {
|
|
|
- if (rec->fld[i].flags & DB_NULL) {
|
|
|
+ if(rec->fld[i].flags & DB_NULL) {
|
|
|
ERR("%s: NULL\n", rec->fld[i].name);
|
|
|
} else {
|
|
|
switch(rec->fld[i].type) {
|
|
|
- case DB_INT:
|
|
|
- case DB_BITMAP:
|
|
|
- ERR("%s: %d\n", rec->fld[i].name, rec->fld[i].v.int4);
|
|
|
- break;
|
|
|
-
|
|
|
- case DB_DATETIME:
|
|
|
- times = ctime(&rec->fld[i].v.time);
|
|
|
- ERR("%s: %d:%.*s\n", rec->fld[i].name, rec->fld[i].v.time, strlen(times) - 1, times);
|
|
|
- break;
|
|
|
-
|
|
|
- case DB_DOUBLE:
|
|
|
- ERR("%s: %f\n", rec->fld[i].name, rec->fld[i].v.dbl);
|
|
|
- break;
|
|
|
-
|
|
|
- case DB_FLOAT:
|
|
|
- ERR("%s: %f\n", rec->fld[i].name, rec->fld[i].v.flt);
|
|
|
- break;
|
|
|
-
|
|
|
- case DB_STR:
|
|
|
- case DB_BLOB:
|
|
|
- ERR("%s: %.*s\n", rec->fld[i].name, rec->fld[i].v.lstr.len, rec->fld[i].v.lstr.s);
|
|
|
- break;
|
|
|
-
|
|
|
- case DB_CSTR:
|
|
|
- ERR("%s: %s\n", rec->fld[i].name, rec->fld[i].v.cstr);
|
|
|
- break;
|
|
|
+ case DB_INT:
|
|
|
+ case DB_BITMAP:
|
|
|
+ ERR("%s: %d\n", rec->fld[i].name, rec->fld[i].v.int4);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DB_DATETIME:
|
|
|
+ times = ctime(&rec->fld[i].v.time);
|
|
|
+ ERR("%s: %d:%.*s\n", rec->fld[i].name,
|
|
|
+ rec->fld[i].v.time, strlen(times) - 1, times);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DB_DOUBLE:
|
|
|
+ ERR("%s: %f\n", rec->fld[i].name, rec->fld[i].v.dbl);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DB_FLOAT:
|
|
|
+ ERR("%s: %f\n", rec->fld[i].name, rec->fld[i].v.flt);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DB_STR:
|
|
|
+ case DB_BLOB:
|
|
|
+ ERR("%s: %.*s\n", rec->fld[i].name,
|
|
|
+ rec->fld[i].v.lstr.len, rec->fld[i].v.lstr.s);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case DB_CSTR:
|
|
|
+ ERR("%s: %s\n", rec->fld[i].name, rec->fld[i].v.cstr);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -522,10 +502,13 @@ int pg_test(void)
|
|
|
db_ctx_free(db);
|
|
|
return 0;
|
|
|
|
|
|
- error:
|
|
|
- if (get) db_cmd_free(get);
|
|
|
- if (put) db_cmd_free(put);
|
|
|
- if (del) db_cmd_free(del);
|
|
|
+error:
|
|
|
+ if(get)
|
|
|
+ db_cmd_free(get);
|
|
|
+ if(put)
|
|
|
+ db_cmd_free(put);
|
|
|
+ if(del)
|
|
|
+ db_cmd_free(del);
|
|
|
db_disconnect(db);
|
|
|
db_ctx_free(db);
|
|
|
return -1;
|
|
@@ -538,7 +521,7 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2)
|
|
|
LM_ERR("failed too allocate buffer");
|
|
|
return -1;
|
|
|
}
|
|
|
- if(db_api_init()<0)
|
|
|
+ if(db_api_init() < 0)
|
|
|
return -1;
|
|
|
return 0;
|
|
|
}
|
|
@@ -546,14 +529,14 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2)
|
|
|
static int pg_mod_init(void)
|
|
|
{
|
|
|
#ifdef PG_TEST
|
|
|
- if (pg_test() == 0) {
|
|
|
+ if(pg_test() == 0) {
|
|
|
ERR("postgres: Testing successful\n");
|
|
|
} else {
|
|
|
ERR("postgres: Testing failed\n");
|
|
|
}
|
|
|
return -1;
|
|
|
#endif /* PG_TEST */
|
|
|
- if(pg_init_lock_set(pg_lockset)<0)
|
|
|
+ if(pg_init_lock_set(pg_lockset) < 0)
|
|
|
return -1;
|
|
|
return km_postgres_mod_init();
|
|
|
}
|