class Sequel::TinyTDS::Database

  1. lib/sequel/adapters/tinytds.rb
Superclass: Sequel::Database

Public Instance methods

connect(server)

Transfer the :user option to the :username option.

[show source]
   # File lib/sequel/adapters/tinytds.rb
13 def connect(server)
14   opts = server_opts(server)
15   opts[:username] = opts[:user]
16   c = TinyTds::Client.new(opts)
17   c.query_options.merge!(:cache_rows=>false)
18 
19   # SEQUEL6: Default to ansi: true
20   if opts[:ansi]
21     sql = %w(
22       ANSI_NULLS
23       ANSI_PADDING
24       ANSI_WARNINGS
25       ANSI_NULL_DFLT_ON
26       QUOTED_IDENTIFIER
27       CONCAT_NULL_YIELDS_NULL
28     ).map{|v| "SET #{v} ON"}.join(";")
29     log_connection_yield(sql, c){c.execute(sql)}
30   end
31 
32   if (ts = opts[:textsize])
33     sql = "SET TEXTSIZE #{typecast_value_integer(ts)}"
34     log_connection_yield(sql, c){c.execute(sql)}
35   end
36 
37   c
38 end
execute(sql, opts=OPTS)

Execute the given sql on the server. If the :return option is present, its value should be a method symbol that is called on the TinyTds::Result object returned from executing the sql. The value of such a method is returned to the caller. Otherwise, if a block is given, it is yielded the result object. If no block is given and a :return is not present, nil is returned.

[show source]
   # File lib/sequel/adapters/tinytds.rb
46 def execute(sql, opts=OPTS)
47   synchronize(opts[:server]) do |c|
48     begin
49       m = opts[:return]
50       r = nil
51       if (args = opts[:arguments]) && !args.empty?
52         types = []
53         values = []
54         args.each_with_index do |(k, v), i|
55           v, type = ps_arg_type(v)
56           types << "@#{k} #{type}"
57           values << "@#{k} = #{v}"
58         end
59         case m
60         when :do
61           sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows"
62           single_value = true
63         when :insert
64           sql = "#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
65           single_value = true
66         end
67         sql = "EXEC sp_executesql N'#{c.escape(sql)}', N'#{c.escape(types.join(', '))}', #{values.join(', ')}"
68         log_connection_yield(sql, c) do
69           r = c.execute(sql)
70           r.each{|row| return row.values.first} if single_value
71         end
72       else
73         log_connection_yield(sql, c) do
74           r = c.execute(sql)
75           return r.public_send(m) if m
76         end
77       end
78       yield(r) if defined?(yield)
79     rescue TinyTds::Error => e
80       raise_error(e, :disconnect=>!c.active?)
81     ensure
82       r.cancel if r && c.sqlsent? && c.active?
83     end
84   end
85 end
execute_ddl(sql, opts=OPTS)
[show source]
    # File lib/sequel/adapters/tinytds.rb
 99 def execute_ddl(sql, opts=OPTS)
100   opts = Hash[opts]
101   opts[:return] = :each
102   execute(sql, opts)
103   nil
104 end
execute_dui(sql, opts=OPTS)
[show source]
   # File lib/sequel/adapters/tinytds.rb
87 def execute_dui(sql, opts=OPTS)
88   opts = Hash[opts]
89   opts[:return] = :do
90   execute(sql, opts)
91 end
execute_insert(sql, opts=OPTS)
[show source]
   # File lib/sequel/adapters/tinytds.rb
93 def execute_insert(sql, opts=OPTS)
94   opts = Hash[opts]
95   opts[:return] = :insert
96   execute(sql, opts)
97 end