#1447 ✓not-applicable
filipeamoreira

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

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Pages