sql server - Rails 4 - MS SQL select * statement returning total count -
i'm trying run select statement on table in ms sql server 2008 database within rails application related gem acts-as-taggable-on if helps any.
there no model/controller/activerecord table, doing tags.all (or of normal methods) won't anything.
i'm on arch linux, ruby 2.1.6 rails 4.1.11.
i want "name" field returned, i'll settle on returning of fields select *
statement.
from rails console, these commands i'm running.
sql = "select * tags" activerecord::base.connection.execute(sql)
which returns:
select * tags => 191
what expected 191 rows of fields
(id:integer 4, name:string 255, taggings_count:integer 4)
running similar select statement within ms sql server manager software returns expected output.
the database.yml connected ms sql database.
its sql statement trying run count(*)
query instead of *
query. but, if run count(*)
query, returns 1 instead of 191.
i'm lost, co-workers, on causing this. , internet searches resulted nothing of use.
update: (6/25/15 1pm)
out of curiosity switched database sqlite, , queries work. must incompatibility sql server 2008 , in app.
gemfile:
source 'https://rubygems.org' gem 'rails', '4.1.11' gem 'railties' gem 'actionpack' gem 'activesupport' gem 'will_paginate' gem 'sqlite3' gem 'icalendar', '2.3.0' gem 'formtastic' gem 'rubycas-client' gem 'rake', '10.4.2' gem 'tiny_tds' gem 'selenium-webdriver', '2.46.2' gem 'tilt' gem 'websocket', '1.2.2' gem 'xpath', '2.0.0' gem 'rails3-jquery-autocomplete' gem 'rack' gem 'auto_complete' gem 'dynamic_form' gem 'jquery-timepicker-addon-rails' gem 'email_spec' gem 'acts-as-taggable-on' gem 'rails-dom-testing' gem 'globalid' gem 'sprockets-rails' gem 'rspec-rails' gem 'person_record', :path => "vendor/gems/person_record-0_0_2", :require => "person_record" gem 'activerecord-sqlserver-adapter' gem 'test-unit', '1.2.3' gem 'arel' gem 'sass-rails' gem 'coffee-rails' gem 'uglifier' group :development, :test gem 'capybara', '2.4.4' gem 'rubyzip', '1.1.7' gem 'mocha', '1.1.0', :require => false gem 'byebug' gem 'spring' end group :test gem 'cucumber-rails', :require => false gem 'webrat' gem 'database_cleaner' end # deploy capistrano gem 'capistrano' gem 'capistrano-rails', '1.1.3' gem 'rvm-capistrano', :require => false
try explicitly naming fields in select. also, make sure store result:
result = activerecord::base.connection.execute(sql) result.fetch_row.first;
for debugging, try:
result.each |row| p row.id p row.name etc. end
Comments
Post a Comment