
Error while running raw SQL query on DataMapper
Reported by filipeamoreira | November 18th, 2010 @ 03:33 AM
I'm building a reporting app using Jruby(1.5.5 on Ubuntu 64) (Sinatra + DataMapper + SQL Server 2000) and what I need is to get, for example, the top 10 bestseller products. The legacy database that I'm querying has a Transaction table (sales ledger info) and a Customer table. At the moment I have 2 models that map to each of those tables.
The info I need can be be retrieved using something like this in SQL:
SELECT TOP 10 DET_STOCK_CODE, SUM(DET_GROSS) FROM [Table Name]
WHERE DET_STOCK_CODE IS NOT NULL GROUP BY DET_STOCK_CODE ORDER BY
SUM(DET_GROSS) DESC
As far as I know (and I'm a noob) there is no way to actually use
an ORM to get this query so I had to go down to metal and use raw
SQL.
When I run the command: repository.adapter.select(" SQL query here")
I get this error:
interning empty string
ArgumentError: interning empty string from
/home/guto/.rvm/gems/jruby-1.5.5@report-sinatra/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:270:in
select_fields' from
/home/guto/.rvm/gems/jruby-1.5.5@report-sinatra/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:270:inmap'
from
/home/guto/.rvm/gems/jruby-1.5.5@report-sinatra/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:270:in
select_fields' from
/home/guto/.rvm/gems/jruby-1.5.5@report-sinatra/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:39:inselect'
from
/home/guto/.rvm/gems/jruby-1.5.5@report-sinatra/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:260:in
with_connection' from
/home/guto/.rvm/gems/jruby-1.5.5@report-sinatra/gems/dm-do-adapter-1.0.2/lib/dm-do-adapter/adapter.rb:33:inselect'
from (irb):4
Any help or suggestions to do this in a better way is greatly appreciated.
Comments and changes to this ticket
-
filipeamoreira November 18th, 2010 @ 05:05 AM
The problem was with my query. Had to add 'as total' to 'SUM(DET_GROSS)' to name the returning column.
Sorry about that.
-
Martin Gamsjaeger (snusnu) November 19th, 2010 @ 02:03 PM
- State changed from new to not-applicable
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »