Skip to content

Commit

Permalink
Add database functions
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-ciurel authored and razvancrainea committed Jan 23, 2019
1 parent 6dda820 commit 4becb73
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
57 changes: 57 additions & 0 deletions modules/proto_smpp/db.c
@@ -0,0 +1,57 @@
#include "../../db/db.h"
#include "../../str.h"
#include "db.h"

static db_con_t* smpp_db_handle;
static db_func_t smpp_dbf;

int smpp_db_bind(const str *db_url)
{
if (db_bind_mod(db_url, &smpp_dbf)) {
LM_ERR("cannot bind module database\n");
return -1;
}
return 0;
}

int smpp_db_init(const str *db_url)
{
if (smpp_dbf.init == 0) {
LM_ERR("unbound database module\n");
return -1;
}
smpp_db_handle = smpp_dbf.init(db_url);
if (smpp_db_handle == 0){
LM_ERR("cannot initialize database connection\n");
return -1;
}
return 0;
}

int smpp_query(const str *smpp_table, db_key_t *cols, int col_nr, db_res_t **res)
{
if (smpp_dbf.use_table(smpp_db_handle, smpp_table) < 0) {
LM_ERR("error while trying to use smpp table\n");
return -1;
}

if (smpp_dbf.query(smpp_db_handle, NULL, 0, NULL, cols, 0, col_nr, 0, res) < 0) {
LM_ERR("error while querying database\n");
return -1;
}

return 0;
}

void smpp_free_results(db_res_t *res)
{
smpp_dbf.free_result(smpp_db_handle, res);
}

void smpp_db_close(void)
{
if (smpp_db_handle && smpp_dbf.close) {
smpp_dbf.close(smpp_db_handle);
smpp_db_handle = 0;
}
}
13 changes: 13 additions & 0 deletions modules/proto_smpp/db.h
@@ -0,0 +1,13 @@
#ifndef _FOOBAR_DB_H_
#define _FOOBAR_DB_H_

#include "../../db/db.h"
#include "../../str.h"

int smpp_db_bind(const str *db_url);
int smpp_db_init(const str *db_url);
int smpp_query(const str *smpp_table, db_key_t *cols, int col_nr, db_res_t **res);
void smpp_free_results(db_res_t *res);
void smpp_db_close(void);

#endif

0 comments on commit 4becb73

Please sign in to comment.