2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-12-06 19:14:20 -05:00
|
|
|
|
2014-10-30 10:03:30 -04:00
|
|
|
#include "SQLiteSupportPrivatePCH.h"
|
|
|
|
|
#include "SQLiteDatabaseConnection.h"
|
|
|
|
|
#include "sqlite3.h"
|
|
|
|
|
|
|
|
|
|
bool FSQLiteDatabase::Execute(const TCHAR* CommandString, FSQLiteResultSet*& RecordSet)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//Compile the statement/query
|
|
|
|
|
sqlite3_stmt* PreparedStatement;
|
2014-12-05 11:08:16 -05:00
|
|
|
int32 PrepareStatus = sqlite3_prepare_v2(DbHandle, TCHAR_TO_UTF8(CommandString), -1, &PreparedStatement, NULL);
|
2014-10-30 10:03:30 -04:00
|
|
|
if (PrepareStatus == SQLITE_OK)
|
|
|
|
|
{
|
|
|
|
|
//Initialize records from compiled query
|
|
|
|
|
RecordSet = new FSQLiteResultSet(PreparedStatement);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RecordSet = NULL;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool FSQLiteDatabase::Execute(const TCHAR* CommandString)
|
|
|
|
|
{
|
|
|
|
|
//Compile the statement/query
|
|
|
|
|
sqlite3_stmt* PreparedStatement;
|
2014-12-05 11:08:16 -05:00
|
|
|
int32 PrepareStatus = sqlite3_prepare_v2(DbHandle, TCHAR_TO_UTF8(CommandString), -1, &PreparedStatement, NULL);
|
2014-10-30 10:03:30 -04:00
|
|
|
if (PrepareStatus == SQLITE_OK)
|
|
|
|
|
{
|
|
|
|
|
int32 StepStatus = SQLITE_ERROR;
|
|
|
|
|
//Execute the statement until it is done or we get an error
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
StepStatus = sqlite3_step(PreparedStatement);
|
|
|
|
|
} while ((StepStatus != SQLITE_ERROR) && (StepStatus != SQLITE_CONSTRAINT) && (StepStatus != SQLITE_DONE));
|
|
|
|
|
|
|
|
|
|
//Did we make it all the way through the query without an error?
|
|
|
|
|
if (StepStatus == SQLITE_DONE)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FSQLiteDatabase::Execute(const TCHAR* CommandString, FDataBaseRecordSet*& RecordSet)
|
|
|
|
|
{
|
|
|
|
|
return Execute(CommandString, (FSQLiteResultSet*&)RecordSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FSQLiteDatabase::Close()
|
|
|
|
|
{
|
|
|
|
|
if (DbHandle)
|
|
|
|
|
{
|
|
|
|
|
sqlite3_close(DbHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool FSQLiteDatabase::Open(const TCHAR* ConnectionString, const TCHAR* RemoteConnectionIP, const TCHAR* RemoteConnectionStringOverride)
|
|
|
|
|
{
|
|
|
|
|
if (DbHandle)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-05 11:08:16 -05:00
|
|
|
int32 Result = sqlite3_open(TCHAR_TO_UTF8(ConnectionString), &DbHandle);
|
2014-10-30 10:03:30 -04:00
|
|
|
return Result == SQLITE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString FSQLiteDatabase::GetLastError()
|
|
|
|
|
{
|
|
|
|
|
TCHAR* ErrorString = NULL;
|
2014-12-05 11:08:16 -05:00
|
|
|
ErrorString = (TCHAR*) UTF8_TO_TCHAR(sqlite3_errmsg(DbHandle));
|
2014-10-30 10:03:30 -04:00
|
|
|
if (ErrorString)
|
|
|
|
|
{
|
|
|
|
|
return FString(ErrorString);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FString();
|
|
|
|
|
}
|
|
|
|
|
}
|