#define DATABASE_H_
typedef enum db_type_t db_type_t;
+typedef enum db_driver_t db_driver_t;
typedef struct database_t database_t;
#include <utils/enumerator.h>
DB_NULL,
};
+/**
+ * Database implementation type.
+ */
+enum db_driver_t {
+ /** SQLite database */
+ DB_SQLITE,
+ /** MySQL database */
+ DB_MYSQL,
+};
/**
* Interface for a database implementation.
int (*execute)(database_t *this, int *rowid, char *sql, ...);
/**
+ * Get the database implementation type.
+ *
+ * To allow driver specific SQL or performance optimizations each database
+ * implementations can be queried for its type.
+ *
+ * @return database implementation type
+ */
+ db_driver_t (*get_driver)(database_t *this);
+
+ /**
* Destroy a database connection.
*/
void (*destroy)(database_t *this);
conn_release(conn);
return affected;
}
+
+/**
+ * Implementation of database_t.get_driver
+ */
+static db_driver_t get_driver(private_mysql_database_t *this)
+{
+ return DB_MYSQL;
+}
/**
* Implementation of database_t.destroy
this->public.db.query = (enumerator_t* (*)(database_t *this, char *sql, ...))query;
this->public.db.execute = (int (*)(database_t *this, int *rowid, char *sql, ...))execute;
+ this->public.db.get_driver = (db_driver_t(*)(database_t*))get_driver;
this->public.db.destroy = (void(*)(database_t*))destroy;
if (!parse_uri(this, uri))
}
/**
+ * Implementation of database_t.get_driver
+ */
+static db_driver_t get_driver(private_sqlite_database_t *this)
+{
+ return DB_SQLITE;
+}
+
+/**
* Implementation of database_t.destroy
*/
static void destroy(private_sqlite_database_t *this)
this->public.db.query = (enumerator_t* (*)(database_t *this, char *sql, ...))query;
this->public.db.execute = (int (*)(database_t *this, int *rowid, char *sql, ...))execute;
+ this->public.db.get_driver = (db_driver_t(*)(database_t*))get_driver;
this->public.db.destroy = (void(*)(database_t*))destroy;
this->mutex = mutex_create(MUTEX_RECURSIVE);