Skip to content

Commit

Permalink
db_unixodbc: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 2a66061 commit 2b597d8
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 494 deletions.
253 changes: 129 additions & 124 deletions src/modules/db_unixodbc/connection.c

Large diffs are not rendered by default.

51 changes: 27 additions & 24 deletions src/modules/db_unixodbc/connection.h
Expand Up @@ -49,58 +49,61 @@ typedef struct strn

struct my_con
{
struct db_id* id; /*!< Connection identifier */
unsigned int ref; /*!< Reference count */
struct pool_con* next; /*!< Next connection in the pool */
SQLHENV env; /*!< Environment handle */
SQLHSTMT stmt_handle; /*!< Actual result */
SQLHDBC dbc; /*!< Connection representation */
char** row; /*!< Actual row in the result */
time_t timestamp; /*!< Timestamp of last query */
int statement_res; /*!< ODBC real statement result */
struct db_id *id; /*!< Connection identifier */
unsigned int ref; /*!< Reference count */
struct pool_con *next; /*!< Next connection in the pool */
SQLHENV env; /*!< Environment handle */
SQLHSTMT stmt_handle; /*!< Actual result */
SQLHDBC dbc; /*!< Connection representation */
char **row; /*!< Actual row in the result */
time_t timestamp; /*!< Timestamp of last query */
int statement_res; /*!< ODBC real statement result */
};

/*
* Some convenience wrappers
*/
#define CON_RESULT(db_con) (((struct my_con*)((db_con)->tail))->stmt_handle)
#define CON_CONNECTION(db_con) (((struct my_con*)((db_con)->tail))->dbc)
#define CON_ROW(db_con) (((struct my_con*)((db_con)->tail))->row)
#define CON_TIMESTAMP(db_con) (((struct my_con*)((db_con)->tail))->timestamp)
#define CON_ID(db_con) (((struct my_con*)((db_con)->tail))->id)
#define CON_ENV(db_con) (((struct my_con*)((db_con)->tail))->env)
#define CON_QUERY_RESULT(db_con) (((struct my_con*)((db_con)->tail))->statement_res)
#define CON_RESULT(db_con) (((struct my_con *)((db_con)->tail))->stmt_handle)
#define CON_CONNECTION(db_con) (((struct my_con *)((db_con)->tail))->dbc)
#define CON_ROW(db_con) (((struct my_con *)((db_con)->tail))->row)
#define CON_TIMESTAMP(db_con) (((struct my_con *)((db_con)->tail))->timestamp)
#define CON_ID(db_con) (((struct my_con *)((db_con)->tail))->id)
#define CON_ENV(db_con) (((struct my_con *)((db_con)->tail))->env)
#define CON_QUERY_RESULT(db_con) \
(((struct my_con *)((db_con)->tail))->statement_res)

#define MAX_CONN_STR_LEN 2048

/*
* Create a new connection structure,
* open the UNIXODBC connection and set reference count to 1
*/
struct my_con* db_unixodbc_new_connection(struct db_id* id);
struct my_con *db_unixodbc_new_connection(struct db_id *id);

/*
* Close the connection and release memory
*/
void db_unixodbc_free_connection(struct my_con* con);
void db_unixodbc_free_connection(struct my_con *con);

char *db_unixodbc_build_conn_str(const struct db_id* id, char *buf);
char *db_unixodbc_build_conn_str(const struct db_id *id, char *buf);

void db_unixodbc_extract_error(const char *fn, const SQLHANDLE handle, const SQLSMALLINT type, char* stret);
void db_unixodbc_extract_error(const char *fn, const SQLHANDLE handle,
const SQLSMALLINT type, char *stret);

/*
* Allocate a new row of cells, without any data
*/
strn * db_unixodbc_new_cellrow(size_t ncols);
strn *db_unixodbc_new_cellrow(size_t ncols);

/*
* Free row of cells and all associated memory
*/
void db_unixodbc_free_cellrow(size_t ncols, strn * row);
void db_unixodbc_free_cellrow(size_t ncols, strn *row);

/*
* Load ODBC cell data into a single cell
*/
int db_unixodbc_load_cell(const db1_con_t* _h, int colindex, strn * cell, const db_type_t _t);
int db_unixodbc_load_cell(
const db1_con_t *_h, int colindex, strn *cell, const db_type_t _t);

#endif /* MY_CON_H */
#endif /* MY_CON_H */
79 changes: 36 additions & 43 deletions src/modules/db_unixodbc/db_unixodbc.c
Expand Up @@ -30,9 +30,9 @@
#include "db_unixodbc.h"

int ping_interval = 5 * 60; /* Default is 5 minutes */
int auto_reconnect = 1; /* Default is enabled */
int use_escape_common = 0; /* Enable common escaping */
int replace_query = 1; /* Enable ODBC replace query */
int auto_reconnect = 1; /* Default is enabled */
int use_escape_common = 0; /* Enable common escaping */
int replace_query = 1; /* Enable ODBC replace query */

char *db_unixodbc_tquote = NULL;

Expand All @@ -45,67 +45,61 @@ int mod_init(void);
* MySQL database module interface
*/
static cmd_export_t cmds[] = {
{"db_bind_api", (cmd_function)db_unixodbc_bind_api, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0}
};
{"db_bind_api", (cmd_function)db_unixodbc_bind_api, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0}};


/*
* Exported parameters
*/
static param_export_t params[] = {
{"ping_interval", INT_PARAM, &ping_interval},
{"auto_reconnect", INT_PARAM, &auto_reconnect},
{"use_escape_common", INT_PARAM, &use_escape_common},
{"replace_query", INT_PARAM, &replace_query},
{"quote_char", PARAM_STRING, &db_unixodbc_tquote},
{0, 0, 0}
};
static param_export_t params[] = {{"ping_interval", INT_PARAM, &ping_interval},
{"auto_reconnect", INT_PARAM, &auto_reconnect},
{"use_escape_common", INT_PARAM, &use_escape_common},
{"replace_query", INT_PARAM, &replace_query},
{"quote_char", PARAM_STRING, &db_unixodbc_tquote}, {0, 0, 0}};


struct module_exports exports = {
"db_unixodbc",
DEFAULT_DLFLAGS, /* dlopen flags */
cmds,
params, /* module parameters */
0, /* exported·RPC·methods */
0, /* exported pseudo-variables */
0, /* response·function */
mod_init, /* module initialization function */
0, /* per-child init function */
0 /* destroy function */
"db_unixodbc", DEFAULT_DLFLAGS, /* dlopen flags */
cmds, params, /* module parameters */
0, /* exported·RPC·methods */
0, /* exported pseudo-variables */
0, /* response·function */
mod_init, /* module initialization function */
0, /* per-child init function */
0 /* destroy function */
};

int db_unixodbc_bind_api(db_func_t *dbb)
{
if(dbb==NULL)
if(dbb == NULL)
return -1;

memset(dbb, 0, sizeof(db_func_t));

dbb->use_table = db_unixodbc_use_table;
dbb->init = db_unixodbc_init;
dbb->close = db_unixodbc_close;
dbb->query = db_unixodbc_query;
dbb->fetch_result = db_unixodbc_fetch_result;
dbb->raw_query = db_unixodbc_raw_query;
dbb->free_result = db_unixodbc_free_result;
dbb->insert = db_unixodbc_insert;
dbb->delete = db_unixodbc_delete;
dbb->update = db_unixodbc_update;
if (replace_query)
dbb->replace = db_unixodbc_replace;
dbb->use_table = db_unixodbc_use_table;
dbb->init = db_unixodbc_init;
dbb->close = db_unixodbc_close;
dbb->query = db_unixodbc_query;
dbb->fetch_result = db_unixodbc_fetch_result;
dbb->raw_query = db_unixodbc_raw_query;
dbb->free_result = db_unixodbc_free_result;
dbb->insert = db_unixodbc_insert;
dbb->delete = db_unixodbc_delete;
dbb->update = db_unixodbc_update;
if(replace_query)
dbb->replace = db_unixodbc_replace;
else
dbb->replace = db_unixodbc_update_or_insert;
dbb->raw_query_async = db_unixodbc_raw_query_async;
dbb->insert_async = db_unixodbc_insert_async;
dbb->replace = db_unixodbc_update_or_insert;
dbb->raw_query_async = db_unixodbc_raw_query_async;
dbb->insert_async = db_unixodbc_insert_async;

return 0;
}

int mod_register(char *path, int *dlflags, void *p1, void *p2)
{
if(db_api_init()<0)
if(db_api_init() < 0)
return -1;
return 0;
}
Expand All @@ -114,4 +108,3 @@ int mod_init(void)
{
return 0;
}

0 comments on commit 2b597d8

Please sign in to comment.