/* ============================================================================ Name : DBConnector.h Author : Stephen Cannon Version : 0.1 Copyright : Copyright 2011 Stephen Cannon Description : ============================================================================ * * This file is part of LikelihoodWeighting. * * LikelihoodWeighting is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * LikelihoodWeighting is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with LikelihoodWeighting. If not, see . * */ #ifndef DBCONNECTOR_H_ #define DBCONNECTOR_H_ #include #include #include #include #ifdef __cplusplus extern "C" { #endif enum { BUFFER_SIZE = 1024, LARGE_BUFFER_SIZE = 10240 }; enum { DBCONNECTOR_STATE_NOT_CONNECTED = 0, DBCONNECTOR_STATE_CONNECTED = 1, DBCONNECTOR_STATE_STMT_PREPARED = 2, DBCONNECTOR_STATE_STMT_EXECUTED = 3}; enum { ERR_GENERAL_ERROR = -1, ERR_ALREADY_CONNECTED = -9, ERR_NOT_CONNECTED = -10, ERR_NO_PREPARED_STMT = -11, ERR_STMT_NOT_EXECUTED = -12}; /** * Defines a parameter binding in a prepared statement. A parameter binding * defines information about the parameter being bound to a prepared statement * as well as holds the value to be passed into the prepared statement when it * is used in a DB query. There is a parameter binding for each "?" in a * prepared statement. */ typedef struct _ParamBinding_ { SQLSMALLINT ioType; SQLSMALLINT valueType; SQLSMALLINT paramType; SQLULEN columnSize; SQLSMALLINT decimalDigits; SQLPOINTER paramValuePtr; SQLLEN bufferLength; SQLLEN *indPtr; } ParamBinding; /** * Defines a column binding in a prepared statement. A column binding defines * a column's type and holds the value returned for that column after the DB * has been queried. */ typedef struct _ColBinding_ { SQLSMALLINT type; SQLPOINTER valuePtr; SQLLEN bufferLength; SQLLEN *indPtr; } ColBinding; /** * Defines a DB connection and allows one to query that DB */ typedef struct _DBConnector_ { SQLHENV h_env; SQLHDBC h_dbc; SQLHSTMT h_stmt; SQLCHAR *stmt; const char *connectionString; size_t state; } DBConnector; char DBConnector__init(DBConnector *self, const char *connectionString); char DBConnector__connect(DBConnector *self); char DBConnector__prepareStatement(DBConnector *self, const char *stmt, ParamBinding *paramBinding, size_t numParams, ColBinding *colBinding, size_t numCols); char DBConnector__executePreparedStatement(DBConnector *self); char DBConnector__fetchExecutedStatementResult(DBConnector *self, char *error); char DBConnector__disconnect(DBConnector *self); char DBConnector__del(DBConnector *self); void __DBConnector__extractError(const char *fn, SQLHANDLE handle, SQLSMALLINT type); #ifdef __cplusplus } #endif #endif /* DBCONNECTOR_H_ */