| Class | Sequel::TinyTDS::Database |
| In: |
lib/sequel/adapters/tinytds.rb
|
| Parent: | Sequel::Database |
Transfer the :user option to the :username option.
# File lib/sequel/adapters/tinytds.rb, line 13
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: if (ts = opts[:textsize])
20: sql = "SET TEXTSIZE #{typecast_value_integer(ts)}"
21: log_connection_yield(sql, c){c.execute(sql)}
22: end
23:
24: c
25: end
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.
# File lib/sequel/adapters/tinytds.rb, line 33
33: def execute(sql, opts=OPTS)
34: synchronize(opts[:server]) do |c|
35: begin
36: m = opts[:return]
37: r = nil
38: if (args = opts[:arguments]) && !args.empty?
39: types = []
40: values = []
41: args.each_with_index do |(k, v), i|
42: v, type = ps_arg_type(v)
43: types << "@#{k} #{type}"
44: values << "@#{k} = #{v}"
45: end
46: case m
47: when :do
48: sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows"
49: single_value = true
50: when :insert
51: sql = "#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident"
52: single_value = true
53: end
54: sql = "EXEC sp_executesql N'#{c.escape(sql)}', N'#{c.escape(types.join(', '))}', #{values.join(', ')}"
55: log_connection_yield(sql, c) do
56: r = c.execute(sql)
57: r.each{|row| return row.values.first} if single_value
58: end
59: else
60: log_connection_yield(sql, c) do
61: r = c.execute(sql)
62: return r.public_send(m) if m
63: end
64: end
65: yield(r) if block_given?
66: rescue TinyTds::Error => e
67: raise_error(e, :disconnect=>!c.active?)
68: ensure
69: r.cancel if r && c.sqlsent? && c.active?
70: end
71: end
72: end
# File lib/sequel/adapters/tinytds.rb, line 86
86: def execute_ddl(sql, opts=OPTS)
87: opts = Hash[opts]
88: opts[:return] = :each
89: execute(sql, opts)
90: nil
91: end
# File lib/sequel/adapters/tinytds.rb, line 74
74: def execute_dui(sql, opts=OPTS)
75: opts = Hash[opts]
76: opts[:return] = :do
77: execute(sql, opts)
78: end