From 6cec1c0c4778d7a41cf75d5c00183765e71f02bc Mon Sep 17 00:00:00 2001 From: coruja747 Date: Fri, 9 Oct 2015 23:13:52 -0300 Subject: [PATCH] Sphere is already using SQLite and MySQL Connector/C libs, so maybe we don't need this old /dbdll folder anymore --- src/dbdll/SphereDbDll.sln | 26 -- src/dbdll/common/SphereDatabasePlugin.def | 14 - src/dbdll/common/SphereDatabasePlugin.h | 228 ------------- src/dbdll/makefile.common | 59 ---- src/dbdll/mysql/MySqlConnection.cpp | 319 ------------------ src/dbdll/mysql/MySqlConnection.h | 84 ----- src/dbdll/mysql/MySqlPlugin.cpp | 139 -------- src/dbdll/mysql/makefile | 25 -- src/dbdll/mysql/mysql.vcxproj | 90 ----- src/dbdll/mysql/mysql.vcxproj.filters | 39 --- src/dbdll/mysql/stdafx.cpp | 31 -- src/dbdll/mysql/stdafx.h | 74 ----- src/dbdll/odbc/OdbcConnection.cpp | 387 ---------------------- src/dbdll/odbc/OdbcConnection.h | 99 ------ src/dbdll/odbc/OdbcPlugin.cpp | 141 -------- src/dbdll/odbc/makefile | 25 -- src/dbdll/odbc/odbc.vcxproj | 86 ----- src/dbdll/odbc/odbc.vcxproj.filters | 39 --- src/dbdll/odbc/stdafx.cpp | 31 -- src/dbdll/odbc/stdafx.h | 68 ---- 20 files changed, 2004 deletions(-) delete mode 100644 src/dbdll/SphereDbDll.sln delete mode 100644 src/dbdll/common/SphereDatabasePlugin.def delete mode 100644 src/dbdll/common/SphereDatabasePlugin.h delete mode 100644 src/dbdll/makefile.common delete mode 100644 src/dbdll/mysql/MySqlConnection.cpp delete mode 100644 src/dbdll/mysql/MySqlConnection.h delete mode 100644 src/dbdll/mysql/MySqlPlugin.cpp delete mode 100644 src/dbdll/mysql/makefile delete mode 100644 src/dbdll/mysql/mysql.vcxproj delete mode 100644 src/dbdll/mysql/mysql.vcxproj.filters delete mode 100644 src/dbdll/mysql/stdafx.cpp delete mode 100644 src/dbdll/mysql/stdafx.h delete mode 100644 src/dbdll/odbc/OdbcConnection.cpp delete mode 100644 src/dbdll/odbc/OdbcConnection.h delete mode 100644 src/dbdll/odbc/OdbcPlugin.cpp delete mode 100644 src/dbdll/odbc/makefile delete mode 100644 src/dbdll/odbc/odbc.vcxproj delete mode 100644 src/dbdll/odbc/odbc.vcxproj.filters delete mode 100644 src/dbdll/odbc/stdafx.cpp delete mode 100644 src/dbdll/odbc/stdafx.h diff --git a/src/dbdll/SphereDbDll.sln b/src/dbdll/SphereDbDll.sln deleted file mode 100644 index c5f3d418b..000000000 --- a/src/dbdll/SphereDbDll.sln +++ /dev/null @@ -1,26 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mysql", "mysql\mysql.vcxproj", "{751A388A-1B1C-4EC9-9ACD-18AB69F023C7}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "odbc", "odbc\odbc.vcxproj", "{89B82F5E-76B0-4C11-96D8-0A5F3DD21977}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {751A388A-1B1C-4EC9-9ACD-18AB69F023C7}.Debug|Win32.ActiveCfg = Debug|Win32 - {751A388A-1B1C-4EC9-9ACD-18AB69F023C7}.Debug|Win32.Build.0 = Debug|Win32 - {751A388A-1B1C-4EC9-9ACD-18AB69F023C7}.Release|Win32.ActiveCfg = Release|Win32 - {751A388A-1B1C-4EC9-9ACD-18AB69F023C7}.Release|Win32.Build.0 = Release|Win32 - {89B82F5E-76B0-4C11-96D8-0A5F3DD21977}.Debug|Win32.ActiveCfg = Debug|Win32 - {89B82F5E-76B0-4C11-96D8-0A5F3DD21977}.Debug|Win32.Build.0 = Debug|Win32 - {89B82F5E-76B0-4C11-96D8-0A5F3DD21977}.Release|Win32.ActiveCfg = Release|Win32 - {89B82F5E-76B0-4C11-96D8-0A5F3DD21977}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/dbdll/common/SphereDatabasePlugin.def b/src/dbdll/common/SphereDatabasePlugin.def deleted file mode 100644 index 82e68ff0d..000000000 --- a/src/dbdll/common/SphereDatabasePlugin.def +++ /dev/null @@ -1,14 +0,0 @@ -EXPORTS -db_isrightversion @1 -db_ping @2 -db_close @3 -db_isconnected @4 -db_getlasterror @5 -db_getlaststringerror @6 -db_connect @7 -db_execute @8 -db_query @9 -db_fetchfields @10 -db_numfields @11 -db_fetchrow @12 -db_escapestring @13 \ No newline at end of file diff --git a/src/dbdll/common/SphereDatabasePlugin.h b/src/dbdll/common/SphereDatabasePlugin.h deleted file mode 100644 index 7495d15dd..000000000 --- a/src/dbdll/common/SphereDatabasePlugin.h +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2006 Francesco Furiani - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _SPHEREDATABASEPLUGIN_H -#define _SPHEREDATABASEPLUGIN_H - -#ifdef _WIN32 - #define DBDLL_API - #define __CALLTYPE __stdcall -#else - #define DBDLL_API extern "C" - #define __CALLTYPE -#endif - -// Defines -#define DBPLUGIN_RESULT_NOQUERYRES 1 -#define DBPLUGIN_INTERNAL_ERROR -1 -#define DBPLUGIN_API_SPECIFIC_ERROR -(0xBEEF) -#define DBPLUGIN_UNKNOWN_ERROR -(0xDEDE) -#define DBPLUGIN_SERVER_LOST_ERROR -(0xDEAD) - -#define MAX_FIELD_NAME 512 -#define MAX_DATA_LENGTH 4096 - -// Interface objects -struct stFieldContainer -{ - char name[MAX_FIELD_NAME]; -}; - -typedef struct stFieldContainer fieldarray_t; - -struct stResultContainer -{ - char data[MAX_DATA_LENGTH]; -}; - -typedef struct stResultContainer resultarray_t; - -// Exported things - -/** - * db_isrightversion - * Used to check that the installed client library is usable. - * - * RETURNS: - * true if the library is usable; otherwise, false. - */ -DBDLL_API bool __CALLTYPE db_isrightversion(void); - -/** - * db_ping - * When connected, Sphere periodically calls this method to check that the connection is - * still alive. - * - * RETURNS: - * 0 to indicate success; otherwise, non-zero indicates that the connection has been lost. - */ -DBDLL_API int __CALLTYPE db_ping(void); - -/** - * db_close - * Used to close the current database connection. - * - * RETURNS: - * true if the connection has been closed; otherwise, false. - */ -DBDLL_API bool __CALLTYPE db_close(void); - -/** - * db_isconnected - * Used to check if there is a current connection to the database. - * - * RETURNS: - * true if there is a connection; otherwise, false. - */ -DBDLL_API bool __CALLTYPE db_isconnected(void); - -/** - * db_getlasterror - * If an operation has failed, this method will be called to retrieve the native error - * code. - * - * RETURNS: - * The error code from a previous operation. - */ -DBDLL_API int __CALLTYPE db_getlasterror(void); - -/** - * db_getlaststringerror - * If an operation has failed, this method will be called to retrieve a descriptive error - * message that can be displayed to the user. - * - * RETURNS: - * A null-terminated string containing the error message from a previous operation. - */ -DBDLL_API const char * __CALLTYPE db_getlaststringerror(void); - -/** - * db_connect - * Used to connect to a database server. - * - * ARGUMENTS: - * args: A list of null-terminated strings to use as the connection parameters, normally - * the parameters will be: - * args[0]: username - * args[1]: password - * args[2]: database - * args[3]: host - * args[4]: port - * argc: The number of connection paramteers. - * - * RETURNS: - * true if the connection was successful; otherwise, false. - */ -DBDLL_API bool __CALLTYPE db_connect(const char ** args, int argc); - -/** - * db_execute - * Used to execute a database query where results are not wanted/needed. - * - * ARGUMENTS: - * query: A null-terminated string containing the SQL query. - * - * RETURNS: - * 0 to indicate success; otherwise, a non-zero value indicates failure. - * - * NOTES: - * Use the DBPLUGIN_* defines to relay the type of error that occurred. Sphere will - * invoke db_getlasterror and db_getlasterrortext to retrieve error details. - */ -DBDLL_API int __CALLTYPE db_execute(const char * query); - -/** - * db_query - * Used to execute a database query where the results should be retrieved. - * - * ARGUMENTS: - * query: A null-terminated string containing the SQL query. - * - * RETURNS: - * 0 to indicate success; otherwise, a non-zero value indicates failure. - * - * NOTES: - * Use the DBPLUGIN_* defines to relay the type of error that occurred. Sphere will - * invoke db_getlasterror and db_getlasterrortext to retrieve error details. - */ -DBDLL_API int __CALLTYPE db_query(const char * query); - -/** - * db_fetchfields - * Used to retrieve column names for query results. - * - * ARGUMENTS: - * fields: A pointer to the list of field structures that need to be populated. - * - * RETURNS: - * The number of fields populated. A negative value indicates an error occurred. - */ -DBDLL_API int __CALLTYPE db_fetchfields(fieldarray_t * fields); - -/** - * db_numfields - * Used to retrieve the number of columns returned in the last query. - * - * RETURNS: - * The number of columns returned in the last query. A negative value indicates an - * error occurred. - */ -DBDLL_API int __CALLTYPE db_numfields(void); - -/** - * db_fetchrow - * Used to retrieve the next row of data from the last query. - * - * ARGUMENTS: - * results: A pointer to the list of result structures that need to be populated. - * - * RETURNS: - * The number of results populated (expected to equal the number of columns), or zero - * if there is no more data left to retrieve. A negative value indicates that an error - * occurred. - */ -DBDLL_API int __CALLTYPE db_fetchrow(resultarray_t * results); - -/** - * db_escapestring - * Used to escape special characters from a given character sequence. - * - * ARGUMENTS: - * inString: A sequence of characters to escape. - * inLength: The number of characters contained in inString. - * outString: An output buffer to write the escaped string sequence to. - * - * RETURNS: - * The number of characters written to outString. A negative value indicates that an - * error occurred. - */ -DBDLL_API int __CALLTYPE db_escapestring(const char * inString, int inLength, char * outString); - -#endif diff --git a/src/dbdll/makefile.common b/src/dbdll/makefile.common deleted file mode 100644 index 1a5e6b78d..000000000 --- a/src/dbdll/makefile.common +++ /dev/null @@ -1,59 +0,0 @@ -PLAT = Linux - -# Generic makefile -MARCH = -march=i686 -OPTDEFAULT = -fno-omit-frame-pointer -ffast-math -fpermissive $(MARCH) -OPT = -O2 $(OPTDEFAULT) -fPIC -shared -WARN = -Wall -Wextra -Wno-unknown-pragmas - -DEBUG = -ggdb2 -#DEBUG = -s - -# Linux -LIBS = -L/usr/lib -INCLUDE = -SRC = - -DEFNIX = -D_LINUX -DEBUGDEFS = -D_DEBUG -DEFINES = -D_REENTRANT $(DEFNIX) $(DEBUGDEFS) - -CC = g++ -CCO = gcc - -NO = -fno-rtti -fno-exceptions -EX = -fexceptions -fnon-call-exceptions -STRICT = # -mstrict-align -SPECIAL = $(EX) $(STRICT) $(DEBUG) - -PROF = -pg -PIPE = -pipe - -O_FLAGS = $(WARN) $(PIPE) $(SPECIAL) -C_FLAGS = $(OPT) $(DEFINES) - -# Targets - -.PHONY: all clean tidy - -all: $(PLUGIN) - -.depend: - @$(SCCO) -MM $(INCLUDE) $(SRC) $(COMMONSRC) > .depend - perl -pi -e 's/([^.]+)\.o/o\/\1.o/g' .depend - -tags: $(SRC) - ctags $(SRC) - -flags: - @echo "Compiler Flags: $(CC) -c $(O_FLAGS) $(C_FLAGS) $(INCLUDE)" - -%.o: %.cpp - @echo " Compiling $<" - @$(CC) -c $(O_FLAGS) $(C_FLAGS) $(INCLUDE) $< -o $@ - -%.co: %.c - @echo " Compiling $<" - @$(CCO) -c $(O_FLAGS) $(C_FLAGS) $(INCLUDE) $< -o $(@:.co=.o) - - diff --git a/src/dbdll/mysql/MySqlConnection.cpp b/src/dbdll/mysql/MySqlConnection.cpp deleted file mode 100644 index e0bf00c7b..000000000 --- a/src/dbdll/mysql/MySqlConnection.cpp +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (c) 2006 Francesco Furiani - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "stdafx.h" -#include "MySqlConnection.h" - -MySqlConnection * MySqlConnection::_mysqlConnection = NULL; - -MySqlConnection * MySqlConnection::GetCurrentInstance() -{ - if ( MySqlConnection::_mysqlConnection == NULL ) - { - MySqlConnection::_mysqlConnection = new MySqlConnection(); - } - - return MySqlConnection::_mysqlConnection; -} - -void MySqlConnection::DestroyCurrentInstance() -{ - if ( MySqlConnection::_mysqlConnection != NULL ) - { - delete MySqlConnection::_mysqlConnection; - MySqlConnection::_mysqlConnection = NULL; - } -} - -MySqlConnection::MySqlConnection() -{ - m_myData = NULL; - m_curResult = NULL; - SetConnected(false); -} - -MySqlConnection::~MySqlConnection() -{ - ClearResult(); - ClearMySqlData(); - - SetConnected(false); -} - -void MySqlConnection::ClearResult() -{ - if ( m_curResult != NULL ) - { - mysql_free_result(m_curResult); - m_curResult = NULL; - } -} - -void MySqlConnection::InitMySqlData() -{ - if ( m_myData == NULL ) - { - m_myData = mysql_init(NULL); - } -} - -void MySqlConnection::ClearMySqlData() -{ - if ( m_myData != NULL ) - { - mysql_close(m_myData); - m_myData = NULL; - } -} - - -bool MySqlConnection::IsConnected() -{ - return m_connected; -} - -void MySqlConnection::SetConnected( bool connected ) -{ - m_connected = connected; -} - -unsigned long MySqlConnection::GetClientVersion() -{ - return mysql_get_client_version(); -} - -int MySqlConnection::ServerPing() -{ - return mysql_ping(m_myData); -} - -bool MySqlConnection::ServerDisconnect() -{ - ClearResult(); - ClearMySqlData(); - - SetConnected(false); - - return IsConnected(); -} - -bool MySqlConnection::ServerConnect(const char * user, const char * password, const char * database, const char * hostip, int hostport) -{ - InitMySqlData(); - - MYSQL * result = mysql_real_connect(m_myData, hostip, user, password, database, hostport, NULL, CLIENT_MULTI_STATEMENTS ); - - if ( result == NULL ) - { - ServerDisconnect(); - } - else - { - SetConnected(true); - } - - return IsConnected(); -} - -int MySqlConnection::GetLastError() -{ - if ( m_myData != NULL ) - { - return mysql_errno(m_myData); - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -const char * MySqlConnection::GetLastStringError() -{ - if ( m_myData != NULL ) - { - return mysql_error(m_myData); - } - - return NULL; -} - -int MySqlConnection::Execute(const char * statement) -{ - if ( m_myData != NULL && statement != NULL && *statement != '\0' ) - { - int queryResult = mysql_query(m_myData, statement); - - switch ( queryResult ) - { - case CR_SERVER_GONE_ERROR: - case CR_SERVER_LOST: - return DBPLUGIN_SERVER_LOST_ERROR; - - case CR_UNKNOWN_ERROR: - return DBPLUGIN_UNKNOWN_ERROR; - - case CR_COMMANDS_OUT_OF_SYNC: - return DBPLUGIN_API_SPECIFIC_ERROR; - - case 0: - { - // even though we don't want (or expect) any result data, it must be - // retrieved anyway otherwise we will lose server connection - MYSQL_RES* res = mysql_store_result(m_myData); - if (res != NULL) - mysql_free_result(res); - } - } - - return 0; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int MySqlConnection::Query(const char * statement) -{ - if ( m_myData != NULL && statement != NULL && *statement != '\0' ) - { - int queryResult = mysql_query(m_myData, statement); - - switch ( queryResult ) - { - case CR_SERVER_GONE_ERROR: - case CR_SERVER_LOST: - return DBPLUGIN_SERVER_LOST_ERROR; - - case CR_UNKNOWN_ERROR: - return DBPLUGIN_UNKNOWN_ERROR; - - case CR_COMMANDS_OUT_OF_SYNC: - return DBPLUGIN_API_SPECIFIC_ERROR; - } - - ClearResult(); - m_curResult = mysql_store_result(m_myData); - - if ( m_curResult == NULL ) - { - int resultError = mysql_errno(m_myData); - - switch ( resultError ) - { - case 0: - return DBPLUGIN_RESULT_NOQUERYRES; - - case CR_SERVER_GONE_ERROR: - case CR_SERVER_LOST: - return DBPLUGIN_SERVER_LOST_ERROR; - - case CR_OUT_OF_MEMORY: - return DBPLUGIN_API_SPECIFIC_ERROR; - } - - return DBPLUGIN_UNKNOWN_ERROR; - } - - return 0; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int MySqlConnection::LastQueryNumFields() -{ - if ( m_myData != NULL && m_curResult != NULL ) - { - return mysql_num_fields(m_curResult); - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int MySqlConnection::LastQueryFetchFields(fieldarray_t * fields) -{ - if ( m_myData != NULL && m_curResult != NULL ) - { - MYSQL_FIELD *msFields = mysql_fetch_fields(m_curResult); - int numField = mysql_num_fields(m_curResult); - - for ( int i = 0; i < numField; i++ ) - { - strncpy(fields[i].name, msFields[i].name, (MAX_FIELD_NAME - 1)); - } - - return numField; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int MySqlConnection::LastQueryFetchRow(resultarray_t * results) -{ - if ( m_myData != NULL && m_curResult != NULL ) - { - MYSQL_ROW row = mysql_fetch_row(m_curResult); - if ( row == NULL ) - { - int resultError = mysql_errno(m_myData); - - switch ( resultError ) - { - case 0: - return 0; - - case CR_SERVER_LOST: - return DBPLUGIN_SERVER_LOST_ERROR; - } - - return DBPLUGIN_UNKNOWN_ERROR; - } - - int num_fields = mysql_num_fields(m_curResult); - - for ( int i = 0; i < num_fields; i++ ) - { - strncpy(results[i].data, row[i], (MAX_DATA_LENGTH - 1)); - } - - return num_fields; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int MySqlConnection::EscapeString(const char * inString, int inLength, char * outString) -{ - if ( IsConnected() ) - { - return mysql_real_escape_string(m_myData, outString, inString, inLength); - } - else - { - return mysql_escape_string(outString, inString, inLength); - } -} diff --git a/src/dbdll/mysql/MySqlConnection.h b/src/dbdll/mysql/MySqlConnection.h deleted file mode 100644 index 1e2363b9e..000000000 --- a/src/dbdll/mysql/MySqlConnection.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2006 Francesco Furiani - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _MYSQLCONNECTION_H -#define _MYSQLCONNECTION_H - -#define MIN_MYSQL_VERSION_ALLOW 40115 -#include "../common/SphereDatabasePlugin.h" - -class MySqlConnection -{ - // Static members -private: - static MySqlConnection * _mysqlConnection; - -public: - static MySqlConnection * GetCurrentInstance(void); - static void DestroyCurrentInstance(void); - - // Dynamic members -private: - bool m_connected; // are we online? - MYSQL * m_myData; // mySQL link - MYSQL_RES * m_curResult; // last result - -public: - MySqlConnection(); - ~MySqlConnection(); - - bool IsConnected(void); - void SetConnected(bool connected); - - unsigned long GetClientVersion(void); - int ServerPing(void); - - bool ServerDisconnect(void); - bool ServerConnect(const char * user, const char * password, const char * database, const char * host, int port); - - int GetLastError(void); - const char * GetLastStringError(void); - - int Execute(const char * statement); - int Query(const char * statement); - - int LastQueryNumFields(void); - int LastQueryFetchFields(fieldarray_t * fields); - int LastQueryFetchRow(resultarray_t * results); - - int EscapeString(const char * inString, int inLength, char * outString); - -private: - void ClearResult(void); - void InitMySqlData(void); - void ClearMySqlData(void); -}; - -#endif diff --git a/src/dbdll/mysql/MySqlPlugin.cpp b/src/dbdll/mysql/MySqlPlugin.cpp deleted file mode 100644 index 37e1d6ca2..000000000 --- a/src/dbdll/mysql/MySqlPlugin.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2006 Francesco Furiani - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "stdafx.h" -#include "MySqlConnection.h" - -// DLLs specific things -#ifdef _WIN32 -BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) -{ - UNREFERENCED_PARAMETER(hModule); - UNREFERENCED_PARAMETER(lpReserved); - - switch (ul_reason_for_call) - { - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - break; - - case DLL_PROCESS_ATTACH: - { - MySqlConnection::GetCurrentInstance(); - } break; - - case DLL_PROCESS_DETACH: - { - MySqlConnection::DestroyCurrentInstance(); - } break; - } - - return TRUE; -} -#else -void __attribute__((constructor)) dll_init() -{ - MySqlConnection::GetCurrentInstance(); -} - -void __attribute__((destructor)) dll_fini() -{ - MySqlConnection::DestroyCurrentInstance(); -} -#endif - -// Exported things -DBDLL_API bool __CALLTYPE db_isrightversion(void) -{ - return (MySqlConnection::GetCurrentInstance()->GetClientVersion() >= MIN_MYSQL_VERSION_ALLOW); -} - -DBDLL_API int __CALLTYPE db_ping(void) -{ - return MySqlConnection::GetCurrentInstance()->ServerPing(); -} - -DBDLL_API bool __CALLTYPE db_close(void) -{ - return MySqlConnection::GetCurrentInstance()->ServerDisconnect(); -} - -DBDLL_API bool __CALLTYPE db_isconnected(void) -{ - return MySqlConnection::GetCurrentInstance()->IsConnected(); -} - -DBDLL_API int __CALLTYPE db_getlasterror(void) -{ - return MySqlConnection::GetCurrentInstance()->GetLastError(); -} - -DBDLL_API const char * __CALLTYPE db_getlaststringerror(void) -{ - return MySqlConnection::GetCurrentInstance()->GetLastStringError(); -} - -DBDLL_API bool __CALLTYPE db_connect(const char ** args, int argc) -{ - if (argc < 5) - return false; - - return MySqlConnection::GetCurrentInstance()->ServerConnect(args[0], args[1], args[2], args[3], atoi(args[4])); -} - -DBDLL_API int __CALLTYPE db_execute(const char * query) -{ - return MySqlConnection::GetCurrentInstance()->Execute(query); -} - -DBDLL_API int __CALLTYPE db_query(const char * query) -{ - return MySqlConnection::GetCurrentInstance()->Query(query); -} - -DBDLL_API int __CALLTYPE db_fetchfields(fieldarray_t * fields) -{ - return MySqlConnection::GetCurrentInstance()->LastQueryFetchFields(fields); -} - -DBDLL_API int __CALLTYPE db_numfields(void) -{ - return MySqlConnection::GetCurrentInstance()->LastQueryNumFields(); -} - -DBDLL_API int __CALLTYPE db_fetchrow(resultarray_t * results) -{ - return MySqlConnection::GetCurrentInstance()->LastQueryFetchRow(results); -} - -DBDLL_API int __CALLTYPE db_escapestring(const char * inString, int inLength, char * outString) -{ - return MySqlConnection::GetCurrentInstance()->EscapeString(inString, inLength, outString); -} diff --git a/src/dbdll/mysql/makefile b/src/dbdll/mysql/makefile deleted file mode 100644 index 3be477d34..000000000 --- a/src/dbdll/mysql/makefile +++ /dev/null @@ -1,25 +0,0 @@ -# MySQL Plugin - -PLUGIN = mysql.so -include ../makefile.common - -INCLUDE := $(INCLUDE) -I/usr/include/mysql -LIBS := $(LIBS) -lmysqlclient - -SRC := MySqlConnection.cpp \ - MySqlPlugin.cpp \ - stdafx.cpp - -# Targets - -clean: tidy - rm -f *.o ../bin/$(PLUGIN) - -tidy: - rm -f *~ *orig *bak *rej - -plugin: $(SRC:.cpp=.o) $(SRC:.c=.co) - -$(PLUGIN): flags plugin - @$(CC) $(O_FLAGS) $(C_FLAGS) $(INCLUDE) $(LIBS) -o ../bin/$(PLUGIN) *.o - diff --git a/src/dbdll/mysql/mysql.vcxproj b/src/dbdll/mysql/mysql.vcxproj deleted file mode 100644 index 862539aeb..000000000 --- a/src/dbdll/mysql/mysql.vcxproj +++ /dev/null @@ -1,90 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {751A388A-1B1C-4EC9-9ACD-18AB69F023C7} - mysql - - - - DynamicLibrary - true - MultiByte - v120 - - - DynamicLibrary - false - true - MultiByte - v120 - - - - - - - - - - - - - $(SolutionDir)bin\$(Configuration)\ - - - $(SolutionDir)bin\$(Configuration)\ - - - - Level3 - Disabled - ../external/mysql/include - _MBCS;WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - ../external/mysql/lib/debug - ../common/SphereDatabasePlugin.def - - - - - Level4 - MaxSpeed - true - true - ../external/mysql/include - _MBCS;WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - false - true - true - ../external/mysql/lib/release - ../common/SphereDatabasePlugin.def - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/dbdll/mysql/mysql.vcxproj.filters b/src/dbdll/mysql/mysql.vcxproj.filters deleted file mode 100644 index 0a18e4f4f..000000000 --- a/src/dbdll/mysql/mysql.vcxproj.filters +++ /dev/null @@ -1,39 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/src/dbdll/mysql/stdafx.cpp b/src/dbdll/mysql/stdafx.cpp deleted file mode 100644 index 52c67eee1..000000000 --- a/src/dbdll/mysql/stdafx.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2006 Francesco Furiani - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "stdafx.h" diff --git a/src/dbdll/mysql/stdafx.h b/src/dbdll/mysql/stdafx.h deleted file mode 100644 index 72ae8b094..000000000 --- a/src/dbdll/mysql/stdafx.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2006 Francesco Furiani - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _STDAFX_H -#define _STDAFX_H - -#ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#endif - -#include -#include - -#ifdef _WIN32 - #include - #include - typedef int socklen_t; -#else - #include - #include - #include - #include - #include - #include - #include - - // Compatibility stuff. - #define INVALID_SOCKET (SOCKET)(~0) - #define SOCKET_ERROR (-1) - #define SOCKET int - #define TCP_NODELAY 0x0001 -#endif - -#ifndef UNREFERENCED_PARAMETER - #define UNREFERENCED_PARAMETER(P) (void)(P) -#endif - -#include -#include - -#ifdef _WIN32 - #pragma comment(lib, "libmySQL") -#else - #pragma comment(lib, "libmysqlclient") -#endif - -#endif diff --git a/src/dbdll/odbc/OdbcConnection.cpp b/src/dbdll/odbc/OdbcConnection.cpp deleted file mode 100644 index a9bedd479..000000000 --- a/src/dbdll/odbc/OdbcConnection.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright (c) 2010 Thomas Lowe - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "stdafx.h" -#include "OdbcConnection.h" - -OdbcConnection * OdbcConnection::_instance = NULL; - -OdbcConnection * OdbcConnection::GetCurrentInstance() -{ - if ( OdbcConnection::_instance == NULL ) - { - OdbcConnection::_instance = new OdbcConnection(); - } - - return OdbcConnection::_instance; -} - -void OdbcConnection::DestroyCurrentInstance() -{ - if ( OdbcConnection::_instance != NULL ) - { - delete OdbcConnection::_instance; - OdbcConnection::_instance = NULL; - } -} - -OdbcConnection::OdbcConnection() -{ - m_odbc = NULL; - m_connection = NULL; - m_statement = NULL; - m_lastError = 0; - m_lastErrorText[0] = '\0'; - m_lastErrorWasConnection = false; - m_lastErrorWasDriver = false; - m_lastErrorWasOdbc = false; - - SetConnected(false); -} - -OdbcConnection::~OdbcConnection() -{ - ClearResult(); - ClearOdbcData(); - - SetConnected(false); -} - -void OdbcConnection::ClearResult() -{ - if ( m_statement != NULL ) - { - SQLFreeHandle(SQL_HANDLE_STMT, m_statement); - m_statement = NULL; - } -} - -void OdbcConnection::InitOdbcData() -{ - if ( m_odbc == NULL ) - { - SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_odbc); - SQLSetEnvAttr(m_odbc, SQL_ATTR_ODBC_VERSION, (void*) SQL_OV_ODBC3, 0); - } - - if ( m_connection == NULL ) - { - SQLAllocHandle(SQL_HANDLE_DBC, m_odbc, &m_connection); - } -} - -void OdbcConnection::ClearOdbcData() -{ - if ( m_connection != NULL ) - { - SQLDisconnect(m_connection); - SQLFreeHandle(SQL_HANDLE_DBC, m_connection); - m_connection = NULL; - } - - if ( m_odbc != NULL ) - { - SQLFreeHandle(SQL_HANDLE_ENV, m_odbc); - m_odbc = NULL; - } -} - -bool OdbcConnection::IsConnected() -{ - return m_connected; -} - -void OdbcConnection::SetConnected( bool connected ) -{ - m_connected = connected; -} - -bool OdbcConnection::ServerDisconnect() -{ - ClearResult(); - ClearOdbcData(); - - SetConnected(false); - - return IsConnected(); -} - -bool OdbcConnection::ServerConnect(const char * user, const char * password, const char * database, const char * hostip, int hostport) -{ - UNREFERENCED_PARAMETER(hostport); - UNREFERENCED_PARAMETER(hostip); - - InitOdbcData(); - - // SQLConnect expects non-const pointers which we can't/shouldn't cast away, so - // we'll need to copy the strings to our own variables... - char * temp_servername = new char[strlen(database) + 1]; - char * temp_username = new char[strlen(user) + 1]; - char * temp_authentication = new char[strlen(password) + 1]; - - std::strcpy(temp_servername, database); - std::strcpy(temp_username, user); - std::strcpy(temp_authentication, password); - - SQLRETURN result = SQLConnect(m_connection, reinterpret_cast(temp_servername), SQL_NTS, reinterpret_cast(temp_username), SQL_NTS, reinterpret_cast(temp_authentication), SQL_NTS); - SetLastError(SQL_HANDLE_DBC, m_connection, result); - - if (SQL_SUCCEEDED(result)) - { - SetConnected(true); - } - else - { - ServerDisconnect(); - } - - delete[] temp_servername; - delete[] temp_username; - delete[] temp_authentication; - - return IsConnected(); -} - -void OdbcConnection::SetLastError(SQLSMALLINT handleType, SQLHANDLE handle, SQLRETURN result) -{ - // clear last error - m_lastError = 0; - m_lastErrorText[0] = '\0'; - m_lastErrorWasConnection = false; - m_lastErrorWasDriver = false; - m_lastErrorWasOdbc = false; - - // check if failure occurred - if (SQL_SUCCEEDED(result) == false) - { - SQLSMALLINT i = 0; - SQLINTEGER native; - SQLSTATE state; - SQLCHAR text[256]; - SQLSMALLINT textLength; - - std::string errorText; - errorText.reserve(MAX_DATA_LENGTH); - - for (;;) - { - SQLRETURN result = SQLGetDiagRec(handleType, handle, ++i, state, &native, text, sizeof(text) / sizeof(text[0]), &textLength); - if (SQL_SUCCEEDED(result) == false) - break; - - if (i == 1) - m_lastError = native; - else - errorText.append(1, '\n'); - - // since we can receive multiple error states from a single operation (and in - // no particular order), the best approach seems to be to flag which error - // types have shown up - if ( strncmp(reinterpret_cast((state)), ODBCERR_CLASS_CONNECTION, SQLSTATE_CLASS_LENGTH) == 0 ) - m_lastErrorWasConnection = true; - if ( strncmp(reinterpret_cast((state)), ODBCERR_CLASS_DRIVER, SQLSTATE_CLASS_LENGTH) == 0 ) - m_lastErrorWasDriver = true; - if ( strncmp(reinterpret_cast((state)), ODBCERR_CLASS_ODBC, SQLSTATE_CLASS_LENGTH) == 0 ) - m_lastErrorWasOdbc = true; - - // build error messages (prepend with odbc error state) - errorText.append("["); - errorText.append(reinterpret_cast(state)); - errorText.append(1, ']'); - errorText.append(reinterpret_cast(text)); - } - - // copy error - std::string::size_type length = errorText.copy(m_lastErrorText, MAX_DATA_LENGTH - 1); - m_lastErrorText[length] = '\0'; - } -} - -int OdbcConnection::GetLastError() -{ - return m_lastError; -} - -const char * OdbcConnection::GetLastStringError() -{ - return m_lastErrorText; -} - -int OdbcConnection::Execute(const char * statement) -{ - if ( m_odbc != NULL && m_connection != NULL && statement != NULL && *statement != '\0' ) - { - ClearResult(); - - // SQLExecDirect expects a non-const string, so we'll need to copy it - char * temp_statement = new char[strlen(statement) + 1]; - std::strcpy(temp_statement, statement); - - // execute the statement - SQLAllocHandle(SQL_HANDLE_STMT, m_connection, &m_statement); - SQLRETURN result = SQLExecDirect(m_statement, reinterpret_cast(temp_statement), SQL_NTS); - SetLastError(SQL_HANDLE_STMT, m_statement, result); - - delete[] temp_statement; - - // check success - if (SQL_SUCCEEDED(result) == false) - { - if (m_lastErrorWasConnection) - return DBPLUGIN_SERVER_LOST_ERROR; - - if (m_lastErrorWasDriver || m_lastErrorWasOdbc) - return DBPLUGIN_INTERNAL_ERROR; - - return DBPLUGIN_API_SPECIFIC_ERROR; - } - - return 0; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int OdbcConnection::Query(const char * statement) -{ - if ( m_odbc != NULL && m_connection != NULL && statement != NULL && *statement != '\0' ) - { - ClearResult(); - - // SQLExecDirect expects a non-const string, so we'll need to copy it - char * temp_statement = new char[strlen(statement) + 1]; - std::strcpy(temp_statement, statement); - - // execute statement - SQLAllocHandle(SQL_HANDLE_STMT, m_connection, &m_statement); - SQLRETURN result = SQLExecDirect(m_statement, reinterpret_cast(temp_statement), SQL_NTS); - SetLastError(SQL_HANDLE_STMT, m_statement, result); - - delete[] temp_statement; - - // check success - if (SQL_SUCCEEDED(result) == false) - { - if (m_lastErrorWasConnection) - return DBPLUGIN_SERVER_LOST_ERROR; - - if (m_lastErrorWasDriver || m_lastErrorWasOdbc) - return DBPLUGIN_INTERNAL_ERROR; - - return DBPLUGIN_API_SPECIFIC_ERROR; - } - - return 0; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int OdbcConnection::LastQueryNumFields() -{ - if ( m_odbc != NULL && m_connection != NULL && m_statement != NULL ) - { - SQLSMALLINT fields = 0; - SQLNumResultCols(m_statement, &fields); - return fields; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int OdbcConnection::LastQueryFetchFields(fieldarray_t * fields) -{ - if ( m_odbc != NULL && m_connection != NULL && m_statement != NULL ) - { - SQLSMALLINT numField = 0; - SQLNumResultCols(m_statement, &numField); - - for ( SQLSMALLINT i = 0; i < numField; i++ ) - { - SQLDescribeCol(m_statement, i + 1, reinterpret_cast(fields[i].name), (MAX_FIELD_NAME - 1), NULL, NULL, NULL, NULL, NULL); - } - - return numField; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int OdbcConnection::LastQueryFetchRow(resultarray_t * results) -{ - if ( m_odbc != NULL && m_connection != NULL && m_statement != NULL ) - { - SQLRETURN result = SQLFetch(m_statement); - SetLastError(SQL_HANDLE_STMT, m_statement, result); - if (SQL_SUCCEEDED(result) == false) - { - if (m_lastErrorWasConnection) - return DBPLUGIN_SERVER_LOST_ERROR; - - if (m_lastErrorWasDriver || m_lastErrorWasOdbc) - return DBPLUGIN_INTERNAL_ERROR; - - return DBPLUGIN_UNKNOWN_ERROR;; - } - - SQLSMALLINT num_fields = 0; - SQLNumResultCols(m_statement, &num_fields); - - for ( SQLSMALLINT i = 0; i < num_fields; i++ ) - { - SQLINTEGER indicator; - - result = SQLGetData(m_statement, i + 1, SQL_C_CHAR, results[i].data, (MAX_DATA_LENGTH - 1), &indicator); - SetLastError(SQL_HANDLE_STMT, m_statement, result); - if (SQL_SUCCEEDED(result) == false || indicator == SQL_NULL_DATA) - std::strcpy(results[i].data, ""); - } - - return num_fields; - } - - return DBPLUGIN_INTERNAL_ERROR; -} - -int OdbcConnection::EscapeString(const char * inString, int inLength, char * outString) -{ - // note: ODBC may not actually have a built-in way to escape a string, it seems the recommended - // approach is to bind parameters to a query instead. - - // for now, use the ms-sql style of double-quoting apostrophes (this might not - // be correctly translated for different providers (e.g. mysql)) - std::string s(inString, inLength); - for (std::string::size_type pos = 0; (pos = s.find('\'', pos)) != s.npos; pos += 2) - s.replace(pos, 1, 2, '\''); - - s.copy(outString, s.length()); - outString[s.length()] = '\0'; - return s.length(); -} diff --git a/src/dbdll/odbc/OdbcConnection.h b/src/dbdll/odbc/OdbcConnection.h deleted file mode 100644 index ab0559fd4..000000000 --- a/src/dbdll/odbc/OdbcConnection.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2010 Thomas Lowe - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _ODBCCONNECTION_H -#define _ODBCCONNECTION_H - -#include "../common/SphereDatabasePlugin.h" - -#ifndef _WIN32 -typedef SQLTCHAR SQLSTATE[6]; -#endif - -// The first 2 characters of SQLSTATE is the error class, -// these are the ones we might be interested in -#define ODBCERR_CLASS_CONNECTION "08" // connection error -#define ODBCERR_CLASS_DRIVER "HY" // driver error -#define ODBCERR_CLASS_ODBC "IM" // odbc error -#define SQLSTATE_CLASS_LENGTH 2 - -class OdbcConnection -{ - // Static members -private: - static OdbcConnection * _instance; - -public: - static OdbcConnection * GetCurrentInstance(void); - static void DestroyCurrentInstance(void); - - // Dynamic members -private: - bool m_connected; // are we online? - SQLHANDLE m_odbc; // ODBC link - SQLHANDLE m_connection; // database connection - SQLHANDLE m_statement; // current statement - - SQLINTEGER m_lastError; // error code from latest operation - char m_lastErrorText[MAX_DATA_LENGTH]; // error text from latest operation - bool m_lastErrorWasConnection; // indicates last operation produced a connection error - bool m_lastErrorWasDriver; // indicates last operation produced a driver error - bool m_lastErrorWasOdbc; // indicates last operation produced an odbc error - -public: - OdbcConnection(); - ~OdbcConnection(); - - bool IsConnected(void); - void SetConnected(bool connected); - - bool ServerDisconnect(void); - bool ServerConnect(const char * user, const char * password, const char * database, const char * host, int port); - - int GetLastError(void); - const char * GetLastStringError(void); - - int Execute(const char * statement); - int Query(const char * statement); - - int LastQueryNumFields(void); - int LastQueryFetchFields(fieldarray_t * fields); - int LastQueryFetchRow(resultarray_t * results); - - int EscapeString(const char * inString, int inLength, char * outString); - -private: - void ClearResult(void); - void InitOdbcData(void); - void ClearOdbcData(void); - void SetLastError(SQLSMALLINT handleType, SQLHANDLE handle, SQLRETURN result); -}; - -#endif diff --git a/src/dbdll/odbc/OdbcPlugin.cpp b/src/dbdll/odbc/OdbcPlugin.cpp deleted file mode 100644 index 1e76e0cc4..000000000 --- a/src/dbdll/odbc/OdbcPlugin.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2010 Thomas Lowe - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "stdafx.h" -#include "OdbcConnection.h" - -// DLLs specific things -#ifdef _WIN32 -BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) -{ - UNREFERENCED_PARAMETER(hModule); - UNREFERENCED_PARAMETER(lpReserved); - - switch (ul_reason_for_call) - { - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - break; - - case DLL_PROCESS_ATTACH: - { - OdbcConnection::GetCurrentInstance(); - } break; - - case DLL_PROCESS_DETACH: - { - OdbcConnection::DestroyCurrentInstance(); - } break; - } - - return TRUE; -} -#else -void __attribute__((constructor)) dll_init() -{ - OdbcConnection::GetCurrentInstance(); -} - -void __attribute__((destructor)) dll_fini() -{ - OdbcConnection::DestroyCurrentInstance(); -} -#endif - -// Exported things -DBDLL_API bool __CALLTYPE db_isrightversion(void) -{ - // not applicable to odbc - return true; -} - -DBDLL_API int __CALLTYPE db_ping(void) -{ - // not applicable to odbc - return 0; -} - -DBDLL_API bool __CALLTYPE db_close(void) -{ - return OdbcConnection::GetCurrentInstance()->ServerDisconnect(); -} - -DBDLL_API bool __CALLTYPE db_isconnected(void) -{ - return OdbcConnection::GetCurrentInstance()->IsConnected(); -} - -DBDLL_API int __CALLTYPE db_getlasterror(void) -{ - return OdbcConnection::GetCurrentInstance()->GetLastError(); -} - -DBDLL_API const char * __CALLTYPE db_getlaststringerror(void) -{ - return OdbcConnection::GetCurrentInstance()->GetLastStringError(); -} - -DBDLL_API bool __CALLTYPE db_connect(const char ** args, int argc) -{ - if (argc < 5) - return false; - - return OdbcConnection::GetCurrentInstance()->ServerConnect(args[0], args[1], args[2], args[3], atoi(args[4])); -} - -DBDLL_API int __CALLTYPE db_execute(const char * query) -{ - return OdbcConnection::GetCurrentInstance()->Execute(query); -} - -DBDLL_API int __CALLTYPE db_query(const char * query) -{ - return OdbcConnection::GetCurrentInstance()->Query(query); -} - -DBDLL_API int __CALLTYPE db_fetchfields(fieldarray_t * fields) -{ - return OdbcConnection::GetCurrentInstance()->LastQueryFetchFields(fields); -} - -DBDLL_API int __CALLTYPE db_numfields(void) -{ - return OdbcConnection::GetCurrentInstance()->LastQueryNumFields(); -} - -DBDLL_API int __CALLTYPE db_fetchrow(resultarray_t * results) -{ - return OdbcConnection::GetCurrentInstance()->LastQueryFetchRow(results); -} - -DBDLL_API int __CALLTYPE db_escapestring(const char * inString, int inLength, char * outString) -{ - return OdbcConnection::GetCurrentInstance()->EscapeString(inString, inLength, outString); -} diff --git a/src/dbdll/odbc/makefile b/src/dbdll/odbc/makefile deleted file mode 100644 index a3d6048da..000000000 --- a/src/dbdll/odbc/makefile +++ /dev/null @@ -1,25 +0,0 @@ -# ODBC Plugin - -PLUGIN = odbc.so -include ../makefile.common - -INCLUDE := $(INCLUDE) -LIBS := $(LIBS) -lodbc - -SRC := OdbcConnection.cpp \ - OdbcPlugin.cpp \ - stdafx.cpp - -# Targets - -clean: tidy - rm -f *.o ../bin/$(PLUGIN) - -tidy: - rm -f *~ *orig *bak *rej - -plugin: $(SRC:.cpp=.o) $(SRC:.c=.co) - -$(PLUGIN): flags plugin - @$(CC) $(O_FLAGS) $(C_FLAGS) $(INCLUDE) $(LIBS) -o ../bin/$(PLUGIN) *.o - diff --git a/src/dbdll/odbc/odbc.vcxproj b/src/dbdll/odbc/odbc.vcxproj deleted file mode 100644 index 0af151ecb..000000000 --- a/src/dbdll/odbc/odbc.vcxproj +++ /dev/null @@ -1,86 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {89B82F5E-76B0-4C11-96D8-0A5F3DD21977} - odbc - - - - DynamicLibrary - true - MultiByte - v120 - - - DynamicLibrary - false - true - MultiByte - v120 - - - - - - - - - - - - - $(SolutionDir)bin\$(Configuration)\ - - - $(SolutionDir)bin\$(Configuration)\ - - - - Level3 - Disabled - _MBCS;WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - ../common/SphereDatabasePlugin.def - - - - - Level4 - MaxSpeed - true - true - _MBCS;WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - false - true - true - ../common/SphereDatabasePlugin.def - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/dbdll/odbc/odbc.vcxproj.filters b/src/dbdll/odbc/odbc.vcxproj.filters deleted file mode 100644 index a42a24971..000000000 --- a/src/dbdll/odbc/odbc.vcxproj.filters +++ /dev/null @@ -1,39 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/src/dbdll/odbc/stdafx.cpp b/src/dbdll/odbc/stdafx.cpp deleted file mode 100644 index 625e745b7..000000000 --- a/src/dbdll/odbc/stdafx.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2010 Thomas Lowe - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#include "stdafx.h" diff --git a/src/dbdll/odbc/stdafx.h b/src/dbdll/odbc/stdafx.h deleted file mode 100644 index 00a518662..000000000 --- a/src/dbdll/odbc/stdafx.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2010 Thomas Lowe - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * Except as contained in this notice, the name(s) of the above - * copyright holders shall not be used in advertising or otherwise - * to promote the sale, use or other dealings in this Software - * without prior written authorization. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _STDAFX_H -#define _STDAFX_H - -#ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -#endif - -#include -#include -#include - -#ifdef _WIN32 - #include -#else - #include - #include - #include - #include - #include - #include - #include - - // Compatibility stuff. - #define INVALID_SOCKET (SOCKET)(~0) - #define SOCKET_ERROR (-1) - #define SOCKET int - #define TCP_NODELAY 0x0001 -#endif - -#ifndef UNREFERENCED_PARAMETER - #define UNREFERENCED_PARAMETER(P) (void)(P) -#endif - -#include -#include -#include - -#endif