Bladeren bron

sqlite fixes

rextimmy 8 jaren geleden
bovenliggende
commit
79118ee00f

+ 0 - 0
Engine/source/sqlite/sqlite3.c → Engine/lib/sqlite/sqlite3.c


+ 0 - 0
Engine/source/sqlite/sqlite3.h → Engine/lib/sqlite/sqlite3.h


+ 0 - 0
Engine/source/sqlite/sqlite3ext.h → Engine/lib/sqlite/sqlite3ext.h


+ 39 - 47
Engine/source/sqlite/SQLiteObject.cc → Engine/source/sqlite/SQLiteObject.cpp

@@ -36,17 +36,17 @@
 #include "console/engineAPI.h"
 
 #include "console/consoleInternal.h"
-#include <STDLIB.H>
+#include <cstdlib>
 
 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<int> vTemp;
-	Vector<int>::iterator iTemp;
+	Vector<S32> vTemp;
+	Vector<S32>::iterator iTemp;
 
 	VectorPtr<sqlite_resultset*>::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<sqlite_resultset*>::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<sqlite_resultset*>::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<char*>::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<char*>::iterator iName;
-	VectorPtr<char*>::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<char*>::iterator iName;
-	VectorPtr<char*>::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<char*>::iterator iName;
-	VectorPtr<char*>::iterator iValue;
 	S32 iColumn;
 
 	pResultSet = object->GetResultSet(dAtoi(argv[2]));

+ 17 - 17
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<sqlite_resultrow*>  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<sqlite_resultset*>  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); };
    //--------------------------------------------------------------------------
 };
 

+ 28 - 0
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()

+ 6 - 5
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()
+option(TORQUE_SQLITE "Enable sqlite module" ON)
+if(TORQUE_SQLITE)
+   addPath( "${srcDir}/sqlite" )
+   addLib( "sqlite" )
+   addInclude( "${libDir}/sqlite" )
+endif()