2shady4u / godot-sqlite

GDExtension wrapper for SQLite (Godot 4.x+)
MIT License
850 stars 76 forks source link

Query across multiple databases #161

Closed ac-arcana closed 6 months ago

ac-arcana commented 7 months ago

I have a database with a Weapons table. I have another database that acts as a save file and contains a table which specifies the weapons a user has available, UserWeapons. I want to write a query to get all rows from Weapons where the weapon id is found in UserWeapons.

Usually you can specify which db you are querying when you specify a table in SQL queries, however I do not see a way to specify multiple databases in one query if the query is tied to a db object.

Is there a way to specify a database or path in the query that is not documented?

2shady4u commented 7 months ago

Hello @ac-arcana

I think this might be possible with the ATTACH DATABASE command, see here: https://sqlite.org/lang_attach.html

ac-arcana commented 7 months ago

I'll take a look at this for sure! I'm guessing the syntax as in this documentation should work? So ATTACH filepath AS dbname. I'll try it and I'll close if this works for me. I knew vaguely about the attach command but wasn't sure it would work with this plugin due to the database variables

ac-arcana commented 6 months ago

I'm gonna mark this as solved and closed. I don't think I truly understood the power of using SQL syntax in query, instead of just the built in functions. Anything normally done with SQL can be done this way.