qreport 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,6 +1,10 @@
1
+ 2013-10-01 Kurt A. Stephens <ks.github@kurtstephens.com>
2
+ * v0.0.10: New Features.
3
+ * Support CTE queries using "FROM (<subselect>) AS" syntax.
4
+
1
5
  2013-09-24 Kurt A. Stephens <ks.github@kurtstephens.com>
2
6
  * v0.0.9: New Version: Bug fixes.
3
- * Use Connection.verbose_stream.
7
+ * Use Connection#verbose_stream.
4
8
 
5
9
  2013-09-24 Kurt A. Stephens <ks.github@kurtstephens.com>
6
10
  * v0.0.8: Bug fixes, performance improvements, new features.
@@ -32,10 +32,10 @@ module Qreport
32
32
  # Create a report row sequence:
33
33
  run "DROP SEQUENCE IF EXISTS qr_row_seq"
34
34
  run "CREATE TEMPORARY SEQUENCE qr_row_seq"
35
- # Infer base columns, if not specified.
36
- if report_run.base_columns.empty?
37
- infer_base_columns!
38
- end
35
+ # Infer base columns, if not specified.
36
+ if report_run.base_columns.empty?
37
+ infer_base_columns!
38
+ end
39
39
  end
40
40
 
41
41
  # Construct report_table name from column names and types:
@@ -109,7 +109,7 @@ module Qreport
109
109
  begin
110
110
  conn.transaction do
111
111
  # Proof query to infer base columns:
112
- result = run report_run.report_sql, :limit => 0, :arguments => arguments, :verbose => @verbose
112
+ result = run report_sql(sql, :limit => 'LIMIT 0'), :arguments => arguments, :verbose => @verbose
113
113
  base_columns = report_run.base_columns = result.columns
114
114
  end # transaction
115
115
  rescue ::StandardError => exc
@@ -118,16 +118,20 @@ module Qreport
118
118
  base_columns
119
119
  end
120
120
 
121
- def report_sql sql
122
- sql = sql.sub(/\A\s*SELECT\s+/im, <<"END"
121
+ def report_sql sql, opts = { }
122
+ sql = sql.sub(/;\s*\Z/, '')
123
+ sql = <<"END"
123
124
  SELECT
124
125
  :qr_run_id
125
126
  AS "qr_run_id"
126
127
  , nextval('qr_row_seq')
127
128
  AS "qr_run_row"
128
- ,
129
+ , _qr_r_.*
130
+ FROM (
131
+ #{sql}
132
+ ) AS "_qr_r_"
133
+ #{opts[:limit]}
129
134
  END
130
- )
131
135
  sql
132
136
  end
133
137
 
@@ -1,3 +1,3 @@
1
1
  module Qreport
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -89,6 +89,33 @@ END
89
89
  report_run.delete!
90
90
  end
91
91
 
92
+ it "should support CTE queries." do
93
+ report_run = Qreport::ReportRun.new(:name => :counts, :description => 'CTE test')
94
+ report_run.sql = <<"END"
95
+ WITH
96
+ total_users AS
97
+ (
98
+ SELECT count(*) AS total_users
99
+ FROM users
100
+ )
101
+ , total_articles AS
102
+ (
103
+ SELECT count(*) AS total_articles
104
+ FROM articles
105
+ )
106
+ SELECT total_users.*, total_articles.*
107
+ FROM total_users, total_articles;
108
+ END
109
+ report_run.verbose = true
110
+ report_run.run! conn
111
+ report_run.columns.should == [["qr_run_id", "bigint"], ["qr_run_row", "bigint"], ["total_users", "bigint"], ["total_articles", "bigint"]]
112
+ rows = report_run.select.rows
113
+ rows.size.should == 1
114
+ row = rows[0]
115
+ row['total_users'].should == 10
116
+ row['total_articles'].should == 100
117
+ end
118
+
92
119
  it "should support :~ {{PATTERN}} {{EXPR}}." do
93
120
  report_run = Qreport::ReportRun.new(:name => :users_with_articles, :description => 'last 24 hours')
94
121
  now = Time.now
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qreport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-25 00:00:00.000000000 Z
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -164,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: 3795772995723267023
167
+ hash: -862269867070365342
168
168
  required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  none: false
170
170
  requirements:
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  segments:
175
175
  - 0
176
- hash: 3795772995723267023
176
+ hash: -862269867070365342
177
177
  requirements: []
178
178
  rubyforge_project:
179
179
  rubygems_version: 1.8.25