Wrap sql in read only transaction for postgres still executes? #2140
Replies: 3 comments 2 replies
-
It appears this has to do with the way I'm executing sql. |
Beta Was this translation helpful? Give feedback.
-
Try running with a database logger to see what SQL is actually being executed: https://sequel.jeremyevans.net/rdoc/files/doc/cheat_sheet_rdoc.html#label-Logging+SQL+statements If you actually issue non-read-only queries inside a read-only transaction, it should raise a Sequel::DatabaseError. I tried and that's what I got:
|
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
I am either misusing or misunderstanding wrapping a sql statement in a read-only transaction
Using a local db for testing, the following does create a new table in my database
db.transaction(read_only: true) { db[sql] }
Where db.class is
Sequel::Postgres::Database
anddb = #<Sequel::Postgres::Database: {:adapter=>"postgres", :host=>"localhost", :database=>"local_dev", :user=>"", :password=>"", :port=>"5432"}>
and
sql = "CREATE TABLE employees_four (\n id SERIAL PRIMARY KEY,\n username VARCHAR(50) NOT NULL\n);\n"
I want to wrap my sql statements in a read only transaction to prevent any kind of db modification. For various reason I would like to do this instead of creating a read only users. Am I using the
transaction
statement wrong?Beta Was this translation helpful? Give feedback.
All reactions