diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 864f5d30..bd5c506c 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -450,6 +450,9 @@ if(FRAMEWORK_SQL) set(framework_LIBRARIES ${framework_LIBRARIES} ${MYSQL_LIBRARY}) set(framework_SOURCES ${framework_SOURCES} + ${CMAKE_CURRENT_LIST_DIR}/sql/declarations.h + ${CMAKE_CURRENT_LIST_DIR}/sql/database.cpp + ${CMAKE_CURRENT_LIST_DIR}/sql/database.h ${CMAKE_CURRENT_LIST_DIR}/sql/mysql.cpp ${CMAKE_CURRENT_LIST_DIR}/sql/mysql.h ) diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 915f2ba4..8de02cea 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -45,6 +45,10 @@ #include #endif +#ifdef FW_SQL +#include +#endif + void Application::registerLuaFunctions() { // conversion globals @@ -700,4 +704,14 @@ void Application::registerLuaFunctions() g_lua.bindSingletonFunction("g_sounds", "isAudioEnabled", &SoundManager::isAudioEnabled, &g_sounds); g_lua.bindSingletonFunction("g_sounds", "getCurrentMusic", &SoundManager::getCurrentMusic, &g_sounds); #endif + +#ifdef FW_SQL + // Database + g_lua.registerClass(); + + // Mysql + g_lua.registerClass(); + g_lua.bindClassStaticFunction("create", []{ return DatabaseMySQLPtr(new DatabaseMySQL); }); + g_lua.bindClassMemberFunction("connect", &DatabaseMySQL::connect); +#endif } diff --git a/src/framework/sql/database.cpp b/src/framework/sql/database.cpp new file mode 100644 index 00000000..c137b88e --- /dev/null +++ b/src/framework/sql/database.cpp @@ -0,0 +1,9 @@ +#include "database.h" + +Database::Database() +{ +} + +Database::~Database() +{ +} diff --git a/src/framework/sql/database.h b/src/framework/sql/database.h new file mode 100644 index 00000000..bf26e55a --- /dev/null +++ b/src/framework/sql/database.h @@ -0,0 +1,15 @@ +#ifndef DATABASE_H +#define DATABASE_H + +#include "declarations.h" +#include +#include + +class Database : public LuaObject +{ +public: + Database(); + ~Database(); +}; + +#endif diff --git a/src/framework/sql/declarations.h b/src/framework/sql/declarations.h new file mode 100644 index 00000000..72b1e441 --- /dev/null +++ b/src/framework/sql/declarations.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010-2012 OTClient + * + * 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. + * + * 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 FRAMEWORK_SQL_DECLARATIONS_H +#define FRAMEWORK_SQL_DECLARATIONS_H + +#include + +class DatabaseMySQL; + +typedef stdext::shared_object_ptr DatabaseMySQLPtr; + +#endif diff --git a/src/framework/sql/mysql.h b/src/framework/sql/mysql.h index 3a8b1222..e7b12c7e 100644 --- a/src/framework/sql/mysql.h +++ b/src/framework/sql/mysql.h @@ -1,6 +1,7 @@ -#ifndef DATABASE_H -#define DATABASE_H +#ifndef DATABASEMYSQL_H +#define DATABASEMYSQL_H +#include "database.h" #include #ifdef WIN32 #include @@ -9,7 +10,7 @@ class DBResult; -class DatabaseMySQL +class DatabaseMySQL : public Database { public: DatabaseMySQL();