PublicDependencyModuleNames.AddRange(newstring []{“Core”,”CoreUObject”,”Engine”,”InputCore”,”SQLiteSupport”});
查询例
//Path 数据库路径, SqlQuery 查询语句, Items 查询返回结果。 FSqliteDataTable
UFUNCTION (BlueprintCallable ,Category =”SqliteDatabase”)
bool LoadSqlAsTable (FString Path,FString SqlQuery,TArray
引入头文件
include “SQLiteDatabaseConnection.h”
函数实现
bool ASqliteActor ::LoadSqlAsTable (FString Path,FString SqlQuery,TArray
FSQLiteDatabaseConnection db;
// 连接数据库
Path =*FPaths ::ProjectContentDir ()+Path; // 项目地址 + 数据库路径
//GEngine->AddOnScreenDebugMessage(-1,5.0f,FColor::White,Path);
if (!db.Open (*Path,nullptr ,nullptr ))
GEngine->AddOnScreenDebugMessage (-1 ,5.0f ,FColor ::Red ,”OPENDATABASEFAILED”);
returnfalse ;
GEngine->AddOnScreenDebugMessage (-1 ,5.0f ,FColor ::Green ,”OPENDATABASESUCCESS”);
//FStringquery=FString::Printf(TEXT(“SELECTName,PriceFROMShopItems”));
// 执行 Sql 语句
FDataBaseRecordSet *outRecords=nullptr ; // 处理结果
if (!db.Execute (*SqlQuery,outRecords))
GEngine->AddOnScreenDebugMessage (-1 ,5.0f ,FColor ::Red ,”EXECUTEFAILED”);
delete outRecords;
db.Close ();
returnfalse ;
GEngine->AddOnScreenDebugMessage (-1 ,5.0f ,FColor ::Green ,”EXECUTESUCCESS”);
// 判断查询结果数量
int count=outRecords->GetRecordCount ();
GEngine->AddOnScreenDebugMessage (-1 ,5.0f ,FColor ::Red ,FString ::FromInt (count));
if (count==0 )
delete outRecords;
db.Close ();
returnfalse ;
// 查询结果加入返回的 Datatable
for (FDataBaseRecordSet ::TIterator i (outRecords );i;++i)
FSqliteDataTable &newItem=Items.AddDefaulted_GetRef ();
for (FDatabaseColumnInfo column:i ->GetColumnNames ())
if (column.ColumnName ==TEXT (“Name”))
newItem.Name =i ->GetString (*column.ColumnName );
elseif (column.ColumnName ==TEXT (“Price”))
newItem.Price =i ->GetFloat (*column.ColumnName );
delete outRecords;
db.Close ();
returntrue ;
USTRUCT (BlueprintType )
struct FSqliteDataTable :public FTableRowBase
GENERATED_BODY ()
public:
UPROPERTY (BlueprintReadWrite ,EditAnywhere )
FString Name ;
UPROPERTY (BlueprintReadWrite ,EditAnywhere )
UTexture2D *Icon ;
UPROPERTY (BlueprintReadWrite ,EditAnywhere )
float Price ;
Original: https://blog.csdn.net/qq_42003378/article/details/123242916
Author: 902D9
Title: UE4 使用Sqlite
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/816502/
转载文章受原作者版权保护。转载请注明原作者出处!