Skip to content

Commit

Permalink
Merge pull request #49544 from hieuk09/bug/fix-sqlite3-table-name-quote
Browse files Browse the repository at this point in the history
SQLite: add additional quote to table name only when it’s not quoted
  • Loading branch information
byroot committed Oct 10, 2023
2 parents 77a5605 + 6da327c commit ce2eb72
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -673,7 +673,7 @@ def arel_from_relation(relation)

def extract_table_ref_from_insert_sql(sql)
if sql =~ /into\s("[A-Za-z0-9_."\[\]\s]+"|[A-Za-z0-9_."\[\]]+)\s*/im
$1.strip
$1.delete('"').strip
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
Expand Up @@ -96,6 +96,19 @@ def test_exec_insert
end
end

def test_exec_insert_with_quote
with_example_table do
vals = [Relation::QueryAttribute.new("number", 10, Type::Value.new)]
@conn.exec_insert("insert into \"ex\" (number) VALUES (?)", "SQL", vals)

result = @conn.exec_query(
"select number from \"ex\" where number = ?", "SQL", vals)

assert_equal 1, result.rows.length
assert_equal 10, result.rows.first.first
end
end

def test_primary_key_returns_nil_for_no_pk
with_example_table "id int, data string" do
assert_nil @conn.primary_key("ex")
Expand Down

0 comments on commit ce2eb72

Please sign in to comment.