Create a recordset in code


I have a weird need, perhaps you can help.

I need to test a function that will work on a recordset, but I have no way of generating the recordset itself. The function will be used to export XML data from the recordset and I have a set of sample data with very few rows I can work with.

Is it possible to create a sample recordset directly in code, so I can test the functions on it without having to have a database of any kind set-up?

I thought I could build it by defining a new recordset and adding columns and rows but I can’t find a way to do it.

I may be missing something obvious.

I would suggest using an in memory SQLite database. You can easily do this by creating a new sqlitedatabase property and connecting to it without assigning a folderitem for the databasefile. Once done you can create your table & add rows.

In-Memory Database
An “in-memory database” is a SQLite database that exists only in memory; there is no related file on disk. It works exactly as a SQLite database except it is very fast and completely temporary.

To create an in-memory database, just create a new SQLiteDatabase instance and connect to it:

Dim inMemoryDB As New SQLiteDatabase If inMemoryDB.Connect Then // Can now use inMemoryDB End If

After which you can use code to create tables, insert records, and query data

Ah. I hadn’t thought about creating an in-memory sqlite database. That would also work.

Thanks! I knew it had to be obvious :smiley:

Also you can check our MBS Xojo SQL Plugin with BuildRecordSetMBS function.

Thanks Christian, but it wouldn’t be useful in this specific case. I need this to create a self-contained method that will be used to teach how to programmatically create a nested XML from tables multiple recordsets. I’ll share the code with the class so it needs to be plain vanilla Xojo, without dependencies.

And InMemory database is probably the closest to my original request for this goal.