Posted on November 17, 2005 at 5:56 pm

Yeah, I know. But hey, sometimes you gotta live on the edge.

If you don’t already have ODBC talking to MS SQL Server on your Mac, you’ll need to get that set up and tested first.

We need a couple of extra pieces of software to let Rails talk to the server via ODBC.

Ruby-ODBC:

cd /tmp
wget http://www.ch-werner.de/rubyodbc/ruby-odbc-0.996.tar.gz
tar vxzf ruby-odbc-0.996.tar.gz
cd ruby-odbc-0.996
ruby extconf.rb
make
sudo make install

Ruby DBI ODBC driver:

cd /tmp
wget http://rubyforge.org/frs/download.php/655/ruby-dbi-all-0.0.23.tar.gz
tar vxzf ruby-dbi-all-0.0.23.tar.gz
cd ruby-dbi-all
ruby setup.rb config --with=dbi,dbd_odbc
ruby setup.rb setup
sudo ruby setup.rb install

The format of the database.yml will be slightly different than the norm:

development:
  adapter: sqlserver
  mode: odbc
  dsn:  the_dsn_you_created_and_tested_in_iodbc_administrator
  username: username
  password: password

There is currently a bug in script/console that will throw a BUS error when trying to access the database, but everything works outside of the console.

You should also be aware that SQL Server isn’t currently supported very well in Rails. I ran into a couple of bugs today and submitted patches for them:

4 Comments:
Posted on December 16, 2005 at 3:08 pm by Grant Gelinas-Brown

Thanks for the pointers. This certainly get’s me hopeful, but I encounter a load of warnings when executing ‘make’ on the Ruby-ODBC file:


gcc -fno-common -arch ppc -g -Os -pipe -fno-common -arch ppc -pipe -pipe -fno-common -I. -I/usr/lib/ruby/1.8/powerpc-darwin8.0 -I/usr/lib/ruby/1.8/powerpc-darwin8.0 -I. -DHAVE_SQL_H -DHAVE_SQLEXT_H -DHAVE_TYPE_SQLTCHAR -c odbc.c
odbc.c: In function 'get_err_or_info':
odbc.c:761: warning: pointer targets in passing argument 4 of 'SQLError' differ in signedness
odbc.c:761: warning: pointer targets in passing argument 6 of 'SQLError' differ in signedness
odbc.c: In function 'callsql':
odbc.c:949: warning: pointer targets in passing argument 4 of 'SQLError' differ in signedness
odbc.c:949: warning: pointer targets in passing argument 6 of 'SQLError' differ in signedness
odbc.c: In function 'make_coltypes':
odbc.c:1747: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:1755: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:1774: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:1779: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c: In function 'make_pinfo':
odbc.c:1880: warning: passing argument 4 of 'SQLDescribeParam' from incompatible pointer type
odbc.c: In function 'upcase_if':
odbc.c:1994: warning: pointer targets in initialization differ in signedness
odbc.c: In function 'make_col':
odbc.c:2093: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:2109: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:2121: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:2130: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:2139: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:2148: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:2157: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c:2166: warning: passing argument 7 of 'SQLColAttributes' from incompatible pointer type
odbc.c: In function 'dbc_info':
odbc.c:2305: warning: pointer targets in passing argument 6 of 'SQLTables' differ in signedness
odbc.c:2313: warning: pointer targets in passing argument 6 of 'SQLColumns' differ in signedness
odbc.c:2321: warning: pointer targets in passing argument 6 of 'SQLPrimaryKeys' differ in signedness
odbc.c:2332: warning: pointer targets in passing argument 6 of 'SQLStatistics' differ in signedness
odbc.c:2348: warning: pointer targets in passing argument 6 of 'SQLForeignKeys' differ in signedness
odbc.c:2348: warning: pointer targets in passing argument 12 of 'SQLForeignKeys' differ in signedness
odbc.c:2357: warning: pointer targets in passing argument 6 of 'SQLTablePrivileges' differ in signedness
odbc.c:2365: warning: pointer targets in passing argument 6 of 'SQLProcedures' differ in signedness
odbc.c:2374: warning: pointer targets in passing argument 6 of 'SQLProcedureColumns' differ in signedness
odbc.c:2374: warning: pointer targets in passing argument 8 of 'SQLProcedureColumns' differ in signedness
odbc.c:2385: warning: pointer targets in passing argument 7 of 'SQLSpecialColumns' differ in signedness
odbc.c: In function 'stmt_nrows':
odbc.c:3704: warning: passing argument 2 of 'SQLRowCount' from incompatible pointer type
odbc.c: In function 'stmt_cursorname':
odbc.c:3763: warning: pointer targets in passing argument 2 of 'SQLSetCursorName' differ in signedness
odbc.c: In function 'do_fetch':
odbc.c:4082: warning: passing argument 6 of 'SQLGetData' from incompatible pointer type
odbc.c:4115: warning: passing argument 6 of 'SQLGetData' from incompatible pointer type
odbc.c: In function 'stmt_prep_int':
odbc.c:4667: warning: pointer targets in passing argument 2 of 'SQLExecDirect' differ in signedness
odbc.c:4672: warning: pointer targets in passing argument 2 of 'SQLPrepare' differ in signedness
odbc.c: In function 'stmt_exec_int':
odbc.c:4857: warning: passing argument 10 of 'SQLBindParameter' from incompatible pointer type
odbc.c:4889: warning: passing argument 10 of 'SQLBindParameter' from incompatible pointer type
cc -dynamic -bundle -undefined suppress -flat_namespace -L"/usr/lib" -o odbc.bundle odbc.o -liodbc -lpthread -ldl -lobjc

I’m new to all this ‘make’ business…should I assume this is bad?

Any help would be most welcome.
Grant

Posted on December 16, 2005 at 4:26 pm by Admin

The just look like warnings to me. You can probably safely ignore them.

Posted on February 20, 2006 at 3:57 am by James Adam
Posted on February 22, 2006 at 10:09 am by Mark Imbriaco

More specifically, in case it’s not immediately obvious, just edit irb.rb in your ruby lib directory and remove the assignment to $0. Commenting it out makes the problem go away.

Thanks for the tip, James, saved me some time.

Leave a comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>