0
class Connection < DataObjects::Connection
0
include_class 'java.sql.DriverManager'
0
options = Hash[*uri.query.split(/[&=]/)].inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
0
url = uri.path.dup["/"] = ""
0
include_class(options[:driver])
0
@connection = DriverManager.get_connection("jdbc:#{options[:protocol]}:#{url}", uri.user, uri.password)
0
def execute_non_query(*args)
0
- sql = @connection.jdbc_connection.create_statement
0
- return nil if (updcount = sql.execute_update(@text)) < 0
0
- Result.new(self, updcount, key)
0
- # create a result object with the number of affected rows and the created id, if any
0
+ sql = @connection.jdbc_connection.create_statement
0
+ return nil if (updcount = sql.execute_update(@text)) < 0
0
+ Result.new(self, updcount, key)
0
+ # create a result object with the number of affected rows and the created id, if any
0
def execute_reader(*args)
0
- # escape all parameters given and pass them to query
0
- # if no response return nil
0
- # save the field count
0
- # instantiate a new reader
0
- # pass the response to the reader
0
- # mark the reader as opened
0
- # save the field_count in reader
0
- # if no types passed, guess the types
0
- # guess the type if no types passed
0
- # set the reader @field_names and @types (guessed or otherwise)
0
- # yield the reader if a block is given, then close it
0
+ # escape all parameters given and pass them to query
0
+ # if no response return nil
0
+ # save the field count
0
+ # instantiate a new reader
0
+ # pass the response to the reader
0
+ # mark the reader as opened
0
+ # save the field_count in reader
0
+ # if no types passed, guess the types
0
+ # guess the type if no types passed
0
+ # set the reader @field_names and @types (guessed or otherwise)
0
+ # yield the reader if a block is given, then close it
0
sql = @connection.jdbc_connection.create_statement()
0
-
Reader.new(sql.execute_query(@text), @types)
0
+
Reader.new(sql.execute_query(@text), @types)
0
class Result < DataObjects::Result
0
class Transaction < DataObjects::Transaction
0
class Reader < DataObjects::Reader
0
include_class 'java.sql.Types'
0
def initialize(result, types)
0
- @meta_data = result.meta_data
0
- @types = types || java_types_to_ruby_types(@meta_data)
0
+ @meta_data = result.meta_data
0
+ @types = types || java_types_to_ruby_types(@meta_data)
0
def java_types_to_ruby_types(meta_data)
0
- (1 .. meta_data.column_count).map do |i|
0
- case meta_data.column_type(i)
0
- when Types::INTEGER, Types::SMALLINT, Types::TINYINT
0
- when Types::BIT, Types::BOOLEAN
0
- when Types::CHAR, Types::VARCHAR
0
+ (1 .. meta_data.column_count).map do |i|
0
+ case meta_data.column_type(i)
0
+ when Types::INTEGER, Types::SMALLINT, Types::TINYINT
0
+ when Types::BIT, Types::BOOLEAN
0
+ when Types::CHAR, Types::VARCHAR
0
- when Types::DECIMAL, Types::NUMERIC
0
- when Types::FLOAT, Types::DOUBLE
0
+ when Types::DECIMAL, Types::NUMERIC
0
+ when Types::FLOAT, Types::DOUBLE
0
-
raise "No casting rule for type #{meta_data.column_type(i)} (#{meta_data.column_name(i)}). Please report this."
0
+
raise "No casting rule for type #{meta_data.column_type(i)} (#{meta_data.column_name(i)}). Please report this."
0
-
@in_row = (@result.next || nil)
0
+
@in_row = (@result.next || nil)
0
-
raise "error" unless @in_row
0
+
raise "error" unless @in_row
0
- @values = (1 .. @meta_data.column_count).map do |i|
0
- type_cast_value(i - 1, @result.object(i))
0
+ @values = (1 .. @meta_data.column_count).map do |i|
0
+ type_cast_value(i - 1, @result.object(i))
0
def type_cast_value(index, value)
0
- if String == @types[index]
0
- elsif [Fixnum, Bignum].include?(@types[index])
0
+ if String == @types[index]
0
+ elsif [Integer, Fixnum, Bignum].include?(@types[index])
0
elsif BigDecimal == @types[index]
0
-
BigDecimal.new(value.to_string)
0
+
BigDecimal.new(value.to_string)
0
elsif Float == @types[index]
0
- elsif [TrueClass, FalseClass].include?(@types[index])
0
+ elsif [TrueClass, FalseClass].include?(@types[index])
0
elsif Date == @types[index]
0
-
Date.parse(value.to_string)
0
+
Date.parse(value.to_string)
0
elsif DateTime == @types[index]
0
- DateTime.parse(value.to_string)
0
- raise "Oops! Forgot to handle #{@types[index]} (#{value})"
0
+ DateTime.parse(value.to_string)
0
+ raise "Oops! Forgot to handle #{@types[index]} (#{value})"
0
- ccnt = @meta_data.column_count
0
- fields << @meta_data.column_name(i)
0
+ ccnt = @meta_data.column_count
0
+ fields << @meta_data.column_name(i)