Included modules
Public Instance methods
connect
(server)
Transfer the :user option to the :username option.
[show source]
# File lib/sequel/adapters/tinytds.rb, line 11 def connect(server) opts = server_opts(server) opts[:username] = opts[:user] c = TinyTds::Client.new(opts) c.query_options.merge!(:cache_rows=>false) if (ts = opts[:textsize]) sql = "SET TEXTSIZE #{typecast_value_integer(ts)}" log_yield(sql){c.execute(sql)} end c 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, line 31 def execute(sql, opts=OPTS) synchronize(opts[:server]) do |c| begin m = opts[:return] r = nil if (args = opts[:arguments]) && !args.empty? types = [] values = [] args.each_with_index do |(k, v), i| v, type = ps_arg_type(v) types << "@#{k} #{type}" values << "@#{k} = #{v}" end case m when :do sql = "#{sql}; SELECT @@ROWCOUNT AS AffectedRows" single_value = true when :insert sql = "#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident" single_value = true end sql = "EXEC sp_executesql N'#{c.escape(sql)}', N'#{c.escape(types.join(', '))}', #{values.join(', ')}" log_yield(sql) do r = c.execute(sql) r.each{|row| return row.values.first} if single_value end else log_yield(sql) do r = c.execute(sql) return r.send(m) if m end end yield(r) if block_given? rescue TinyTds::Error => e raise_error(e, :disconnect=>!c.active?) ensure r.cancel if r && c.sqlsent? end end end
execute_ddl
(sql, opts=OPTS)
Execute the DDL sql
on the database and return nil.
[show source]
# File lib/sequel/adapters/tinytds.rb, line 84 def execute_ddl(sql, opts=OPTS) execute(sql, opts.merge(:return=>:each)) nil end
execute_dui
(sql, opts=OPTS)
Return the number of rows modified by the given sql
.
[show source]
# File lib/sequel/adapters/tinytds.rb, line 73 def execute_dui(sql, opts=OPTS) execute(sql, opts.merge(:return=>:do)) end
execute_insert
(sql, opts=OPTS)
Return the value of the autogenerated primary key (if any) for the row
inserted by the given sql
.
[show source]
# File lib/sequel/adapters/tinytds.rb, line 79 def execute_insert(sql, opts=OPTS) execute(sql, opts.merge(:return=>:insert)) end