sqlite3 with Ruby - how to open a database as read only?

I'm using the following on Windows 10 with Ruby 2.7.2.

require 'sqlite3'
db = SQLite3::Database.open 'C:/sqlite/mytest.db'
p db

which gives:
#<SQLite3::Database:0x00000000064b6d00 ... , @readonly=false>
and with that I can read tables and also add rows to tables.

What I would like to be able to do is use something like:
db = SQLite3::Database.open 'C:/sqlite/mytest.db', argument

From searching the internet, 1 seems to be the flag which opens an
SQLite3 database as read only. But:
db = SQLite3::Database.open 'C:/sqlite/mytest.db', 1
raises a 'no implicit conversion of Symbol into Integer (TypeError)' exception.

db = SQLite3::Database.open 'C:/sqlite/mytest.db', xxxsymbolxxx: 1
works without raising an exception, but still: @readonly=false

Using :mode still gives: @readonly=false
Is there any Symbol instead of :xxxsymbolxxx or :mode which works?

Thanks for any hints.

Hi, Colin. Try pass readonly: true

···

3:40 ПП, 6 июня 2021 г., Colin Bartlett colinb2r@googlemail.com:

I’m using the following on Windows 10 with Ruby 2.7.2.

require ‘sqlite3’
db = SQLite3::Database.open ‘C:/sqlite/mytest.db’
p db

which gives:
#<SQLite3::Database:0x00000000064b6d00 … , @readonly=false>
and with that I can read tables and also add rows to tables.

What I would like to be able to do is use something like:
db = SQLite3::Database.open ‘C:/sqlite/mytest.db’, argument

From searching the internet, 1 seems to be the flag which opens an
SQLite3 database as read only. But:
db = SQLite3::Database.open ‘C:/sqlite/mytest.db’, 1
raises a ‘no implicit conversion of Symbol into Integer (TypeError)’ exception.

db = SQLite3::Database.open ‘C:/sqlite/mytest.db’, xxxsymbolxxx: 1
works without raising an exception, but still: @readonly=false

Using :mode still gives: @readonly=false
Is there any Symbol instead of :xxxsymbolxxx or :mode which works?

Thanks for any hints.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>