So this is a follow up to a previous post on using SQLite with Unreal.
The good news is that compiling the SQLite amalgamation now also works in Windows. So you can simply use the Amalgamation in Windows, Mac, and ios.
To review, you can download the SQLite amalgamation from https://sqlite.org/download.html. It is basically a .c and .h file with the entire SQLite db in it. All you need to do to use it is include with the source code of your project.
For an Unreal project, this means just adding it to YourProject/Source. In my instance, there was one minor error involving a #define for :gethostuuid
error: "gethostuuid() is disabled." [-Werror,-W#warnings] # warning "gethostuuid() is disabled."
So I changed this:
# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \ && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0)) # define HAVE_GETHOSTUUID 1 # else # warning "gethostuuid() is disabled." # endif
to this:
# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \ && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0)) # define HAVE_GETHOSTUUID 1 # endif
Now that SQLite is in our project, it would be great if we could use it from BP. As mentioned in the previous post, there are some SQLite plugins available. However, for this project, I decided to write some specific BP functionality.
Since exposing structures and functions from c++ to BP is so easy, I decided to write some specific code just for this project that will enable me to use from Blueprints.
In general, we want to execute some sql and get a result set back. For this game, I have decided that I will create some structs to represent a 1-1 mapping for any table I want to query. Then I will export a BP function that accepts a sql string and returns a TArray of the appropriate struct.
Clearly, there are much more generic approaches to doing this, but for this game I chose the simplest hard-coded approach of simply creating a struct in c++ for any table I want to query.. This is actually very easy to do, because it is so easy to export structs and functions from c++ to bp.
To Be Continued.... (Posting now to help respond to forum question)