Skip to content

Commit 188a1c0

Browse files
committed
Restore wiki details
1 parent 9d380a3 commit 188a1c0

6 files changed

+737
-8
lines changed

‎README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ The SQL Server adapter for ActiveRecord. If you need the adapter for SQL Server
1313

1414
#### Testing Rake Tasks Support
1515

16-
This is a long story, but if you are not working with a legacy database and you can trust your schema.rb to setup your local development or test database, then we have adapter level support for rails :db rake tasks. Please read this wiki page for full details.
17-
18-
http://wiki..com/rails-sqlserver/activerecord-sqlserver-adapter/rails-db-rake-tasks
19-
16+
This is a long story, but if you are not working with a legacy database and you can trust your schema.rb to setup your local development or test database, then we have adapter level support for rails :db rake tasks. Please read [this guide](guides/RAKE_DB_TASKS.md) for full details.
2017

2118
#### Date/Time Data Type Hinting
2219

@@ -202,10 +199,7 @@ gem 'tiny_tds'
202199
gem 'activerecord-sqlserver-adapter', '~> 4.0.0'
203200
```
204201

205-
If you want to use ruby ODBC, please use at least version 0.99992 since that contains fixes for both native types as well as fixes for proper encoding support under 1.9. If you have any troubles installing the lower level libraries for the adapter, please consult the wiki pages for various platform installation guides. Tons of good info can be found and we ask that you contribute too!
206-
207-
http://wiki..com/rails-sqlserver/activerecord-sqlserver-adapter/platform-installation
208-
202+
If you want to use ruby ODBC, please use at least version 0.99992 since that contains fixes for both native types as well as fixes for proper encoding support under 1.9. If you have any troubles installing the lower level libraries for the adapter, please consult the [guide pages](guides/PLATAFORM_INSTALLATION.md) for various platform installation guides. Tons of good info can be found and we ask that you contribute too!
209203

210204

211205
## Contributing

‎guides/PLATAFORM_INSTALLATION.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## TinyTDS Makes Things Easy
2+
3+
Most of the platform installation wiki pages were written when ODBC was the preferred connection mode for the adapter. The modern connection mode is is DBLIB and that uses the [`TinyTDS gem`](https://.com/rails-sqlserver/tiny_tds). Please read the [[Using TinyTDS]] page which covers all the details for all platforms.
4+
5+
## Older Platform Installation Pages
6+
7+
Headings that have a __*tested*__ after it have been confirmed to pass all the adapters test suite. If you have found that a method that is marked as __*untested*__ does pass all the tests, please let us know and/or update the wiki.
8+
9+
- [Platform Installation - Mac](PLATAFORM_INSTALLATION_MAC.md)
10+
- [Platform Installation - Ubuntu](PLATAFORM_INSTALLATION_UBUNTU.md)
11+
- [Platform Installation - Windows](PLATAFORM_INSTALLATION_WINDOWS.md)

‎guides/PLATAFORM_INSTALLATION_MAC.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## MacPorts 1.8/1.9 __[tested]__
2+
3+
The method for getting the SQL Server stack on Mac OS X is pretty much the same no matter which OS version you have. This article covers some of the finer points of Snow Leopard and x86_64 compatibility but can be applied to pretty much any version that MacPorts targets.
4+
5+
"The Ultimate OS X Snow Leopard Stack For Rails Development: <br/>x86_64, MacPorts, Ruby 1.8/1.9, SQL Server & More":http://www.metaskills.net/2009/9/5/the-ultimate-os-x-snow-leopard-stack-for-rails-development-x86_64-macports-ruby-1-8-1-9-sql-server-more
6+
7+
## MacPorts Base w/REE (Ruby Enterprise Edition) __[tested]__
8+
9+
Recently, I have built on the article above and written another on how to use Ruby Enterprise Edition with the SQL Server stack. The title is "Installing REE With The Snow Leopard SQL Server Stack":http://www.metaskills.net/2009/10/27/installing-ree-with-the-snow-leopard-sql-server-stack
10+
11+
## MacPorts Base Using RVM For Additional Rubies __[tested]__
12+
13+
Being the maintainer of the SQL Server adapter, this is the setup I use with RVM to install additional ruby interpreters with the unixODBC ruby gem. "The RVM Ruby API - Setting Up A CI System For The SQL Server Adapter":http://metaskills.net/2010/7/30/the-rvm-ruby-api
14+
15+
## Mac's Native w/iODBC __[tested]__
16+
17+
Using the built in iODBC with Mac OS 10.6.0 will cause a segmentation fault with FreeTDS. A is available at "iODBC.org":http://www.iodbc.org/dataspace/iodbc/wiki/iODBC/Downloads
18+
19+
This package contains a bug-fix for the version of iODBC provided by Apple, installing in /usr; this is recommend for compiling interfaces such as Perl DBD::ODBC, the Ruby ODBC bridge and PHP: Mac OS X (10.5 Leopard, 10.6 Snow Leopard) iodbc-usr-sdk.zip
20+
21+
penwellr: I installed FreeTDS on 10.6 with the above using MacPorts. After that I was able to establish a connection using a DSNless string such as the following settings:
22+
23+
<pre>
24+
production:
25+
adapter: sqlserver
26+
mode: :ODBC
27+
username: sa
28+
password: password_goes_here
29+
database: database_goes_here
30+
dsn: DRIVER=/opt/local/lib/libtdsodbc.so;SERVER=server_goes_here;DATABASE=database_goes_here;UID=sa;PWD=password_goes_here
31+
</pre>
32+
33+
34+
## Homebrew Project-Specific RVM, Passenger, ENV Vars
35+
36+
Put together by Brennan Dunn.
37+
38+
"Homebrew Project-Specific RVM, Passenger, ENV Vars":http://gist..com/279686
39+
40+
## Homebrew All The Way w/unixODBC __[untested]__
41+
42+
Hugh Evans wrote a simple article that details how far HomeBrew has come and possibly how simple it is to use now for the adapter.
43+
44+
"Homebrew, FreeTDS and RubyODBC":http://hughevans.net/2009/11/05/homebrew-ruby-odbc
45+
46+
47+
## Making Sure Your LOCALE setting is UTF-8
48+
49+
Jon Kinney wrote this article on making sure your local settings are correct for the FreeTDS connection to SQL Server.
50+
51+
"Change locale on os x snow leopard for FreeTDS functionality":http://jonkinney.com/articles/2009/11/23/change-locale-on-os-x-snow-leopard-for-freetds-functionality
+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
## TinyTDS Note
2+
3+
Current versions of the adapter use TinyTDS rendering much of this documentation obsolete. You can still follow this guide but should be able to skip the Unix ODBC sections. Then look at [[Using TinyTDS]] for more info.
4+
5+
## Configure SQL Server 2008
6+
7+
By default the server does not listen on a TCP port. Enable it following
8+
these "instructions.":http://msdn.microsoft.com/en-us/library/bb909712.aspx
9+
10+
## FreeTDS
11+
12+
This package implements the TDS protocol between SQL Server and the Ubuntu box.
13+
The Ubuntu packages for this are:
14+
15+
@sudo apt-get install freetds-dev freetds-bin tdsodbc@
16+
17+
## UnixODBC
18+
19+
This package implements and ODBC layer over FreeTDS The Ubuntu packages for
20+
this are:
21+
22+
@sudo apt-get install unixodbc unixodbc-dev@
23+
24+
## Configure FreeTDS
25+
26+
FreeTDS needs a configuration file named /etc/freetds/freetds.conf.
27+
28+
The example below has two entries. The first entry, [developer], tells FreeTDS how to
29+
connect to a named SQL Server 2008 instance named DEVELOPER.
30+
31+
The second entry, [production], tells FreeTDS how to connect to the default SQL Server
32+
instance. In this case no 'instance' parameter is required.
33+
34+
<pre>
35+
[developer]
36+
host = endor
37+
port = 1433
38+
instance = DEVELOPER # connect to a named instance
39+
tds version = 8.0
40+
client charset = UTF-8
41+
42+
[production]
43+
host = endor
44+
port = 1433
45+
tds version = 8.0
46+
client charset = UTF-8
47+
</pre>
48+
49+
## Test FreeTDS
50+
51+
Use the command line client sqsh to test your FreeTDS configuration.
52+
53+
@sudo apt-get install sqsh@
54+
55+
For example, to connect to the developer database and perform a count on the people
56+
table do this:
57+
58+
@sqsh -S developer -U database_username -P database_password@
59+
60+
A sqsh prompt should open up.
61+
<pre>
62+
> use project_development
63+
> go
64+
> select count(*) from people
65+
> go
66+
</pre>
67+
68+
You should see the result of the count.
69+
70+
## Configure UnixODBC
71+
72+
Tell UnixODBC where the FreeTDS driver is. In /etc/odbcinst.ini put the
73+
following:
74+
75+
<pre>
76+
[FreeTDS]
77+
Description = TDS driver (Sybase/MS SQL)
78+
Driver = /usr/lib/odbc/libtdsodbc.so
79+
Setup = /usr/lib/odbc/libtdsS.so
80+
CPTimeout =
81+
CPReuse =
82+
FileUsage = 1
83+
</pre>
84+
85+
or
86+
Ubuntu after to 12.04 has a different odbc path.
87+
<pre>
88+
[FreeTDS]
89+
Description = TDS driver (Sybase/MS SQL)
90+
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
91+
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
92+
CPTimeout =
93+
CPReuse =
94+
FileUsage = 1
95+
</pre>
96+
## Create the ODBC entries for you databases
97+
98+
ODBC DSN entries are defined in /etc/odbc.ini.
99+
100+
Note that the names you give these entries are the names you'll use in your
101+
rails database.yml file.
102+
103+
The template for an odbc.ini entry is:
104+
105+
<pre>
106+
[dsn] #this is the name you use for the 'dsn' field in your rails database.yml
107+
Driver = FreeTDS
108+
Description = ODBC connection via FreeTDS
109+
Trace = No
110+
Servername = myserver # This is the name of an entry in your /etc/freetds/freetds.conf file
111+
Database = actual_database_name # This is the name of a database in your SQL Server instance.
112+
</pre>
113+
114+
My /etc/odbc.ini looks like this:
115+
116+
<pre>
117+
[project_development]
118+
Driver = FreeTDS
119+
Description = ODBC connection via FreeTDS
120+
Trace = No
121+
Servername = developer
122+
Database = project_development
123+
124+
[project_test]
125+
Driver = FreeTDS
126+
Description = ODBC connection via FreeTDS
127+
Trace = No
128+
Servername = developer
129+
Database = test
130+
131+
[project_production]
132+
Driver = FreeTDS
133+
Description = ODBC connection via FreeTDS
134+
Trace = No
135+
Servername = production
136+
Database = project_production
137+
</pre>
138+
139+
## Test UnixODBC
140+
141+
You can test your ODBC configuration with the isql command. For example:
142+
143+
<pre>
144+
isql -v project_development database_username password
145+
SQL> select count(*) from people;
146+
</pre>
147+
148+
returns the count of records in the people table.
149+
150+
## Install ruby-odbc
151+
152+
ruby-odbc is the ruby binding to the UnixODBC library.
153+
154+
h3. Install ruby-odbc from apt
155+
156+
On Ubuntu install the package libodbc-ruby1.8
157+
158+
@sudo apt-get install libodbc-ruby1.8@
159+
160+
h3. Install ruby-odbc from source (when the installation from apt doesn't work)
161+
162+
The ruby-odbc library is available in the apt repository and the version in apt has worked in the past, but if the ruby-odbc layer returns an error like
163+
@ODBC::Error: INTERN (0) [RubyODBC]Cannot allocate SQLHENV@
164+
then try installing from source.
165+
166+
The version in apt is compiled to dynamically load the odbc library at run time. This allows ruby-odbc to pick between the iODBC library and the UnixODBC library. There are cases where ruby-odbc is unable to load the UnixODBC library at run time. This behavior can be changed at compile time.
167+
168+
First remove the apt package if you installed it.
169+
@sudo apt-get remove librubyodbc-ruby1.8@
170+
171+
Get the latest source package from "http://www.ch-werner.de/rubyodbc/":http://www.ch-werner.de/rubyodbc/.
172+
173+
Follow the instructions in the README, using the following command to disable dynamically loading the odbc library at runtime (the --disable-dlopen is the key bit):
174+
175+
@ruby -Cext extconf.rb --disable-dlopen@
176+
177+
h3. Test ruby-odbc using irb
178+
<pre>
179+
irb > require 'odbc'
180+
irb > ODBC.connect("dsn", "username", "password")
181+
</pre>
182+
183+
If you don't get an error ruby-odbc is good to go.
184+
185+
## Install The Rails Adapter
186+
187+
Follow the Installation instructions in the adapter's README, located here:
188+
"README":http://.com/rails-sqlserver/2000-2005-adapter/tree/master
189+
190+
Scroll down to the "Installation" section.
191+
192+
## Setup your database.yml
193+
194+
The database.yml setup is pretty simple. There is a special case for the 'test'
195+
entry. If your test database name doesn't match the DSN name for that database
196+
you must explicitly set the database name by assigning to the database field.
197+
198+
<pre>
199+
production:
200+
adapter: sqlserver
201+
mode: odbc
202+
dsn: project_production
203+
username: dbuser
204+
password: password
205+
encoding: utf8
206+
207+
development:
208+
adapter: sqlserver
209+
mode: odbc
210+
dsn: project_development
211+
username: dbuser
212+
password: password
213+
encoding: utf8
214+
215+
test:
216+
adapter: sqlserver
217+
mode: odbc
218+
dsn: project_test
219+
database: test #This must be the real name of the database on the server, not the ODBC DSN! Only required for test.
220+
username: dbuser
221+
password: password
222+
encoding: utf8
223+
</pre>
224+
225+
## Test that the application can talk to the database
226+
227+
Enter the console and query a table using active_record:
228+
229+
<pre>
230+
script/console
231+
> Person.count
232+
</pre>
233+
234+
## One last bit of Rails hackery.
235+
236+
There are several places where Rails' lib/tasks/database.rake assumes it is
237+
installed on windows and calls oslq. The test:purge task does this so you can't
238+
run your tests from Ubuntu. My solution is to simply edit that task in place like this:
239+
240+
<pre>
241+
when "sqlserver"
242+
- dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
243+
- `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
244+
- `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
245+
+ ActiveRecord::Base.clear_active_connections!
246+
+ ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
247+
when "oci", "oracle"
248+
ActiveRecord::Base.establish_connection(:test)
249+
</pre>

0 commit comments

Comments
 (0)