|
@@ -2,138 +2,14 @@
|
|
|
* $Id$
|
|
|
*/
|
|
|
|
|
|
-#ifndef __DB_H__
|
|
|
-#define __DB_H__
|
|
|
+#ifndef DB_H
|
|
|
+#define DB_H
|
|
|
|
|
|
-#include <time.h>
|
|
|
-
|
|
|
-/*
|
|
|
- * Generic database interface
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
-/* =================== db_key =============== */
|
|
|
-
|
|
|
-/*
|
|
|
- * Type of a database key (column)
|
|
|
- */
|
|
|
-typedef const char* db_key_t;
|
|
|
-
|
|
|
-
|
|
|
-/* =================== db_val =============== */
|
|
|
-
|
|
|
-/*
|
|
|
- * Accepted column types
|
|
|
- */
|
|
|
-typedef enum {
|
|
|
- DB_INT,
|
|
|
- DB_DOUBLE,
|
|
|
- DB_STRING,
|
|
|
- DB_DATETIME
|
|
|
-} db_type_t;
|
|
|
-
|
|
|
-
|
|
|
-/*
|
|
|
- * Column value structure
|
|
|
- */
|
|
|
-typedef struct {
|
|
|
- db_type_t type; /* Type of the value */
|
|
|
- int nul; /* Means that the column in database has no value */
|
|
|
- union {
|
|
|
- int int_val; /* integer value */
|
|
|
- double double_val; /* double value */
|
|
|
- time_t time_val; /* unix time value */
|
|
|
- const char* string_val; /* NULL terminated string */
|
|
|
- } val; /* union of all possible types */
|
|
|
-} db_val_t;
|
|
|
-
|
|
|
-
|
|
|
-/*
|
|
|
- * Useful macros for accessing attributes of db_val structure
|
|
|
- */
|
|
|
-
|
|
|
-/* Get value type */
|
|
|
-#define VAL_TYPE(dv) ((dv)->type)
|
|
|
-
|
|
|
-/* Get null flag (means that value in dabase is null) */
|
|
|
-#define VAL_NULL(dv) ((dv)->nul)
|
|
|
-
|
|
|
-/* Get integer value */
|
|
|
-#define VAL_INT(dv) ((dv)->val.int_val)
|
|
|
-
|
|
|
-/* Get double value */
|
|
|
-#define VAL_DOUBLE(dv) ((dv)->val.double_val)
|
|
|
-
|
|
|
-/* Get time_t value */
|
|
|
-#define VAL_TIME(dv) ((dv)->val.time_val)
|
|
|
-
|
|
|
-/* Get char* value */
|
|
|
-#define VAL_STRING(dv) ((dv)->val.string_val)
|
|
|
-
|
|
|
-
|
|
|
-/* ==================== db_con ======================= */
|
|
|
-
|
|
|
-/*
|
|
|
- * This structure represents a database connection
|
|
|
- * and pointer to this structure is used as a connection
|
|
|
- * handle
|
|
|
- */
|
|
|
-typedef struct {
|
|
|
- char* table; /* Default table to use */
|
|
|
- void* con; /* Mysql Connection */
|
|
|
- void* res; /* Result of previous operation */
|
|
|
- void* row; /* Actual row in the result */
|
|
|
- int connected; /* TRUE if connection is established */
|
|
|
-} db_con_t;
|
|
|
-
|
|
|
-
|
|
|
-/* ===================== db_row ====================== */
|
|
|
-
|
|
|
-/*
|
|
|
- * Structure holding result of query_table function (ie. table row)
|
|
|
- */
|
|
|
-typedef struct db_row {
|
|
|
- db_val_t* values; /* Columns in the row */
|
|
|
- int n; /* Number of columns in the row */
|
|
|
-} db_row_t;
|
|
|
-
|
|
|
-/* Useful macros for manipulating db_row structure attributes */
|
|
|
-
|
|
|
-/* Get row members */
|
|
|
-#define ROW_VALUES(rw) ((rw)->values)
|
|
|
-
|
|
|
-/* Get number of member in the row */
|
|
|
-#define ROW_N(rw) ((rw)->n)
|
|
|
-
|
|
|
-
|
|
|
-/* ===================== db_res ====================== */
|
|
|
-
|
|
|
-typedef struct db_res {
|
|
|
- struct {
|
|
|
- db_key_t* names; /* Column names */
|
|
|
- db_type_t* types; /* Column types */
|
|
|
- int n; /* Number of columns */
|
|
|
- } col;
|
|
|
- struct db_row* rows; /* Rows */
|
|
|
- int n; /* Number of rows */
|
|
|
-} db_res_t;
|
|
|
-
|
|
|
-/* Useful macros for manipulating db_res attributes */
|
|
|
-
|
|
|
-/* Column names */
|
|
|
-#define RES_NAMES(re) ((re)->col.names)
|
|
|
-
|
|
|
-/* Column types */
|
|
|
-#define RES_TYPES(re) ((re)->col.types)
|
|
|
-
|
|
|
-/* Number of columns */
|
|
|
-#define RES_COL_N(re) ((re)->col.n)
|
|
|
-
|
|
|
-/* Rows */
|
|
|
-#define RES_ROWS(re) ((re)->rows)
|
|
|
-
|
|
|
-/* Number of rows */
|
|
|
-#define RES_ROW_N(re) ((re)->n)
|
|
|
+#include "db_key.h"
|
|
|
+#include "db_val.h"
|
|
|
+#include "db_con.h"
|
|
|
+#include "db_row.h"
|
|
|
+#include "db_res.h"
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -235,8 +111,6 @@ typedef struct db_func{
|
|
|
* returns TRUE if everything went OK
|
|
|
* FALSE otherwise
|
|
|
*/
|
|
|
-int bind_dbmod(void);
|
|
|
-
|
|
|
|
|
|
extern db_func_t dbf;
|
|
|
|
|
@@ -249,5 +123,9 @@ extern db_func_t dbf;
|
|
|
#define db_insert (dbf.insert)
|
|
|
#define db_delete (dbf.delete)
|
|
|
#define db_update (dbf.update)
|
|
|
+
|
|
|
+
|
|
|
+int bind_dbmod(void);
|
|
|
|
|
|
+
|
|
|
#endif
|