1

I came across various similar questions, but I can't figure it out.

how to I use the .import command from ruby? I mean, when you run the sqlite3, you can type in commands, like this:

sqlite3> .import file table

so, how can i import file this way into sqlite3 in-memory database and performing sql on it?

my "not-so-pseudocode" (which not work):

require 'sqlite3'
begin
    db = SQLite3::Database.new ":memory:"
    db.execute ".import file table"   #<----- not working, obviously

rescue SQLite3::Exception => e

    puts "Exception occurred"
    puts e

ensure
    db.close if db
end
user_pruser
  • 422
  • 2
  • 13

1 Answers1

0

".import" and the rest of the "dot" commands are not part of the sqlite3 library, but are part of the sqlite3 command-line tool. Therefore, you must either implement what the command does in your program, or invoke the "sqlite3" program from ruby just like you would any other external program, using e.g. system or other means.

varro
  • 2,382
  • 2
  • 16
  • 24