diff --git a/Source/CISQLite3/Private/CISQLite3.cpp b/Source/CISQLite3/Private/CISQLite3.cpp index bd3293e..60deba1 100644 --- a/Source/CISQLite3/Private/CISQLite3.cpp +++ b/Source/CISQLite3/Private/CISQLite3.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2016 conflict.industries MIT License (MIT) +#include "CISQLite3.h" #include "CISQLite3PrivatePCH.h" DEFINE_LOG_CATEGORY(LogDatabase) diff --git a/Source/CISQLite3/Private/SQLiteBlueprintFunctionLibrary.cpp b/Source/CISQLite3/Private/SQLiteBlueprintFunctionLibrary.cpp index 0fbde01..de89ac8 100644 --- a/Source/CISQLite3/Private/SQLiteBlueprintFunctionLibrary.cpp +++ b/Source/CISQLite3/Private/SQLiteBlueprintFunctionLibrary.cpp @@ -1,18 +1,13 @@ +#include "SQLiteBlueprintFunctionLibrary.h" #include "CISQLite3PrivatePCH.h" #include "Engine.h" -#include "CString.h" - -#include "SQLiteBlueprintFunctionLibrary.h" - - - +#include "Misc/CString.h" int32 USQLiteBlueprintFunctionLibrary::CastToInt(FString SQLiteResultValue) { return FCString::Atoi(*SQLiteResultValue); } - bool USQLiteBlueprintFunctionLibrary::CastToBoolean(FString SQLiteResultValue) { return FCString::Atoi(*SQLiteResultValue) > 0; diff --git a/Source/CISQLite3/Private/SQLiteDatabase.cpp b/Source/CISQLite3/Private/SQLiteDatabase.cpp index 7070d92..d429a99 100644 --- a/Source/CISQLite3/Private/SQLiteDatabase.cpp +++ b/Source/CISQLite3/Private/SQLiteDatabase.cpp @@ -1,5 +1,5 @@ -#include "CISQLite3PrivatePCH.h" #include "SQLiteDatabase.h" +#include "CISQLite3PrivatePCH.h" #define LOGSQLITE(verbosity, text) UE_LOG(LogDatabase, verbosity, TEXT("SQLite: %s"), text) @@ -17,7 +17,7 @@ USQLiteDatabase::USQLiteDatabase(const FObjectInitializer& ObjectInitializer) bool USQLiteDatabase::CreateDatabase(const FString& Filename, bool RelativeToProjectContentDirectory) { - const FString actualFilename = RelativeToProjectContentDirectory ? FPaths::ProjectContentDir() + Filename : Filename; + const FString actualFilename = RelativeToProjectContentDirectory ? FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()) + Filename : Filename; sqlite3* db; int res = sqlite3_open(TCHAR_TO_ANSI(*actualFilename), &db); @@ -37,7 +37,7 @@ bool USQLiteDatabase::CreateDatabase(const FString& Filename, bool RelativeToPro bool USQLiteDatabase::RegisterDatabase(const FString& Name, const FString& Filename, bool RelativeToProjectContentDirectory, bool KeepOpen) { - const FString actualFilename = RelativeToProjectContentDirectory ? FPaths::ProjectContentDir() + Filename : Filename; + const FString actualFilename = RelativeToProjectContentDirectory ? FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()) + Filename : Filename; if (!IsValidDatabase(actualFilename, true)) { @@ -273,12 +273,12 @@ bool USQLiteDatabase::GetDataIntoObjectBP(const FSQLiteDatabaseReference& DataSo //-------------------------------------------------------------------------------------------------------------- -TMap USQLiteDatabase::CollectProperties(UObject* SourceObject) +TMap USQLiteDatabase::CollectProperties(UObject* SourceObject) { UClass* SourceObjectClass = SourceObject->GetClass(); - TMap Props; - for (TFieldIterator PropIt(SourceObjectClass, EFieldIteratorFlags::SuperClassFlags::IncludeSuper); + TMap Props; + for (TFieldIterator PropIt(SourceObjectClass, EFieldIteratorFlags::SuperClassFlags::IncludeSuper); PropIt; ++PropIt) { Props.Add(*PropIt->GetNameCPP(), *PropIt); @@ -782,6 +782,7 @@ TUniquePtr USQLiteDatabase::RunQueryAndGetResults(const FStri sqlite3_finalize(preparedStatement); if (!keepOpen) sqlite3_close(db); + result.InsertedId = sqlite3_last_insert_rowid(db); result.Results = resultRows; result.Success = true; return MakeUnique(MoveTemp(result)); @@ -797,37 +798,37 @@ void USQLiteDatabase::AssignResultsToObjectProperties(const SQLiteResultValue& R { if (propertyMap.Contains(field.Name)) { - UProperty* targetProperty = propertyMap[field.Name]; + FProperty* targetProperty = propertyMap[field.Name]; if (field.Type == SQLiteResultValueTypes::Integer) { - UInt64Property* int64prop = NULL; - UIntProperty* int32prop = NULL; - UInt16Property* int16prop = NULL; - UInt8Property* int8prop = NULL; - UBoolProperty* boolProp = NULL; + FInt64Property* int64prop = NULL; + FIntProperty* int32prop = NULL; + FInt16Property* int16prop = NULL; + FInt8Property* int8prop = NULL; + FBoolProperty* boolProp = NULL; - if ((int64prop = Cast(targetProperty)) != NULL) + if ((int64prop = CastField(targetProperty)) != NULL) { int64prop->SetPropertyValue_InContainer(ObjectToPopulate, field.IntValue); LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue)); } - else if ((int32prop = Cast(targetProperty)) != NULL) + else if ((int32prop = CastField(targetProperty)) != NULL) { int32prop->SetPropertyValue_InContainer(ObjectToPopulate, (int32)field.IntValue); LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue)); } - else if ((int16prop = Cast(targetProperty)) != NULL) + else if ((int16prop = CastField(targetProperty)) != NULL) { int16prop->SetPropertyValue_InContainer(ObjectToPopulate, (int16)field.IntValue); LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue)); } - else if ((int8prop = Cast(targetProperty)) != NULL) + else if ((int8prop = CastField(targetProperty)) != NULL) { int8prop->SetPropertyValue_InContainer(ObjectToPopulate, (int8)field.IntValue); LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue)); } - else if ((boolProp = Cast(targetProperty)) != NULL) + else if ((boolProp = CastField(targetProperty)) != NULL) { boolProp->SetPropertyValue_InContainer(ObjectToPopulate, field.IntValue > 0); LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%d'"), *field.Name, field.IntValue)); @@ -836,14 +837,14 @@ void USQLiteDatabase::AssignResultsToObjectProperties(const SQLiteResultValue& R else if (field.Type == SQLiteResultValueTypes::Float) { - UDoubleProperty* doubleProp = NULL; - UFloatProperty* floatProp = NULL; - if ((doubleProp = Cast(targetProperty)) != NULL) + FDoubleProperty* doubleProp = NULL; + FFloatProperty* floatProp = NULL; + if ((doubleProp = CastField(targetProperty)) != NULL) { doubleProp->SetPropertyValue_InContainer(ObjectToPopulate, field.DoubleValue); LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%f'"), *field.Name, field.DoubleValue)); } - else if ((floatProp = Cast(targetProperty)) != NULL) + else if ((floatProp = CastField(targetProperty)) != NULL) { floatProp->SetPropertyValue_InContainer(ObjectToPopulate, (float)field.DoubleValue); LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%f'"), *field.Name, field.DoubleValue)); @@ -852,8 +853,8 @@ void USQLiteDatabase::AssignResultsToObjectProperties(const SQLiteResultValue& R else if (field.Type == SQLiteResultValueTypes::Text) { - UStrProperty* strProp = NULL; - if ((strProp = Cast(targetProperty)) != NULL) + FStrProperty* strProp = NULL; + if ((strProp = CastField(targetProperty)) != NULL) { strProp->SetPropertyValue_InContainer(ObjectToPopulate, field.StringValue); LOGSQLITE(Verbose, *FString::Printf(TEXT("Property '%s' was set to '%s'"), *field.Name, *field.StringValue.Mid(0, 64))); diff --git a/Source/CISQLite3/Public/CISQLite3.h b/Source/CISQLite3/Public/CISQLite3.h index 0ba53e2..25f0bd7 100644 --- a/Source/CISQLite3/Public/CISQLite3.h +++ b/Source/CISQLite3/Public/CISQLite3.h @@ -2,7 +2,7 @@ #pragma once -#include "ModuleManager.h" +#include "Modules/ModuleManager.h" class FCISQLite3 : public IModuleInterface { diff --git a/Source/CISQLite3/Public/SQLiteDatabase.h b/Source/CISQLite3/Public/SQLiteDatabase.h index 648f428..b79768f 100644 --- a/Source/CISQLite3/Public/SQLiteDatabase.h +++ b/Source/CISQLite3/Public/SQLiteDatabase.h @@ -111,6 +111,7 @@ struct SQLiteQueryResult bool Success; FString ErrorMessage; TArray Results; + int InsertedId = 0; }; @@ -214,7 +215,7 @@ class CISQLITE3_API USQLiteDatabase : public UObject /** Tries to open a database. */ static bool CanOpenDatabase(const FString& DatabaseFilename); /** Collects all properties from an UObject and maps them by the property name. */ - static TMap CollectProperties(UObject* SourceObject); + static TMap CollectProperties(UObject* SourceObject); /** Constructs an SQL query from the blueprint fed data. */ static FString ConstructQuery(TArray Tables, TArray Fields, FSQLiteQueryFinalizedQuery QueryObject, int32 MaxResults = -1, int32 ResultOffset = 0); /** Assigns a result row's fields' values to an UObject, ie. assigns them to the properties that have the same name. */