提交 edfb738b 编写于 作者: R Ryuta Kamizono

Remove `#tables` extra args again

This issue was resolved by #21687 already. But re-add args by #18856.
`#tables` extra args was only using by `#table_exists?`. This is for
internal API. This commit will remove these extra args again.
上级 d8b076c9
......@@ -482,16 +482,11 @@ def collation
show_variable 'collation_database'
end
def tables(name = nil, database = nil, like = nil) #:nodoc:
database ||= current_database
def tables(name = nil) # :nodoc:
sql = "SELECT table_name FROM information_schema.tables "
sql << "WHERE table_schema = #{quote(database)}"
sql << " AND table_name = #{quote(like)}" if like
sql << "WHERE table_schema = #{quote(@config[:database])}"
execute_and_free(sql, 'SCHEMA') do |result|
result.collect(&:first)
end
select_values(sql, 'SCHEMA')
end
alias data_sources tables
......
......@@ -311,22 +311,18 @@ def exec_rollback_db_transaction #:nodoc:
# SCHEMA STATEMENTS ========================================
def tables(name = nil, table_name = nil) #:nodoc:
sql = <<-SQL
SELECT name
FROM sqlite_master
WHERE (type = 'table' OR type = 'view') AND NOT name = 'sqlite_sequence'
SQL
sql << " AND name = #{quote_table_name(table_name)}" if table_name
exec_query(sql, 'SCHEMA').map do |row|
row['name']
end
def tables(name = nil) # :nodoc:
select_values("SELECT name FROM sqlite_master WHERE type IN ('table','view') AND name <> 'sqlite_sequence'", 'SCHEMA')
end
alias data_sources tables
def table_exists?(table_name)
table_name && tables(nil, table_name).any?
return false unless table_name.present?
sql = "SELECT name FROM sqlite_master WHERE type IN ('table','view') AND name <> 'sqlite_sequence'"
sql << " AND name = #{quote(table_name)}"
select_values(sql, 'SCHEMA').any?
end
alias data_source_exists? table_exists?
......
......@@ -294,7 +294,7 @@ def test_tables
def test_tables_logs_name
sql = <<-SQL
SELECT name FROM sqlite_master
WHERE (type = 'table' OR type = 'view') AND NOT name = 'sqlite_sequence'
WHERE type IN ('table','view') AND name <> 'sqlite_sequence'
SQL
assert_logged [[sql.squish, 'SCHEMA', []]] do
@conn.tables('hello')
......@@ -313,8 +313,7 @@ def test_table_exists_logs_name
with_example_table do
sql = <<-SQL
SELECT name FROM sqlite_master
WHERE (type = 'table' OR type = 'view')
AND NOT name = 'sqlite_sequence' AND name = \"ex\"
WHERE type IN ('table','view') AND name <> 'sqlite_sequence' AND name = 'ex'
SQL
assert_logged [[sql.squish, 'SCHEMA', []]] do
assert @conn.table_exists?('ex')
......
......@@ -103,7 +103,7 @@ def clear_log; self.log = []; self.log_all = []; end
# ignored SQL, or better yet, use a different notification for the queries
# instead examining the SQL content.
oracle_ignored = [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from all_triggers/im, /^\s*select .* from all_constraints/im, /^\s*select .* from all_tab_cols/im]
mysql_ignored = [/^SHOW FULL TABLES/i, /^SHOW FULL FIELDS/, /^SHOW CREATE TABLE /i, /^SHOW VARIABLES /, /^SELECT DATABASE\(\) as db$/, /^\s*SELECT (?:column_name|table_name)\b.*\bFROM information_schema\.(?:key_column_usage|tables)\b/im]
mysql_ignored = [/^SHOW FULL TABLES/i, /^SHOW FULL FIELDS/, /^SHOW CREATE TABLE /i, /^SHOW VARIABLES /, /^\s*SELECT (?:column_name|table_name)\b.*\bFROM information_schema\.(?:key_column_usage|tables)\b/im]
postgresql_ignored = [/^\s*select\b.*\bfrom\b.*pg_namespace\b/im, /^\s*select tablename\b.*from pg_tables\b/im, /^\s*select\b.*\battname\b.*\bfrom\b.*\bpg_attribute\b/im, /^SHOW search_path/i]
sqlite3_ignored = [/^\s*SELECT name\b.*\bFROM sqlite_master/im, /^\s*SELECT sql\b.*\bFROM sqlite_master/im]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册