0

I am trying to parse a sqlite3 database in rails 3 (using sqlite3-ruby gem). The database to parse is coming from a file upload. Here is my controller code:

  require 'fileutils'
  require 'sqlite3'

  tmp = params[:file_upload][:my_file]
  file = params[:file_upload][:my_file].tempfile
  filename = params[:file_upload][:my_file].original_filename

  file = File.join("public", params[:file_upload][:my_file].original_filename)
  FileUtils.cp tmp.path, filename

  db = SQLite3::Database.new(filename)

So it works very well in local, but not in production (with EngineYard). I get the following error:

 SQLite3::NotADatabaseException (file is encrypted or is not a database)

I do not understand why. Any help would be very appreciated, because i really don't know how to solve this thing.

Thanks

mathieurip
  • 547
  • 1
  • 6
  • 16
  • typically this means the file was created with WAL mode and your sqlite module is too old. – schlenk Sep 29 '12 at 21:25
  • i am not familiar with WAL mode, but indeed i see that a WAL file is created in my temp directory when uploading the sqlite3 file. I am using the following gems : sqlite3 (1.3.6) and sqlite3-ruby (1.3.3) – mathieurip Sep 29 '12 at 21:34
  • See http://www.sqlite.org/draft/wal.html for details about WAL. – schlenk Sep 29 '12 at 23:18
  • Thanks! So what are the solutions ? 1. Read with the databse with wal mode desactivated ? 2. Use another version of sqlite ? – mathieurip Sep 30 '12 at 06:39
  • In local i have sqlite 3.7.7.1 whereas on my amazon ec2 instance (via engine yard) i have sqlite 3.6.13 . Does it explain why i cannot use wal mode in production ? – mathieurip Sep 30 '12 at 07:09
  • 2
    The message you got can mean: 'This database uses WAL mode', or it can really be a corrupted DB or it can be a database encrypted with the SEE plugin. But the typical case is the WAL mode. Usually it works if you use: `PRAGMA journal_mode=DELETE`, but this only works with a recent enough SQLite. So in production, if you get a WAL database your out of luck. And yes, WAL is in 3.7 but not 3.6. So try to set the DB to non-WAL mode before upload. – schlenk Sep 30 '12 at 11:55
  • Even with changing journal_mode from WAL to OFF with `db.execute("PRAGMA temp.journal_mode=off;")`, i still have the same `SQLite3::NotADatabaseException (file is encrypted or is not a database)` – mathieurip Sep 30 '12 at 12:01
  • When you say "this only works with a recent enough SQLite", is sqlite 3.6.13 enough recent ? Thanks a lot – mathieurip Sep 30 '12 at 12:14
  • Already said so, to cite the docs: "The WAL journaling mode uses a write-ahead log instead of a rollback journal to implement transactions. The WAL journaling mode is persistent; after being set it stays in effect across multiple database connections and after closing and reopening the database. A database in WAL journaling mode can only be accessed by SQLite version 3.7.0 or later." – schlenk Sep 30 '12 at 17:49

1 Answers1

0

According to your own question Sqlite 3.7 on amazon ec2 with Engine Yard it seems :) Engine Yard provided you with sqlite 3.6, meaning that @schlenk above gave the right answer: The error message typically indicates that the database file was created with WAL mode, which requires mysql 3.7, which Engine Yard do not yet offer.

Community
  • 1
  • 1
Simon B.
  • 2,530
  • 24
  • 30