5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/annotato/trigger_formatter.rb', line 5
def self.format(conn, table_name)
rows = case conn.adapter_name.downcase
when "postgresql"
conn.exec_query(
"SELECT tgname AS name FROM pg_trigger WHERE tgrelid = $1::regclass AND NOT tgisinternal",
"SQL", [table_name]
)
when "mysql2", "mysql", "trilogy"
conn.exec_query(
"SELECT TRIGGER_NAME AS name FROM information_schema.TRIGGERS " \
"WHERE EVENT_OBJECT_SCHEMA = DATABASE() AND EVENT_OBJECT_TABLE = ?",
"SQL", [table_name]
)
when "sqlite3"
conn.exec_query(
"SELECT name FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ?",
"SQL", [table_name]
)
else
return []
end
rows.map { |r| "# #{r['name']}" }
end
|