lua sqlite3 attach database

Posted by Renny on Sun 12 Aug 2018 06:16 AM — 3 posts, 15,709 views.

Canada #0
For the mud aardwolf I would like to attach Aardwolf.db to my own database so I can do a join on one of the tables.

Is there a way to do this with the lsqlite3 module?

I have thought of some workarounds such as copying the table to my own database, but I would rather avoid this if possible (due to periodically having to update it).
Australia Forum Administrator #1
See: Stack Overflow question: SQLite - How do you join tables from different databases?.

Something like this:


db = sqlite3.open('foo.db')  -- open

db:exec ("attach 'bar.db' as db2") -- attach other database

for a in db:nrows ('SELECT * FROM foo LEFT JOIN bar USING (id)') do
  tprint(a)
end

db:close ()
Amended on Sun 12 Aug 2018 09:16 PM by Nick Gammon
USA Global Moderator #2
This sounds interesting. What are you making, Renny?