From a801d1f7ca841dcad23e99ff824d95fdf2540313 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Fri, 26 Nov 2010 19:57:02 +0100 Subject: better logging of sql commands --- web/lib/sql.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'web') 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] } -- cgit v1.2.3