-
Notifications
You must be signed in to change notification settings - Fork 14
Fix for UE4.25.1 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember fighting path issues on Android, but I don't think this should be a problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't tested on anything else but Windows, sorry. I'm not sure why I did this either, but IIRC a relative path didn't work correctly. I'm sorry for the incredibly low quality of the MR - I just managed to make it work on my machine and decided to share ;p Thanks for your time! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, sharing is always valuable, maybe someone using this on Android will pick it up and verify 👍 |
||
|
||
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<FString, UProperty*> USQLiteDatabase::CollectProperties(UObject* SourceObject) | ||
TMap<FString, FProperty*> USQLiteDatabase::CollectProperties(UObject* SourceObject) | ||
{ | ||
|
||
UClass* SourceObjectClass = SourceObject->GetClass(); | ||
TMap<FString, UProperty*> Props; | ||
for (TFieldIterator<UProperty> PropIt(SourceObjectClass, EFieldIteratorFlags::SuperClassFlags::IncludeSuper); | ||
TMap<FString, FProperty*> Props; | ||
for (TFieldIterator<FProperty> PropIt(SourceObjectClass, EFieldIteratorFlags::SuperClassFlags::IncludeSuper); | ||
PropIt; ++PropIt) | ||
{ | ||
Props.Add(*PropIt->GetNameCPP(), *PropIt); | ||
|
@@ -782,6 +782,7 @@ TUniquePtr<SQLiteQueryResult> 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<SQLiteQueryResult>(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<UInt64Property>(targetProperty)) != NULL) | ||
if ((int64prop = CastField<FInt64Property>(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<UIntProperty>(targetProperty)) != NULL) | ||
else if ((int32prop = CastField<FIntProperty>(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<UInt16Property>(targetProperty)) != NULL) | ||
else if ((int16prop = CastField<FInt16Property>(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<UInt8Property>(targetProperty)) != NULL) | ||
else if ((int8prop = CastField<FInt8Property>(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<UBoolProperty>(targetProperty)) != NULL) | ||
else if ((boolProp = CastField<FBoolProperty>(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<UDoubleProperty>(targetProperty)) != NULL) | ||
FDoubleProperty* doubleProp = NULL; | ||
FFloatProperty* floatProp = NULL; | ||
if ((doubleProp = CastField<FDoubleProperty>(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<UFloatProperty>(targetProperty)) != NULL) | ||
else if ((floatProp = CastField<FFloatProperty>(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<UStrProperty>(targetProperty)) != NULL) | ||
FStrProperty* strProp = NULL; | ||
if ((strProp = CastField<FStrProperty>(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))); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,6 +111,7 @@ struct SQLiteQueryResult | |
bool Success; | ||
FString ErrorMessage; | ||
TArray<SQLiteResultValue> Results; | ||
int InsertedId = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a functional change - not sure if this is the way you'd like it.. But I really needed the "last insert id" for an inserted record from a regular query (I'm only using this as a C++ module, not using the blueprints), so you might want to check that out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a SQLite (litterally, specific to sqlite) query for that |
||
}; | ||
|
||
|
||
|
@@ -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<FString, UProperty*> CollectProperties(UObject* SourceObject); | ||
static TMap<FString, FProperty*> CollectProperties(UObject* SourceObject); | ||
/** Constructs an SQL query from the blueprint fed data. */ | ||
static FString ConstructQuery(TArray<FString> Tables, TArray<FString> 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. */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the PCH needs the BlueprintFunctionLibrary or why is this? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea, I'm a complete noob in UE4 and C++ 😆
I don't quite remember why, but this fixed some issues I had..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, found it.
CString.h
was moved toMisc/CString.h
, and the order of imports was important, so they moved.