DBI/unixODBC/FreeTDS weird problems on Linux

Hey :slight_smile:

I’m trying to migrate my rails app that uses an MS SQL server to Linux.
I’ve setup freetds and unixodbc, installed ruby-dbi and ruby-odbc. isql
and tsql work fine with this query:

SELECT TOP 1 * FROM Item WHERE (Item.Itemnumber = ‘9780444422286’)

This query is taken from the error html output of my app when hitting
the page that executes that query. It fails stating that,

ActiveRecord::StatementInvalid in ItemsController#show
DBI::DatabaseError: INTERN (0) [RubyODBC]No data found: SELECT TOP 1 *
FROM Item WHERE (Item.Itemnumber = ‘9780444422286’)

Opening a console in RadRails and doing the same,

Loading development environment.

dbh = DBI.connect(‘dbi:ODBC:PolyBookDSN’, ‘sa’, ‘adminpassword’)
dbh = DBI.connect(‘dbi:ODBC:PolyBookDSN’, ‘sa’, ‘adminpassword’)
=> #<DBI::DatabaseHandle:0xb747063c @trace_mode=2,
@handle=#<DBI::DBD::ODBC::Database:0xb7470434 @attr={},
@handle=#ODBC::Database:0xb7470470>, @trace_output=#IO:0xb7cf0028>

dbh.execute(“SELECT TOP 1 * FROM Item WHERE (Item.Itemnumber = ‘9780444422286’)”)
dbh.execute(“SELECT TOP 1 * FROM Item WHERE (Item.Itemnumber =
‘9780444422286’)”)
=> #<DBI::StatementHandle:0xb74542fc @cols=[“Itemnumber”, “ISBNP”,
“ItemType”, “TitlePrefix”, “TitleMain”, “TitleVolumeNo”, “TitleVolume”,
“TitleSub”, “TitleSeries”, “TitleSeriesVolumeNo”, “Edition”, “Imprint”,
“ImprintID”, “PublisherID”, “PublisherType”, “DescrLong”, “DescrPoly”,
“Contents”, “KeyWordsBG”, “KeyWordsTitle”, “BookFeatured”,
“AvailStatusCode”, “PublicationDate”, “MarketCode”, “PriceBasis”,
“PriceDiscounted”, “PostageFree”, “DataSourceID”, “ItemGroup”,
“LineDiscGroup”, “Blocked”, “Popularity”, “TrashType”], @trace_mode=2,
@prepared=false, @handle=#<DBI::DBD::ODBC::Statement:0xb7454248
@arr=[], @params=[], @handle=#ODBC::Statement:0xb7454284>,
@fetchable=true, @row=[nil, nil, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
@trace_output=#IO:0xb7cf0028>


So, there’s connectivity, the column names are there, but the data is
empty. Doing the query in isql using the same DSN, I get data, too…

What am I missing?

I’m having the same class of problem on Solaris using
FreeTDS/UnixODBC/RubyODBC. Doing something as simple as
Roster.find(:all) will return the error:

ActiveRecord::StatementInvalid: DBI::DatabaseError: INTERN (0)
[RubyODBC]No data found: SELECT * FROM roster

BUT, if you do Roster.find(:first), it finds the first record, no
problem. Also, doing “SELECT * FROM roster” using the command line tool
that froms with FreeTDS works fine as well.

I can’t determine if this is a RubyODBC problem or something with Rails.

The database table “roster” is fairly large, but not unreasonable at
29926 rows.

Daniel Smedegaard B. wrote:

Hey :slight_smile:

I’m trying to migrate my rails app that uses an MS SQL server to Linux.
I’ve setup freetds and unixodbc, installed ruby-dbi and ruby-odbc. isql
and tsql work fine with this query:

SELECT TOP 1 * FROM Item WHERE (Item.Itemnumber = ‘9780444422286’)

This query is taken from the error html output of my app when hitting
the page that executes that query. It fails stating that,

ActiveRecord::StatementInvalid in ItemsController#show
DBI::DatabaseError: INTERN (0) [RubyODBC]No data found: SELECT TOP 1 *
FROM Item WHERE (Item.Itemnumber = ‘9780444422286’)

Opening a console in RadRails and doing the same,

Loading development environment.

dbh = DBI.connect(‘dbi:ODBC:PolyBookDSN’, ‘sa’, ‘adminpassword’)
dbh = DBI.connect(‘dbi:ODBC:PolyBookDSN’, ‘sa’, ‘adminpassword’)
=> #<DBI::DatabaseHandle:0xb747063c @trace_mode=2,
@handle=#<DBI::DBD::ODBC::Database:0xb7470434 @attr={},
@handle=#ODBC::Database:0xb7470470>, @trace_output=#IO:0xb7cf0028>

dbh.execute(“SELECT TOP 1 * FROM Item WHERE (Item.Itemnumber = ‘9780444422286’)”)
dbh.execute(“SELECT TOP 1 * FROM Item WHERE (Item.Itemnumber =
‘9780444422286’)”)
=> #<DBI::StatementHandle:0xb74542fc @cols=[“Itemnumber”, “ISBNP”,
“ItemType”, “TitlePrefix”, “TitleMain”, “TitleVolumeNo”, “TitleVolume”,
“TitleSub”, “TitleSeries”, “TitleSeriesVolumeNo”, “Edition”, “Imprint”,
“ImprintID”, “PublisherID”, “PublisherType”, “DescrLong”, “DescrPoly”,
“Contents”, “KeyWordsBG”, “KeyWordsTitle”, “BookFeatured”,
“AvailStatusCode”, “PublicationDate”, “MarketCode”, “PriceBasis”,
“PriceDiscounted”, “PostageFree”, “DataSourceID”, “ItemGroup”,
“LineDiscGroup”, “Blocked”, “Popularity”, “TrashType”], @trace_mode=2,
@prepared=false, @handle=#<DBI::DBD::ODBC::Statement:0xb7454248
@arr=[], @params=[], @handle=#ODBC::Statement:0xb7454284>,
@fetchable=true, @row=[nil, nil, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
@trace_output=#IO:0xb7cf0028>


So, there’s connectivity, the column names are there, but the data is
empty. Doing the query in isql using the same DSN, I get data, too…

What am I missing?

Hi, I was having the same problem and found a fix(so to speak) here:

http://groups.google.com.au/group/rubyonrails-talk/browse_thread/thread/82db43270d2a0d59/2aa97ff83907fdc3?lnk=st&q=DBI%3A%3ADatabaseError%3A+INTERN+(0)+[RubyODBC]+No+data+found&rnum=3&hl=en#2aa97ff83907fdc3

Brad

On Feb 16, 9:17 am, David M. [email protected]