From 79118ee00f36b6122a50d57f506f05f9e94a6b40 Mon Sep 17 00:00:00 2001 From: rextimmy Date: Thu, 31 Aug 2017 21:07:23 +1000 Subject: [PATCH 1/3] sqlite fixes --- Engine/{source => lib}/sqlite/sqlite3.c | 0 Engine/{source => lib}/sqlite/sqlite3.h | 0 Engine/{source => lib}/sqlite/sqlite3ext.h | 0 .../{SQLiteObject.cc => SQLiteObject.cpp} | 86 +++++++++---------- Engine/source/sqlite/SQLiteObject.h | 34 ++++---- Tools/CMake/libraries/sqlite.cmake | 28 ++++++ Tools/CMake/modules/module_sqlite.cmake | 11 +-- 7 files changed, 90 insertions(+), 69 deletions(-) rename Engine/{source => lib}/sqlite/sqlite3.c (100%) rename Engine/{source => lib}/sqlite/sqlite3.h (100%) rename Engine/{source => lib}/sqlite/sqlite3ext.h (100%) rename Engine/source/sqlite/{SQLiteObject.cc => SQLiteObject.cpp} (92%) create mode 100644 Tools/CMake/libraries/sqlite.cmake diff --git a/Engine/source/sqlite/sqlite3.c b/Engine/lib/sqlite/sqlite3.c similarity index 100% rename from Engine/source/sqlite/sqlite3.c rename to Engine/lib/sqlite/sqlite3.c diff --git a/Engine/source/sqlite/sqlite3.h b/Engine/lib/sqlite/sqlite3.h similarity index 100% rename from Engine/source/sqlite/sqlite3.h rename to Engine/lib/sqlite/sqlite3.h diff --git a/Engine/source/sqlite/sqlite3ext.h b/Engine/lib/sqlite/sqlite3ext.h similarity index 100% rename from Engine/source/sqlite/sqlite3ext.h rename to Engine/lib/sqlite/sqlite3ext.h diff --git a/Engine/source/sqlite/SQLiteObject.cc b/Engine/source/sqlite/SQLiteObject.cpp similarity index 92% rename from Engine/source/sqlite/SQLiteObject.cc rename to Engine/source/sqlite/SQLiteObject.cpp index 1832dc112..cd20b93f3 100644 --- a/Engine/source/sqlite/SQLiteObject.cc +++ b/Engine/source/sqlite/SQLiteObject.cpp @@ -36,17 +36,17 @@ #include "console/engineAPI.h" #include "console/consoleInternal.h" -#include +#include IMPLEMENT_CONOBJECT(SQLiteObject); SQLiteObject::SQLiteObject() { - m_pDatabase = NULL; - m_szErrorString = NULL; - m_iLastResultSet = 0; - m_iNextResultSet = 1; + m_pDatabase = NULL; + m_szErrorString = NULL; + m_iLastResultSet = 0; + m_iNextResultSet = 1; } SQLiteObject::~SQLiteObject() @@ -63,8 +63,8 @@ SQLiteObject::~SQLiteObject() // So (HACK HACK HACK) what i'm doing for now is making a temporary vector that // contains a list of the result sets that the user hasn't cleaned up. // Clean up all those result sets, then delete the temp vector. - Vector vTemp; - Vector::iterator iTemp; + Vector vTemp; + Vector::iterator iTemp; VectorPtr::iterator i; for (i = m_vResultSets.begin(); i != m_vResultSets.end(); i++) @@ -89,8 +89,6 @@ bool SQLiteObject::processArguments(S32 argc, const char **argv) return true; else return true; - - return false; } bool SQLiteObject::onAdd() @@ -131,7 +129,7 @@ void SQLiteObject::initPersistFields() // These functions below are our custom functions that we will tie into // script. -int Callback(void *pArg, int argc, char **argv, char **columnNames) +S32 Callback(void *pArg, S32 argc, char **argv, char **columnNames) { // basically this callback is called for each row in the SQL query result. // for each row, argc indicates how many columns are returned. @@ -142,7 +140,7 @@ int Callback(void *pArg, int argc, char **argv, char **columnNames) sqlite_resultset* pResultSet; char* name; char* value; - int i; + S32 i; if (argc == 0) return 0; @@ -196,7 +194,7 @@ bool SQLiteObject::OpenDatabase(const char* filename) // we need to clear what we have to avoid a memory leak. ClearErrorString(); - int isOpen = sqlite3_open(filename, &m_pDatabase); + S32 isOpen = sqlite3_open(filename, &m_pDatabase); if (isOpen == SQLITE_ERROR) { // there was an error and the database could not @@ -211,16 +209,16 @@ bool SQLiteObject::OpenDatabase(const char* filename) Con::executef(this, "1", "onOpened()"); //Now, for OpenSimEarth, load spatialite dll, so we can have GIS functions. - //int canLoadExt = sqlite3_load_extension(m_pDatabase,"mod_spatialite.dll",0,0); + //S32 canLoadExt = sqlite3_load_extension(m_pDatabase,"mod_spatialite.dll",0,0); //Con::printf("opened spatialite extension: %d",canLoadExt); //Sigh, no luck yet. Cannot find function GeomFromText(). } return true; } -int SQLiteObject::ExecuteSQL(const char* sql) +S32 SQLiteObject::ExecuteSQL(const char* sql) { - int iResult; + S32 iResult; sqlite_resultset* pResultSet; // create a new resultset @@ -287,8 +285,9 @@ void SQLiteObject::CloseDatabase() ** If the operation is successful, SQLITE_OK is returned. Otherwise, if ** an error occurs, an SQLite error code is returned. */ -int SQLiteObject::loadOrSaveDb(const char *zFilename, bool isSave) { - int rc; /* Function return code */ +S32 SQLiteObject::loadOrSaveDb(const char *zFilename, bool isSave) +{ + S32 rc; /* Function return code */ sqlite3 *pFile; /* Database connection opened on zFilename */ sqlite3_backup *pBackup; /* Backup object used to copy data */ sqlite3 *pTo; /* Database to copy to (pFile or pInMemory) */ @@ -355,7 +354,7 @@ int SQLiteObject::loadOrSaveDb(const char *zFilename, bool isSave) { return false; } -void SQLiteObject::NextRow(int resultSet) +void SQLiteObject::NextRow(S32 resultSet) { sqlite_resultset* pResultSet; @@ -366,7 +365,7 @@ void SQLiteObject::NextRow(int resultSet) pResultSet->iCurrentRow++; } -bool SQLiteObject::EndOfResult(int resultSet) +bool SQLiteObject::EndOfResult(S32 resultSet) { sqlite_resultset* pResultSet; @@ -388,14 +387,13 @@ void SQLiteObject::ClearErrorString() m_szErrorString = NULL; } -void SQLiteObject::ClearResultSet(int index) +void SQLiteObject::ClearResultSet(S32 index) { if (index <= 0) return; sqlite_resultset* resultSet; - sqlite_resultrow* resultRow; - S32 rows, cols, iResultSet; + S32 iResultSet; // Get the result set specified by index resultSet = GetResultSet(index); @@ -436,7 +434,7 @@ void SQLiteObject::ClearResultSet(int index) m_vResultSets.erase_fast(iResultSet); } -sqlite_resultset* SQLiteObject::GetResultSet(int iResultSet) +sqlite_resultset* SQLiteObject::GetResultSet(S32 iResultSet) { // Get the result set specified by iResultSet VectorPtr::iterator i; @@ -449,9 +447,9 @@ sqlite_resultset* SQLiteObject::GetResultSet(int iResultSet) return *i; } -int SQLiteObject::GetResultSetIndex(int iResultSet) +S32 SQLiteObject::GetResultSetIndex(S32 iResultSet) { - int iIndex; + S32 iIndex; // Get the result set specified by iResultSet VectorPtr::iterator i; iIndex = 0; @@ -474,9 +472,9 @@ bool SQLiteObject::SaveResultSet(sqlite_resultset* pResultSet) return true; } -int SQLiteObject::GetColumnIndex(int iResult, const char* columnName) +S32 SQLiteObject::GetColumnIndex(S32 iResult, const char* columnName) { - int iIndex; + S32 iIndex; VectorPtr::iterator i; sqlite_resultset* pResultSet; sqlite_resultrow* pRow; @@ -500,7 +498,7 @@ int SQLiteObject::GetColumnIndex(int iResult, const char* columnName) return 0; } -int SQLiteObject::numResultSets() +S32 SQLiteObject::numResultSets() { return m_vResultSets.size(); } @@ -535,7 +533,7 @@ ConsoleMethod(SQLiteObject, closeDatabase, void, 2, 2, "Closes the active databa object->CloseDatabase(); } -ConsoleMethod(SQLiteObject, query, S32, 4, 0, "(const char* sql, int mode) Performs an SQL query on the open database and returns an identifier to a valid result set. mode is currently unused, and is reserved for future use.") +ConsoleMethod(SQLiteObject, query, S32, 4, 0, "(const char* sql, S32 mode) Performs an SQL query on the open database and returns an identifier to a valid result set. mode is currently unused, and is reserved for future use.") { S32 iCount; S32 iIndex, iLen, iNewIndex, iArg, iArgLen, i; @@ -614,12 +612,12 @@ ConsoleMethod(SQLiteObject, query, S32, 4, 0, "(const char* sql, int mode) Perfo return 0; } -ConsoleMethod(SQLiteObject, clearResult, void, 3, 3, "(int resultSet) Clears memory used by the specified result set, and deletes the result set.") +ConsoleMethod(SQLiteObject, clearResult, void, 3, 3, "(S32 resultSet) Clears memory used by the specified result set, and deletes the result set.") { object->ClearResultSet(dAtoi(argv[2])); } -ConsoleMethod(SQLiteObject, nextRow, void, 3, 3, "(int resultSet) Moves the result set's row pointer to the next row.") +ConsoleMethod(SQLiteObject, nextRow, void, 3, 3, "(S32 resultSet) Moves the result set's row pointer to the next row.") { sqlite_resultset* pResultSet; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -629,7 +627,7 @@ ConsoleMethod(SQLiteObject, nextRow, void, 3, 3, "(int resultSet) Moves the resu } } -ConsoleMethod(SQLiteObject, previousRow, void, 3, 3, "(int resultSet) Moves the result set's row pointer to the previous row") +ConsoleMethod(SQLiteObject, previousRow, void, 3, 3, "(S32 resultSet) Moves the result set's row pointer to the previous row") { sqlite_resultset* pResultSet; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -639,7 +637,7 @@ ConsoleMethod(SQLiteObject, previousRow, void, 3, 3, "(int resultSet) Moves the } } -ConsoleMethod(SQLiteObject, firstRow, void, 3, 3, "(int resultSet) Moves the result set's row pointer to the very first row in the result set.") +ConsoleMethod(SQLiteObject, firstRow, void, 3, 3, "(S32 resultSet) Moves the result set's row pointer to the very first row in the result set.") { sqlite_resultset* pResultSet; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -649,7 +647,7 @@ ConsoleMethod(SQLiteObject, firstRow, void, 3, 3, "(int resultSet) Moves the res } } -ConsoleMethod(SQLiteObject, lastRow, void, 3, 3, "(int resultSet) Moves the result set's row pointer to the very last row in the result set.") +ConsoleMethod(SQLiteObject, lastRow, void, 3, 3, "(S32 resultSet) Moves the result set's row pointer to the very last row in the result set.") { sqlite_resultset* pResultSet; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -659,7 +657,7 @@ ConsoleMethod(SQLiteObject, lastRow, void, 3, 3, "(int resultSet) Moves the resu } } -ConsoleMethod(SQLiteObject, setRow, void, 4, 4, "(int resultSet int row) Moves the result set's row pointer to the row specified. Row indices start at 1 not 0.") +ConsoleMethod(SQLiteObject, setRow, void, 4, 4, "(S32 resultSet S32 row) Moves the result set's row pointer to the row specified. Row indices start at 1 not 0.") { sqlite_resultset* pResultSet; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -669,7 +667,7 @@ ConsoleMethod(SQLiteObject, setRow, void, 4, 4, "(int resultSet int row) Moves t } } -ConsoleMethod(SQLiteObject, getRow, S32, 3, 3, "(int resultSet) Returns what row the result set's row pointer is currently on.") +ConsoleMethod(SQLiteObject, getRow, S32, 3, 3, "(S32 resultSet) Returns what row the result set's row pointer is currently on.") { sqlite_resultset* pResultSet; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -681,7 +679,7 @@ ConsoleMethod(SQLiteObject, getRow, S32, 3, 3, "(int resultSet) Returns what row return 0; } -ConsoleMethod(SQLiteObject, numRows, S32, 3, 3, "(int resultSet) Returns the number of rows in the result set.") +ConsoleMethod(SQLiteObject, numRows, S32, 3, 3, "(S32 resultSet) Returns the number of rows in the result set.") { sqlite_resultset* pResultSet; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -693,7 +691,7 @@ ConsoleMethod(SQLiteObject, numRows, S32, 3, 3, "(int resultSet) Returns the num return 0; } -ConsoleMethod(SQLiteObject, numColumns, S32, 3, 3, "(int resultSet) Returns the number of columns in the result set.") +ConsoleMethod(SQLiteObject, numColumns, S32, 3, 3, "(S32 resultSet) Returns the number of columns in the result set.") { sqlite_resultset* pResultSet; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -705,17 +703,17 @@ ConsoleMethod(SQLiteObject, numColumns, S32, 3, 3, "(int resultSet) Returns the return 0; } -ConsoleMethod(SQLiteObject, endOfResult, bool, 3, 3, "(int resultSet) Checks to see if the internal pointer for the specified result set is at the end, indicating there are no more rows left to read.") +ConsoleMethod(SQLiteObject, endOfResult, bool, 3, 3, "(S32 resultSet) Checks to see if the internal pointer for the specified result set is at the end, indicating there are no more rows left to read.") { return object->EndOfResult(dAtoi(argv[2])); } -ConsoleMethod(SQLiteObject, EOR, bool, 3, 3, "(int resultSet) Same as endOfResult().") +ConsoleMethod(SQLiteObject, EOR, bool, 3, 3, "(S32 resultSet) Same as endOfResult().") { return object->EndOfResult(dAtoi(argv[2])); } -ConsoleMethod(SQLiteObject, EOF, bool, 3, 3, "(int resultSet) Same as endOfResult().") +ConsoleMethod(SQLiteObject, EOF, bool, 3, 3, "(S32 resultSet) Same as endOfResult().") { return object->EndOfResult(dAtoi(argv[2])); } @@ -729,8 +727,6 @@ ConsoleMethod(SQLiteObject, getColumnName, const char *, 4, 4, "(resultSet colum { sqlite_resultset* pResultSet; sqlite_resultrow* pRow; - VectorPtr::iterator iName; - VectorPtr::iterator iValue; S32 iColumn; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -759,8 +755,6 @@ ConsoleMethod(SQLiteObject, getColumn, const char *, 4, 4, "(resultSet column) R { sqlite_resultset* pResultSet; sqlite_resultrow* pRow; - VectorPtr::iterator iName; - VectorPtr::iterator iValue; S32 iColumn; pResultSet = object->GetResultSet(dAtoi(argv[2])); @@ -802,8 +796,6 @@ ConsoleMethod(SQLiteObject, getColumnNumeric, F32, 4, 4, "(resultSet column) Ret { sqlite_resultset* pResultSet; sqlite_resultrow* pRow; - VectorPtr::iterator iName; - VectorPtr::iterator iValue; S32 iColumn; pResultSet = object->GetResultSet(dAtoi(argv[2])); diff --git a/Engine/source/sqlite/SQLiteObject.h b/Engine/source/sqlite/SQLiteObject.h index ec95304b7..e64836f7a 100644 --- a/Engine/source/sqlite/SQLiteObject.h +++ b/Engine/source/sqlite/SQLiteObject.h @@ -51,11 +51,11 @@ struct sqlite_resultrow struct sqlite_resultset { - int iResultSet; - int iCurrentRow; - int iCurrentColumn; - int iNumRows; - int iNumCols; + S32 iResultSet; + S32 iCurrentRow; + S32 iCurrentColumn; + S32 iNumRows; + S32 iNumCols; bool bValid; VectorPtr vRows; }; @@ -92,20 +92,20 @@ class SQLiteObject : public SimObject // the onOpened() script callback. bool OpenDatabase(const char* filename); void CloseDatabase(); - int loadOrSaveDb(const char *zFilename, bool isSave);//This code courtesy of sqlite.org. - int ExecuteSQL(const char* sql); - void NextRow(int resultSet); - bool EndOfResult(int resultSet); + S32 loadOrSaveDb(const char *zFilename, bool isSave);//This code courtesy of sqlite.org. + S32 ExecuteSQL(const char* sql); + void NextRow(S32 resultSet); + bool EndOfResult(S32 resultSet); void escapeSingleQuotes(const char* source, char *dest); // support functions void ClearErrorString(); - void ClearResultSet(int index); - sqlite_resultset* GetResultSet(int iResultSet); + void ClearResultSet(S32 index); + sqlite_resultset* GetResultSet(S32 iResultSet); bool SaveResultSet(sqlite_resultset* pResultSet); - int GetResultSetIndex(int iResultSet); - int GetColumnIndex(int iResult, const char* columnName); - int numResultSets(); + S32 GetResultSetIndex(S32 iResultSet); + S32 GetColumnIndex(S32 iResult, const char* columnName); + S32 numResultSets(); //Prepared Statements! We need a way to make them and extend them to script. //void prepareStatement(sqlite3_stmt*,); @@ -117,8 +117,8 @@ class SQLiteObject : public SimObject private: char* m_szErrorString; VectorPtr m_vResultSets; - int m_iLastResultSet; - int m_iNextResultSet; + S32 m_iLastResultSet; + S32 m_iNextResultSet; // This macro ties us into the script engine, and MUST MUST MUST be declared @@ -127,7 +127,7 @@ class SQLiteObject : public SimObject //-------------------------------------------------------------------------- public: DECLARE_CONOBJECT(SQLiteObject); - int getLastRowId() { return sqlite3_last_insert_rowid(m_pDatabase); }; + S32 getLastRowId() { return sqlite3_last_insert_rowid(m_pDatabase); }; //-------------------------------------------------------------------------- }; diff --git a/Tools/CMake/libraries/sqlite.cmake b/Tools/CMake/libraries/sqlite.cmake new file mode 100644 index 000000000..069879fc7 --- /dev/null +++ b/Tools/CMake/libraries/sqlite.cmake @@ -0,0 +1,28 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) 2015 GarageGames, LLC +# +# 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. +# ----------------------------------------------------------------------------- + +project(sqlite) + +addPath("${libDir}/sqlite") +addInclude("${libDir}/sqlite") + +finishLibrary() \ No newline at end of file diff --git a/Tools/CMake/modules/module_sqlite.cmake b/Tools/CMake/modules/module_sqlite.cmake index d56fc3a64..e8a1f6dd3 100644 --- a/Tools/CMake/modules/module_sqlite.cmake +++ b/Tools/CMake/modules/module_sqlite.cmake @@ -20,8 +20,9 @@ # IN THE SOFTWARE. # ----------------------------------------------------------------------------- -option(TORQUE_sqlite "Enable sqlite module" ON) -if(TORQUE_sqlite) -# files -addPathRec( "${srcDir}/sqlite" ) -endif() \ No newline at end of file +option(TORQUE_SQLITE "Enable sqlite module" ON) +if(TORQUE_SQLITE) + addPath( "${srcDir}/sqlite" ) + addLib( "sqlite" ) + addInclude( "${libDir}/sqlite" ) +endif() From d7c78472742c0d749367f15e7b6be8aa2307523f Mon Sep 17 00:00:00 2001 From: rextimmy Date: Sun, 10 Sep 2017 09:52:25 +1000 Subject: [PATCH 2/3] Mac compile fix for SQLiteObject --- Engine/source/sqlite/SQLiteObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/sqlite/SQLiteObject.cpp b/Engine/source/sqlite/SQLiteObject.cpp index cd20b93f3..7fe06de5f 100644 --- a/Engine/source/sqlite/SQLiteObject.cpp +++ b/Engine/source/sqlite/SQLiteObject.cpp @@ -605,7 +605,7 @@ ConsoleMethod(SQLiteObject, query, S32, 4, 0, "(const char* sql, S32 mode) Perfo } else return 0; // incorrect number of question marks vs arguments - Con::printf("Old SQL: %s\nNew SQL: %s", argv[2], szNew); + Con::printf("Old SQL: %s\nNew SQL: %s", argv[2].getStringValue(), szNew); return object->ExecuteSQL(szNew); } From bdfe44cc937a54819c48631e7156a79da51a6116 Mon Sep 17 00:00:00 2001 From: rextimmy Date: Sun, 10 Sep 2017 09:56:09 +1000 Subject: [PATCH 3/3] Disable sqlite support by default --- Tools/CMake/modules/module_sqlite.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/CMake/modules/module_sqlite.cmake b/Tools/CMake/modules/module_sqlite.cmake index e8a1f6dd3..325e34dce 100644 --- a/Tools/CMake/modules/module_sqlite.cmake +++ b/Tools/CMake/modules/module_sqlite.cmake @@ -20,7 +20,7 @@ # IN THE SOFTWARE. # ----------------------------------------------------------------------------- -option(TORQUE_SQLITE "Enable sqlite module" ON) +option(TORQUE_SQLITE "Enable sqlite module" OFF) if(TORQUE_SQLITE) addPath( "${srcDir}/sqlite" ) addLib( "sqlite" )