155 def fetch_rows(sql)
156 db = @db
157 cps = db.conversion_procs
158 api = db.api
159 execute(sql) do |rs|
160 convert = convert_smallint_to_bool
161 col_infos = []
162 api.sqlany_num_cols(rs).times do |i|
163 _, _, name, _, type = api.sqlany_get_column_info(rs, i)
164 cp = if type == 500
165 cps[500] if convert
166 else
167 cps[type]
168 end
169 col_infos << [output_identifier(name), cp]
170 end
171
172 self.columns = col_infos.map(&:first)
173 max = col_infos.length
174
175 if rs
176 while api.sqlany_fetch_next(rs) == 1
177 i = -1
178 h = {}
179 while (i+=1) < max
180 name, cp = col_infos[i]
181 v = api.sqlany_get_column(rs, i)[1]
182 h[name] = cp && v ? cp.call(v) : v
183 end
184 yield h
185 end
186 end
187 end
188 self
189 end