tiny_tds 0.4.5.rc1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ Makefile
2
+ *.dSYM
3
+ *.o
4
+ *.bundle
5
+ *.so
6
+ *.a
7
+ *.rbc
8
+ mkmf.log
9
+ pkg/
10
+ tmp
11
+ vendor
12
+ lib/tiny_tds/tiny_tds.rb
13
+ .rvmrc
14
+ Gemfile.lock
15
+ misc
16
+ *.gem
17
+ ports
data/CHANGELOG ADDED
@@ -0,0 +1,99 @@
1
+
2
+ * 0.4.5.rc1 *
3
+
4
+ * Release static libs for Windows.
5
+
6
+ * Change how :host/:port are implemented. Now sending "host:port" to :dataserver.
7
+
8
+
9
+ * 0.4.4 *
10
+
11
+ * New :host/:port connection options. Removes need for freetds.conf file.
12
+
13
+
14
+ * 0.4.3 *
15
+
16
+ * New Client#active? method to check for good connection. Always use this abstract method.
17
+
18
+ * Better SYBEWRIT "Write to SQL Server failed." error handling. New Client#dead? check.
19
+
20
+ * Azure tested using latest FreeTDS with submitted patch. https://gist.github.com/889190
21
+
22
+
23
+ * 0.4.2 *
24
+
25
+ * Iconv is a dep only when compiling locally. However, left in the ability to configure it for native gem installation but you must use --enable-iconv before using --with-iconv-dir=/some/dir
26
+
27
+ * Really fix what 0.4.1 was supposed to do, force SYBDBLIB compile.
28
+
29
+
30
+ * 0.4.1 *
31
+
32
+ * Undefine MSDBLIB in case others have explicitly compiled FreeTDS with "MS db-lib source compatibility: yes".
33
+
34
+
35
+ * 0.4.0 *
36
+
37
+ * Allow SYBEICONVI errors to pass thru so that bad data is converted to ? marks.
38
+
39
+ * Build native deps using MiniPortile [Luis Lavena]
40
+
41
+ * Allow Result#fields to be called before iterating over the results.
42
+
43
+ * Two new client helper methods, #sqlsent? and #canceled?. Possible to use these to determine current
44
+ state of the client and the need to use Result#cancel to stop processing active results. It is also
45
+ safe to call Result#cancel over and over again.
46
+
47
+ * Look for the syb headers only.
48
+
49
+
50
+ * 0.3.2 *
51
+
52
+ * Small changes while testing JRuby. Using options hash for connect vs many args.
53
+
54
+
55
+ * 0.3.1 *
56
+
57
+ * Fix bad gem build.
58
+
59
+
60
+ * 0.3.0 *
61
+
62
+ * Access stored procedure return codes.
63
+
64
+ * Make sure dead or not enabled connections are handled.
65
+
66
+ * Fix bad client after timeout & read from server errors.
67
+
68
+
69
+ * 0.2.3 *
70
+
71
+ * Do not use development ruby/version, but simple memoize an eval check on init to find out, for 1.8.6 reflection.
72
+
73
+
74
+ * 0.2.2 *
75
+
76
+ * Fixed failing test in Ruby 1.8.6. DateTime doesn't support fractional seconds greater than 59.
77
+ See: http://redmine.ruby-lang.org/issues/show/1490 [Erik Bryn]
78
+
79
+
80
+ * 0.2.1 *
81
+
82
+ * Compatibility with 32-bit systems. Better cross language testing. [Klaus Gundermann]
83
+
84
+
85
+ * 0.2.0 *
86
+
87
+ * Convert GUID's in a more compatible way. [Klaus Gundermann]
88
+
89
+ * Handle multiple result sets in command buffer or stored procs. [Ken Collins]
90
+
91
+ * Fixed some compiler warnings. [Erik Bryn]
92
+
93
+ * Avoid segfault related to smalldatetime conversion. [Erik Bryn]
94
+
95
+ * Properly encode column names in 1.9. [Erik Bryn]
96
+
97
+
98
+ * 0.1.0 Initial release!
99
+
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+
2
+ source :rubygems
3
+
4
+ group :development do
5
+ gem 'rake', '>= 0.8.7'
6
+ gem 'mini_portile', '0.2.2'
7
+ gem 'rake-compiler', '0.7.7'
8
+ end
9
+
10
+ group :test do
11
+ gem 'mini_shoulda', '0.3.0'
12
+ gem 'activesupport', '2.3.5'
13
+ gem 'bench_press', '0.3.1'
14
+ platforms :mri_18 do
15
+ gem 'ruby-prof', '0.9.1'
16
+ gem 'ruby-debug', '0.10.3'
17
+ end
18
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 Ken Collins, <ken@metaskills.net>
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/NOTES ADDED
@@ -0,0 +1,11 @@
1
+
2
+ TODO
3
+
4
+ * Client & Connection
5
+ - Make a #ping method that does the "SELECT 1" when not closed.
6
+ - Interrupt handler to cancel a bad SELECT * or long SQL. Maybe use dbsetinterrupt
7
+ - Integrate rb_thread_blocking_region where we can in your extension for proper threading in 1.9.2
8
+
9
+ * Result Set
10
+ - See if we can make a binary string of [timestamp] type.
11
+
data/README.rdoc ADDED
@@ -0,0 +1,277 @@
1
+
2
+ = TinyTDS - A modern, simple and fast FreeTDS library for Ruby using DB-Library.
3
+
4
+ The TinyTDS gem is meant to serve the extremely common use-case of connecting, querying and iterating over results to Microsoft SQL Server databases from ruby. Even though it uses FreeTDS's DB-Library, it is NOT meant to serve as direct 1:1 mapping of that complex C API.
5
+
6
+ The benefits are speed, automatic casting to ruby primitives, and proper encoding support. It converts all SQL Server datatypes to native ruby objects supporting :utc or :local time zones for time-like types. To date it is the only ruby client library that allows client encoding options, defaulting to UTF-8, while connecting to SQL Server. It also properly encodes all string and binary data. The motivation for TinyTDS is to become the de-facto low level connection mode for the SQL Server adapter for ActiveRecord. For further details see the special thanks section at the bottom
7
+
8
+ The API is simple and consists of these classes:
9
+
10
+ * TinyTds::Client - Your connection to the database.
11
+ * TinyTds::Result - Returned from issuing an #execute on the connection. It includes Enumerable.
12
+ * TinyTds::Error - A wrapper for all exceptions.
13
+
14
+
15
+ == New & Noteworthy
16
+
17
+ * Works with FreeTDS 0.91
18
+ * Tested on Windows using MiniPortile & RailsInstaller.
19
+ * New :host/:port connection options. Removes need for freetds.conf file.
20
+
21
+
22
+ == Install
23
+
24
+ Installing with rubygems should just work. TinyTDS is tested on ruby version 1.8.6, 1.8.7, 1.9.1, 1.9.2 as well as REE & JRuby.
25
+
26
+ $ gem install tiny_tds
27
+
28
+ Although we search for FreeTDS's libraries and headers, you may have to specify include and lib directories using "--with-freetds-include=/some/local/include/freetds" and "--with-freetds-lib=/some/local/lib"
29
+
30
+
31
+
32
+ == FreeTDS Compatibility
33
+
34
+ TinyTDS is developed for FreeTDS 0.82 & 0.91. It is tested with SQL Server 2000, 2005, 2008 and Azure using TDS Version 8.0. We utilize FreeTDS's db-lib client library. We compile against sybdb.h, undefine MSDBLIB and define SYBDBLIB which means that internally we conform to sybase API to db-lib. TinyTDS will work for both Sybase & Miscrosoft SQL Server. You do NOT need to compile FreeTDS with the "--enable-msdblib" option for our client to work properly. However, please make sure to compile FreeTDS with libiconv support for encodings to work at their best. Run "tsql -C" in your console and check for "iconv library: yes".
35
+
36
+
37
+
38
+ == Data Types
39
+
40
+ Our goal is to support every SQL Server data type and covert it to a logical ruby object. When dates or times are returned, they are instantiated to either :utc or :local time depending on the query options. Under ruby 1.9, all strings are encoded to the connection's encoding and all binary data types are associated to ruby's ASCII-8BIT/BINARY encoding.
41
+
42
+ Below is a list of the data types we plan to support using future versions of FreeTDS. They are associated with SQL Server 2008. All unsupported data types are returned as properly encoded strings.
43
+
44
+ * [date]
45
+ * [datetime2]
46
+ * [datetimeoffset]
47
+ * [time]
48
+
49
+
50
+
51
+ == TinyTds::Client Usage
52
+
53
+ Connect to a database.
54
+
55
+ client = TinyTds::Client.new(:username => 'sa', :password => 'secret', :host => 'mydb.host.net')
56
+
57
+ Creating a new client takes a hash of options. For valid iconv encoding options, see the output of "iconv -l". Only a few have been tested and highly recommended to leave blank for the UTF-8 default.
58
+
59
+ * :username - The database server user.
60
+ * :password - The user password.
61
+ * :dataserver - The name for your server as defined in freetds.conf.
62
+ * :host - Used if :dataserver blank. Removes need for freetds.conf file.
63
+ * :port - Defaults to 1433. Only used if :host is used.
64
+ * :database - The default database to use.
65
+ * :appname - Short string seen in SQL Servers process/activity window.
66
+ * :tds_version - TDS version. Defaults to 80, not recommended to change.
67
+ * :login_timeout - Seconds to wait for login. Default to 60 seconds.
68
+ * :timeout - Seconds to wait for a response to a SQL command. Default 5 seconds.
69
+ * :encoding - Any valid iconv value like CP1251 or ISO-8859-1. Default UTF-8.
70
+ * :azure - Pass true to signal that you are connecting to azure.
71
+
72
+ Use the #active? method to determine if a connection is good. The implementation of this method may change but it should always guarantee that a connection is good. Current it checks for either a closed or dead connection.
73
+
74
+ client.dead? # => false
75
+ client.closed? # => false
76
+ client.active? # => true
77
+ client.execute("SQL TO A DEAD SERVER")
78
+ client.dead? # => true
79
+ client.closed? # => false
80
+ client.active? # => false
81
+ client.close
82
+ client.closed? # => true
83
+ client.active? # => false
84
+
85
+ Escape strings.
86
+
87
+ client.escape("How's It Going'") # => "How''s It Going''"
88
+
89
+ Send a SQL string to the database and return a TinyTds::Result object.
90
+
91
+ result = client.execute("SELECT * FROM [datatypes]")
92
+
93
+
94
+
95
+ == TinyTds::Result Usage
96
+
97
+ A result object is returned by the client's execute command. It is important that you either return the data from the query, most likely with the #each method, or that you cancel the results before asking the client to execute another SQL batch. Failing to do so will yield an error.
98
+
99
+ Calling #each on the result will lazily load each row from the database.
100
+
101
+ result.each do |row|
102
+ # By default each row is a hash.
103
+ # The keys are the fields, as you'd expect.
104
+ # The values are pre-built ruby primitives mapped from their corresponding types.
105
+ # Here's an leemer: http://is.gd/g61xo
106
+ end
107
+
108
+ A result object has a #fields accessor. It can be called before the result rows are iterated over. Even if no rows are returned, #fields will still return the column names you expected. Any SQL that does not return columned data will always return an empty array for #fields. It is important to remember that if you access the #fields before iterating over the results, the columns will always follow the default query option's :symbolize_keys setting at the client's level and will ignore the query options passed to each.
109
+
110
+ result = client.execute("USE [tinytdstest]")
111
+ result.fields # => []
112
+ result.do
113
+
114
+ result = client.execute("SELECT [id] FROM [datatypes]")
115
+ result.fields # => ["id"]
116
+ result.cancel
117
+ result = client.execute("SELECT [id] FROM [datatypes]")
118
+ result.each(:symbolize_keys => true)
119
+ result.fields # => [:id]
120
+
121
+ You can cancel a result object's data from being loading by the server.
122
+
123
+ result = client.execute("SELECT * FROM [super_big_table]")
124
+ result.cancel
125
+
126
+ If the SQL executed by the client returns affected rows, you can easily find out how many.
127
+
128
+ result.each
129
+ result.affected_rows # => 24
130
+
131
+ This pattern is so common for UPDATE and DELETE statements that the #do method cancels any need for loading the result data and returns the #affected_rows.
132
+
133
+ result = client.execute("DELETE FROM [datatypes]")
134
+ result.do # => 72
135
+
136
+ Likewise for INSERT statements, the #insert method cancels any need for loading the result data and executes a SCOPE_IDENTITY() for the primary key.
137
+
138
+ result = client.execute("INSERT INTO [datatypes] ([xml]) VALUES ('<html><br/></html>')")
139
+ result.insert # => 420
140
+
141
+ The result object can handle multiple result sets form batched SQL or stored procedures. It is critical to remember that when calling each with a block for the first time will return each "row" of each result set. Calling each a second time with a block will yield each "set".
142
+
143
+ sql = ["SELECT TOP (1) [id] FROM [datatypes]",
144
+ "SELECT TOP (2) [bigint] FROM [datatypes] WHERE [bigint] IS NOT NULL"].join(' ')
145
+
146
+ set1, set2 = client.execute(sql).each
147
+ set1 # => [{"id"=>11}]
148
+ set2 # => [{"bigint"=>-9223372036854775807}, {"bigint"=>9223372036854775806}]
149
+
150
+ result = client.execute(sql)
151
+
152
+ result.each do |rowset|
153
+ # First time data loading, yields each row from each set.
154
+ # 1st: {"id"=>11}
155
+ # 2nd: {"bigint"=>-9223372036854775807}
156
+ # 3rd: {"bigint"=>9223372036854775806}
157
+ end
158
+
159
+ result.each do |rowset|
160
+ # Second time over (if columns cached), yields each set.
161
+ # 1st: [{"id"=>11}]
162
+ # 2nd: [{"bigint"=>-9223372036854775807}, {"bigint"=>9223372036854775806}]
163
+ end
164
+
165
+ Use the #sqlsent? and #canceled? query methods on the client to determine if an active SQL batch still needs to be processed and or if data results were canceled from the last result object. These values reset to true and false respectively for the client at the start of each #execute and new result object. Or if all rows are processed normally, #sqlsent? will return false. To demonstrate, lets assume we have 100 rows in the result object.
166
+
167
+ client.sqlsent? # = false
168
+ client.canceled? # = false
169
+
170
+ result = client.execute("SELECT * FROM [super_big_table]")
171
+
172
+ client.sqlsent? # = true
173
+ client.canceled? # = false
174
+
175
+ result.each do |row|
176
+ # Assume we break after 20 rows with 80 still pending.
177
+ break if row["id"] > 20
178
+ end
179
+
180
+ client.sqlsent? # = true
181
+ client.canceled? # = false
182
+
183
+ result.cancel
184
+
185
+ client.sqlsent? # = false
186
+ client.canceled? # = true
187
+
188
+ It is possible to get the return code after executing a stored procedure from either the result or client object.
189
+
190
+ client.return_code # => nil
191
+
192
+ result = client.execute("EXEC tinytds_TestReturnCodes")
193
+ result.return_code # => 420
194
+ client.return_code # => 420
195
+
196
+
197
+ == Query Options
198
+
199
+ Every TinyTds::Result object can pass query options to the #each method. The defaults are defined and configurable by setting options in the TinyTds::Client.default_query_options hash. The default values are:
200
+
201
+ * :as => :hash - Object for each row yielded. Can be set to :array.
202
+ * :symbolize_keys => false - Row hash keys. Defaults to shared/frozen string keys.
203
+ * :cache_rows => true - Successive calls to #each returns the cached rows.
204
+ * :timezone => :local - Local to the ruby client or :utc for UTC.
205
+
206
+ Each result gets a copy of the default options you specify at the client level and can be overridden by passing an options hash to the #each method. For example
207
+
208
+ result.each(:as => :array, :cache_rows => false) do |row|
209
+ # Each row is now an array of values ordered by #fields.
210
+ # Rows are yielded and forgotten about, freeing memory.
211
+ end
212
+
213
+ Besides the standard query options, the result object can take one additional option. Using :first => true will only load the first row of data and cancel all remaining results.
214
+
215
+ result = client.execute("SELECT * FROM [super_big_table]")
216
+ result.each(:first => true) # => [{'id' => 24}]
217
+
218
+
219
+
220
+ == Row Caching
221
+
222
+ By default row caching is turned on because the SQL Server adapter for ActiveRecord would not work without it. I hope to find some time to create some performance patches for ActiveRecord that would allow it to take advantages of lazily created yielded rows from result objects. Currently only TinyTDS and the Mysql2 gem allow such a performance gain.
223
+
224
+
225
+
226
+ == Using TinyTDS With Rails & The ActiveRecord SQL Server adapter.
227
+
228
+ As of version 2.3.11 & 3.0.3 of the adapter, you can specify a :dblib mode in database.yml and use TinyTDS as the low level connection mode. The SQL Server adapter can be found using the link below. Also included is a direct link to the wiki article covering common questions when using TinyTDS as the low level connection mode for the adapter.
229
+
230
+ http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Using-TinyTds
231
+
232
+
233
+
234
+ == Using TinyTDS with Azure
235
+
236
+ TinyTDS is fully tested with the Azure platform. You must set the :azure => true connection option when connecting. This is needed to specify the default database name in the login packet since Azure has no notion of "USE [database]". You must use the latest FreeTDS 0.91. FreeTDS must be compiled with OpenSSL too.
237
+
238
+
239
+
240
+ == Development & Testing
241
+
242
+ We use bundler for development. Simply run "bundle install" then "rake" to build the gem and run the unit tests. The tests assume you have created a database named "tinytdstest" accessible by a database owner named "tinytds". Before running the test rake task, you may need to define a pair of environment variables that help the client connect to your specific FreeTDS database server name and which schema (2000, 2005, 2008 or azure) to use. For example:
243
+
244
+ $ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2008
245
+ or
246
+ $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
247
+
248
+ If you are compiling locally using MiniPortile (the default dev setup) and you do not have a user based freetds.conf file with your dataservers, you may have to configure the locally compiled freetds.conf file. You can find it at the ports/<platform>/freetds/<version>/etc/freetds.conf path locally to your repo. In this situation you may have to set the FREETDS environment variable too this full path.
249
+
250
+ For help and support.
251
+
252
+ * Github Source: http://github.com/rails-sqlserver/tiny_tds
253
+ * Github Issues: http://github.com/rails-sqlserver/tiny_tds/issues
254
+ * Google Group: http://groups.google.com/group/rails-sqlserver-adapter
255
+ * IRC Room: #rails-sqlserver on irc.freenode.net
256
+
257
+ Current to do list.
258
+
259
+ * Install an interrupt handler.
260
+ * Allow #escape to accept all ruby primitives.
261
+ * Get bug reports!
262
+
263
+
264
+
265
+ == About Me
266
+
267
+ My name is Ken Collins and I currently maintain the SQL Server adapter for ActiveRecord and wrote this library as my first cut into learning ruby C extensions. Hopefully it will help promote the power of ruby and the rails framework to those that have not yet discovered it. My blog is http://metaskills.net and I can be found on twitter as @metaskills. Enjoy!
268
+
269
+
270
+
271
+ == Special Thanks
272
+
273
+ * Erik Bryn for joining the project and helping me thru a few tight spots. - http://github.com/ebryn
274
+ * To the authors and contributors of the Mysql2 gem for inspiration. - http://github.com/brianmario/mysql2
275
+ * Yehuda Katz for articulating ruby's need for proper encoding support. Especially in database drivers - http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/
276
+ * Josh Clayton of Thoughtbot for writing about ruby C extensions. - http://robots.thoughtbot.com/post/1037240922/get-your-c-on
277
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require "rake/clean"
4
+ require 'rbconfig'
5
+ require 'rake/testtask'
6
+ require 'rake/extensiontask'
7
+ require "rubygems/package_task"
8
+
9
+ def test_libs
10
+ ['lib','test']
11
+ end
12
+
13
+ def test_files
14
+ Dir.glob("test/**/*_test.rb").sort
15
+ end
16
+
17
+ def gemspec
18
+ @clean_gemspec ||= eval(File.read(File.expand_path('../tiny_tds.gemspec', __FILE__)))
19
+ end
20
+
21
+ Rake::TestTask.new do |t|
22
+ t.libs = test_libs
23
+ t.test_files = test_files
24
+ t.verbose = true
25
+ end
26
+
27
+ Gem::PackageTask.new(gemspec) do |pkg|
28
+ pkg.need_tar = false
29
+ pkg.need_zip = false
30
+ end
31
+
32
+ task :compile => ["ports:freetds"] unless ENV['TINYTDS_SKIP_PORTS']
33
+
34
+ Rake::ExtensionTask.new('tiny_tds', gemspec) do |ext|
35
+ ext.lib_dir = 'lib/tiny_tds'
36
+ ext.config_options << "--enable-iconv" unless ENV['TINYTDS_SKIP_PORTS']
37
+ if RUBY_PLATFORM =~ /mswin|mingw/ then
38
+ # Define target for extension (supporting fat binaries).
39
+ RUBY_VERSION =~ /(\d+\.\d+)/
40
+ ext.lib_dir = "lib/tiny_tds/#{$1}"
41
+ else
42
+ ext.cross_compile = true
43
+ ext.cross_platform = ['i386-mingw32']
44
+ ext.cross_config_options << "--disable-lookup"
45
+ end
46
+ end
47
+
48
+ task :build => [:clean, :compile]
49
+
50
+ task :default => [:build, :test]
51
+
52
+ Dir["tasks/*.rake"].sort.each { |f| load f }