From 85c7ac0acfae38118e8d4e39c44743cb42025b29 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 6 Jan 2013 02:09:33 -0800 Subject: [PATCH] Remove WinDatabase. --- src/cpp/database/win/dbutility.h | 82 --------- src/cpp/database/win/windatabase.cpp | 246 --------------------------- src/cpp/database/win/windatabase.h | 61 ------- 3 files changed, 389 deletions(-) delete mode 100644 src/cpp/database/win/dbutility.h delete mode 100644 src/cpp/database/win/windatabase.cpp delete mode 100644 src/cpp/database/win/windatabase.h diff --git a/src/cpp/database/win/dbutility.h b/src/cpp/database/win/dbutility.h deleted file mode 100644 index 5df5c1ec0c..0000000000 --- a/src/cpp/database/win/dbutility.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef __TMYODBC_UTILITY_H__ -#define __TMYODBC_UTILITY_H__ - -#ifdef HAVE_CONFIG_H -#include -#endif - - -/* STANDARD C HEADERS */ -#include -#include -#include - -/* ODBC HEADERS */ -#include - -#define MAX_NAME_LEN 95 -#define MAX_COLUMNS 255 -#define MAX_ROW_DATA_LEN 255 - - -/* PROTOTYPE */ -void myerror(SQLRETURN rc,SQLSMALLINT htype, SQLHANDLE handle); - -/* UTILITY MACROS */ -#define myenv(henv,r) \ - if ( ((r) != SQL_SUCCESS) ) \ - myerror(r, 1,henv); \ - assert( ((r) == SQL_SUCCESS) || ((r) == SQL_SUCCESS_WITH_INFO) ) - -#define myenv_err(henv,r,rc) \ - if ( rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO ) \ - myerror(rc, 1, henv); \ - assert( r ) - -#define mycon(hdbc,r) \ - if ( ((r) != SQL_SUCCESS) ) \ - myerror(r, 2, hdbc); \ - assert( ((r) == SQL_SUCCESS) || ((r) == SQL_SUCCESS_WITH_INFO) ) - -#define mycon_err(hdbc,r,rc) \ - if ( rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO ) \ - myerror(rc, 2, hdbc); \ - assert( r ) - -#define mystmt(hstmt,r) \ - if ( ((r) != SQL_SUCCESS) ) \ - myerror(r, 3, hstmt); \ - assert( ((r) == SQL_SUCCESS) || ((r) == SQL_SUCCESS_WITH_INFO) ) - -#define mystmt_err(hstmt,r,rc) \ - if ( rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO ) \ - myerror(rc, 3, hstmt); \ - assert( r ) - -/******************************************************** -* MyODBC 3.51 error handler * -*********************************************************/ -void myerror(SQLRETURN rc, SQLSMALLINT htype, SQLHANDLE handle) -{ - SQLRETURN lrc; - - if( rc == SQL_ERROR || rc == SQL_SUCCESS_WITH_INFO ) - { - SQLCHAR szSqlState[6],szErrorMsg[SQL_MAX_MESSAGE_LENGTH]; - SQLINTEGER pfNativeError; - SQLSMALLINT pcbErrorMsg; - - lrc = SQLGetDiagRec(htype, handle,1, - (SQLCHAR *)&szSqlState, - (SQLINTEGER *)&pfNativeError, - (SQLCHAR *)&szErrorMsg, - SQL_MAX_MESSAGE_LENGTH-1, - (SQLSMALLINT *)&pcbErrorMsg); - if(lrc == SQL_SUCCESS || lrc == SQL_SUCCESS_WITH_INFO) - printf("\n [%s][%d:%s]\n",szSqlState,pfNativeError,szErrorMsg); - } -} - - -#endif /* __TMYODBC_UTILITY_H__ */ - diff --git a/src/cpp/database/win/windatabase.cpp b/src/cpp/database/win/windatabase.cpp deleted file mode 100644 index 64215fb8a3..0000000000 --- a/src/cpp/database/win/windatabase.cpp +++ /dev/null @@ -1,246 +0,0 @@ -#include "windatabase.h" -#include "dbutility.h" - -using namespace std; - -Database* Database::newMysqlDatabase(const char* host,const char* user,const char* pass) -{ - return(new WinDatabase(host,user,pass)); -} - -WinDatabase::WinDatabase(const char* host,const char* user,const char* pass) : Database(host,user,pass) -{ - -} - -WinDatabase::~WinDatabase() -{ - disconnect(); -} - - -void WinDatabase::connect() -{ - SQLRETURN rc; - - rc = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv); - myenv(henv, rc); - - rc = SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3,0); - myenv(henv, rc); - - rc = SQLAllocHandle(SQL_HANDLE_DBC,henv, &hdbc); - myenv(henv, rc); - - rc = SQLConnect(hdbc, (unsigned char*)(char*) mHost.c_str(), SQL_NTS, (unsigned char*)(char*) mUser.c_str(), SQL_NTS, (unsigned char*)(char*) mDBPass.c_str(), SQL_NTS); - mycon(hdbc, rc); - - rc = SQLSetConnectAttr(hdbc,SQL_ATTR_AUTOCOMMIT,(SQLPOINTER)SQL_AUTOCOMMIT_ON,0); - mycon(hdbc,rc); - - rc = SQLAllocHandle(SQL_HANDLE_STMT,hdbc,&hstmt); - mycon(hdbc,rc); - - //rc = SQLGetInfo(hdbc,SQL_DBMS_NAME,&server_name,40,NULL); - //mycon(hdbc, rc); - - //theUI->statusMsg("Connection Established to DB"); -} - -void WinDatabase::disconnect() -{ - SQLRETURN rc; - - rc = SQLFreeStmt(hstmt, SQL_DROP); - mystmt(hstmt,rc); - - rc = SQLDisconnect(hdbc); - mycon(hdbc, rc); - - rc = SQLFreeHandle(SQL_HANDLE_DBC, hdbc); - mycon(hdbc, rc); - - rc = SQLFreeHandle(SQL_HANDLE_ENV, henv); - myenv(henv, rc); -} - -int WinDatabase::getNumRowsAffected() -{ -// theUI->statusMsg("getNumRowsAffected()"); - SQLINTEGER ret; - SQLRowCount(hstmt,&ret); - return(ret); -} - -// returns true if the query went ok -bool WinDatabase::executeSQL(const char* sql, bool fail_okay) -{ - SQLRETURN rc = SQLExecDirect(hstmt,(unsigned char*) sql,SQL_NTS); - if(rc==SQL_ERROR) - { - //theUI->errorMsg("Trying to recover from DB error"); - rc = SQLExecDirect(hstmt,(unsigned char*) sql,SQL_NTS); - if(rc==SQL_ERROR) - { - SQLCHAR SqlState[6], /*SQLStmt[100],*/ Msg[SQL_MAX_MESSAGE_LENGTH]; - SQLINTEGER NativeError; - SQLSMALLINT i, MsgLen; - SQLRETURN /*rc1,*/ rc2; - - i = 1; - while ((rc2 = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA) - { - //theUI->errorMsg("DB ERROR: %s,%d,%s",SqlState,NativeError,Msg); - i++; - } - - return(false); - } - } - - mystmt(hstmt,rc); - - // commit the transaction - rc = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT); - mycon(hdbc,rc); - - return(true); - -} - -bool WinDatabase::startIterRows() -{ - SQLUINTEGER pcColDef; - SQLCHAR szColName[MAX_NAME_LEN]; - SQLSMALLINT pfSqlType, pcbScale, pfNullable; - SQLSMALLINT numCol; - - /* get total number of columns from the resultset */ - SQLRETURN rc = SQLNumResultCols(hstmt,&numCol); - mystmt(hstmt,rc); - mNumCol=(int)numCol; - - if(mNumCol) - { - mColNameTable.resize(mNumCol); - - // fill out the column name table - for(int n = 1; n <= mNumCol; n++) - { - rc = SQLDescribeCol(hstmt,n,szColName, MAX_NAME_LEN, NULL, &pfSqlType,&pcColDef,&pcbScale,&pfNullable); - mystmt(hstmt,rc); - - mColNameTable[n-1]= (char*)szColName; - } - return(true); - } - return(false); -} - -// call this after you executeSQL -// will return false if there are no more rows -bool WinDatabase::getNextRow() -{ - SQLRETURN rc = SQLFetch(hstmt); - return((rc==SQL_SUCCESS) || (rc==SQL_SUCCESS_WITH_INFO)); -} - - - -char* WinDatabase::getStr(int colIndex,string& retStr) -{ - colIndex++; - retStr=""; - char buf[1000]; -// SQLINTEGER len; - buf[0]=0; - - while(SQLGetData(hstmt, colIndex, SQL_C_CHAR, &buf, 1000,NULL)!= SQL_NO_DATA) - { - retStr += buf; -// theUI->statusMsg("Win: %s",buf); - } - - //SQLRETURN rc = SQLGetData(hstmt,colIndex,SQL_C_CHAR,&buf,30000,&len); - //mystmt(hstmt,rc); - //*retStr=buf; - - //theUI->statusMsg("Win: %s",buf); - - return((char*)retStr.c_str()); -} - -int32 WinDatabase::getInt(int colIndex) -{ - colIndex++; - int ret=0; - SQLRETURN rc = SQLGetData(hstmt,colIndex,SQL_INTEGER,&ret,sizeof(int),NULL); - mystmt(hstmt,rc); - return(ret); -} - -float WinDatabase::getFloat(int colIndex) -{ - colIndex++; - float ret=0; - SQLRETURN rc = SQLGetData(hstmt,colIndex,SQL_C_FLOAT,&ret,sizeof(float),NULL); - mystmt(hstmt,rc); - - return(ret); -} - -bool WinDatabase::getBool(int colIndex) -{ - colIndex++; - char buf[1]; - buf[0]=0; - SQLRETURN rc = SQLGetData(hstmt,colIndex,SQL_C_CHAR,&buf,1,NULL); - mystmt(hstmt,rc); - - return(buf[0] != 0); -} - - -void WinDatabase::endIterRows() -{ - // free the statement row bind resources - SQLRETURN rc = SQLFreeStmt(hstmt, SQL_UNBIND); - mystmt(hstmt,rc); - - // free the statement cursor - rc = SQLFreeStmt(hstmt, SQL_CLOSE); - mystmt(hstmt,rc); -} - -// TODO -void WinDatabase::escape(const unsigned char* start,int size,std::string& retStr) -{ - retStr=(char*)start; -} - -// TODO -int WinDatabase::getLastInsertID() -{ - return(0); -} - -uint64 WinDatabase::getBigInt(int colIndex) -{ - colIndex++; - uint64 ret=0; - SQLRETURN rc = SQLGetData(hstmt,colIndex,SQL_INTEGER,&ret,sizeof(uint64),NULL); - mystmt(hstmt,rc); - return(ret); -} -// TODO: -int WinDatabase::getBinary(int colIndex,unsigned char* buf,int maxSize) -{ - return(0); -} - -std::vector WinDatabase::getBinary(int colIndex) -{ - // TODO: - std::vector vucResult; - return vucResult; -} \ No newline at end of file diff --git a/src/cpp/database/win/windatabase.h b/src/cpp/database/win/windatabase.h deleted file mode 100644 index 5ce0798707..0000000000 --- a/src/cpp/database/win/windatabase.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef __WINDATABASE__ -#define __WINDATABASE__ - -#include "../database.h" - - -#ifdef WIN32 -#define _WINSOCKAPI_ // prevent inclusion of winsock.h in windows.h -#include -#include "sql.h" -#endif - - -/* - this maintains the connection to the database -*/ -class WinDatabase : public Database -{ - SQLHENV henv; - SQLHDBC hdbc; - SQLHSTMT hstmt; - -public: - WinDatabase(const char* host,const char* user,const char* pass); - virtual ~WinDatabase(); - - void connect(); - void disconnect(); - - //char* getPass(){ return((char*)mDBPass.c_str()); } - - // returns true if the query went ok - bool executeSQL(const char* sql, bool fail_okay=false); - - int getNumRowsAffected(); - int getLastInsertID(); - - // returns false if there are no results - bool startIterRows(); - void endIterRows(); - - // call this after you executeSQL - // will return false if there are no more rows - bool getNextRow(); - - // get Data from the current row - char* getStr(int colIndex,std::string& retStr); - int32 getInt(int colIndex); - float getFloat(int colIndex); - bool getBool(int colIndex); - uint64 getBigInt(int colIndex); - int getBinary(int colIndex,unsigned char* buf,int maxSize); - std::vector getBinary(int colIndex); - bool getNull(int colIndex){ return(true); } - - void escape(const unsigned char* start,int size,std::string& retStr); -}; - - -#endif -