Skip to content

Instantly share code, notes, and snippets.

View metaskills's full-sized avatar
🧠
Adding Digital Intelligence

Ken Collins metaskills

🧠
Adding Digital Intelligence
View GitHub Profile
# Using MySQL2 Gem
data = Topic.connection.send(:select,"SELECT `topics`.* FROM `topics`")
data # => [{"group"=>nil, "author_name"=>"David", "title"=>"The First Topic", "parent_title"=>nil, "approved"=>0, "id"=>1, "type"=>nil, "replies_count"=>1, "bonus_time"=>Sat Jan 01 09:28:00 UTC 2000, "parent_id"=>nil, "content"=>"Have a nice day", "last_read"=>Thu, 15 Apr 2004, "written_on"=>Wed Jul 16 10:28:11 UTC 2003, "author_email_address"=>"[email protected]"},
{"group"=>nil, "author_name"=>"Mary", "title"=>"The Second Topic of the day", "parent_title"=>nil, "approved"=>1, "id"=>2, "type"=>"Reply", "replies_count"=>0, "bonus_time"=>nil, "parent_id"=>1, "content"=>"Have a nice day", "last_read"=>nil, "written_on"=>Thu Jul 15 10:28:00 UTC 2004, "author_email_address"=>nil},
{"group"=>nil, "author_name"=>"Carl", "title"=>"The Third Topic of the day", "parent_title"=>nil, "approved"=>1, "id"=>3, "type"=>nil, "replies_count"=>1, "bonus_time"=>nil, "parent_id"=>nil, "content"=>"I'm a troll"
require 'bench_press'
extend BenchPress
author 'Ken Collins'
summary 'Iterate over rows of array data.'
reps 10_000
ROWS = [
[1, 'Test', 'Body copy', Time.now],
require 'bench_press'
extend BenchPress
author 'Ken Collins'
summary "Check and populate a options hash"
reps 100_000
measure "Hash#key?" do
o = {}
require 'bench_press'
extend BenchPress
author 'Ken Collins'
summary 'Object class inspection vs duck typing.'
reps 100_000
module Foo
class Bar
require 'bench_press'
require 'odbc'
extend BenchPress
author 'Ken Collins'
summary 'Best way to get column names from an ODBC statement handle.'
reps 1000
require 'bench_press'
require 'odbc'
extend BenchPress
author 'Ken Collins'
summary 'Best way to fetch results from an ODBC statement handle.'
reps 1000
module ActiveRecord
module ConnectionAdapters
module Sqlserver
module DatabaseStatements
def select_one(sql, name = nil)
result = raw_select sql, name, :fetch => :one
(result && result.first.present?) ? result.first : nil
end
Thread ID: 2148403500
Total: 2.844094
%self total self wait child calls name
26.76 1.34 0.76 0.00 0.58 2000 Array#each (ruby_runtime:0}
21.82 0.62 0.62 0.00 0.00 1000 ODBC::Statement#fetch_all (ruby_runtime:0}
7.28 0.22 0.21 0.00 0.02 1000 ODBC::Statement#columns (ruby_runtime:0}
4.24 0.12 0.12 0.00 0.00 113000 Array#[] (ruby_runtime:0}
4.09 0.12 0.12 0.00 0.00 1000 ODBC::Database#run (ruby_runtime:0}
2.71 0.08 0.08 0.00 0.00 58000 Kernel#respond_to? (ruby_runtime:0}
diff --git a/lib/active_record/connection_adapters/sqlserver/database_statements.rb b/lib/active_record/connection_adapters/sqlserver/database_statements.rb
index f7f2101..9bab632 100644
--- a/lib/active_record/connection_adapters/sqlserver/database_statements.rb
+++ b/lib/active_record/connection_adapters/sqlserver/database_statements.rb
@@ -256,25 +256,16 @@ module ActiveRecord
def handle_to_names_and_values_odbc(handle, options={})
case options[:fetch]
when :all, :one
- rows = if options[:fetch] == :all
- handle.fetch_all || []
(kencollins@station) - (~)
∴ tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v0.82
freetds.conf directory: /opt/local/etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 5.0