diff options
author | Jochen Topf <jochen@topf.org> | 2010-11-26 19:57:02 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2010-11-26 19:57:02 +0100 |
commit | a801d1f7ca841dcad23e99ff824d95fdf2540313 (patch) | |
tree | 52284601c9804566d8d2b49f799c9c359a448958 /web/lib | |
parent | 006a973738abbdb965daa37adb609ed87b83a837 (diff) | |
download | taginfo-a801d1f7ca841dcad23e99ff824d95fdf2540313.tar taginfo-a801d1f7ca841dcad23e99ff824d95fdf2540313.tar.gz |
better logging of sql commands
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/sql.rb | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/web/lib/sql.rb b/web/lib/sql.rb index 4269421..5f57fb3 100644 --- a/web/lib/sql.rb +++ b/web/lib/sql.rb @@ -154,21 +154,29 @@ module SQL @query.compact.join(' ') end + def log_query(query, params) + if params.size > 0 + puts "Query: #{query}; (with params: #{params.map{ |p| "'#{p}'" }.join(', ')})" + else + puts "Query: #{query};" + end + end + def execute(&block) q = build_query() - puts "Query: #{q}; (with params: #{@params.join(', ')})" + log_query(q, @params) @db.execute(q, *@params, &block) end def get_first_value q = build_query() - puts "Query: #{q}; (with params: #{@params.join(', ')})" + log_query(q, @params) @db.get_first_value(q, *@params) end def get_columns(*columns) q = build_query() - puts "Query: #{q}; (with params: #{@params.join(', ')})" + log_query(q, @params) row = @db.get_first_row(q, *@params) return [nil] * columns.size if row.nil?; columns.map{ |column| row[column.to_s] } |