lib/qreport/report_runner.rb in qreport-0.0.9 vs lib/qreport/report_runner.rb in qreport-0.0.10
- old
+ new
@@ -30,15 +30,15 @@
conn.transaction do
# Create a report row sequence:
run "DROP SEQUENCE IF EXISTS qr_row_seq"
run "CREATE TEMPORARY SEQUENCE qr_row_seq"
- # Infer base columns, if not specified.
- if report_run.base_columns.empty?
- infer_base_columns!
+ # Infer base columns, if not specified.
+ if report_run.base_columns.empty?
+ infer_base_columns!
+ end
end
- end
# Construct report_table name from column names and types:
report_table = report_run.report_table
unless report_run.id
@@ -107,28 +107,32 @@
def infer_base_columns!
base_columns = nil
begin
conn.transaction do
# Proof query to infer base columns:
- result = run report_run.report_sql, :limit => 0, :arguments => arguments, :verbose => @verbose
+ result = run report_sql(sql, :limit => 'LIMIT 0'), :arguments => arguments, :verbose => @verbose
base_columns = report_run.base_columns = result.columns
end # transaction
rescue ::StandardError => exc
@error = @error_1 = exc
end
base_columns
end
- def report_sql sql
- sql = sql.sub(/\A\s*SELECT\s+/im, <<"END"
+ def report_sql sql, opts = { }
+ sql = sql.sub(/;\s*\Z/, '')
+ sql = <<"END"
SELECT
:qr_run_id
AS "qr_run_id"
, nextval('qr_row_seq')
AS "qr_run_row"
- ,
+ , _qr_r_.*
+FROM (
+#{sql}
+) AS "_qr_r_"
+#{opts[:limit]}
END
- )
sql
end
def run *args
# conn.verbose = true