class Sequel::ODBC::Dataset

Public Instance Methods

fetch_rows(sql) { |hash| ... } click to toggle source
    # File lib/sequel/adapters/odbc.rb
 89 def fetch_rows(sql)
 90   execute(sql) do |s|
 91     i = -1
 92     cols = s.columns(true).map{|c| [output_identifier(c.name), c.type, i+=1]}
 93     columns = cols.map{|c| c[0]}
 94     self.columns = columns
 95     s.each do |row|
 96       hash = {}
 97       cols.each do |n,t,j|
 98         v = row[j]
 99         # We can assume v is not false, so this shouldn't convert false to nil.
100         hash[n] = (convert_odbc_value(v, t) if v)
101       end
102       yield hash
103     end
104   end
105   self
106 end

Private Instance Methods

convert_odbc_value(v, t) click to toggle source
    # File lib/sequel/adapters/odbc.rb
110 def convert_odbc_value(v, t)
111   # When fetching a result set, the Ruby ODBC driver converts all ODBC
112   # SQL types to an equivalent Ruby type; with the exception of
113   # SQL_TYPE_DATE, SQL_TYPE_TIME and SQL_TYPE_TIMESTAMP.
114   #
115   # The conversions below are consistent with the mappings in
116   # ODBCColumn#mapSqlTypeToGenericType and Column#klass.
117   case v
118   when ::ODBC::TimeStamp
119     db.to_application_timestamp([v.year, v.month, v.day, v.hour, v.minute, v.second, v.fraction])
120   when ::ODBC::Time
121     Sequel::SQLTime.create(v.hour, v.minute, v.second)
122   when ::ODBC::Date
123     Date.new(v.year, v.month, v.day)
124   else
125     if t == ::ODBC::SQL_BIT
126       v == 1
127     else
128       v
129     end
130   end
131 end
default_timestamp_format() click to toggle source
    # File lib/sequel/adapters/odbc.rb
133 def default_timestamp_format
134   "{ts '%Y-%m-%d %H:%M:%S'}"
135 end
literal_date(v) click to toggle source
    # File lib/sequel/adapters/odbc.rb
137 def literal_date(v)
138   v.strftime("{d '%Y-%m-%d'}")
139 end
literal_false() click to toggle source
    # File lib/sequel/adapters/odbc.rb
141 def literal_false
142   '0'
143 end
literal_true() click to toggle source
    # File lib/sequel/adapters/odbc.rb
145 def literal_true
146   '1'
147 end