# File lib/dbi.rb, line 235
235:         def load_driver(driver_name)
236:             @@driver_monitor.synchronize do
237:                 unless @@driver_map[driver_name]
238:                     dc = driver_name.downcase
239: 
240:                     # caseless look for drivers already loaded
241:                     found = @@driver_map.keys.find {|key| key.downcase == dc}
242:                     return found if found
243: 
244:                     begin
245:                         require "dbd/#{driver_name}"
246:                     rescue LoadError => e1
247:                         # see if you can find it in the path
248:                         unless @@caseless_driver_name_map
249:                             @@caseless_driver_name_map = { } 
250:                             collect_drivers.each do |key, value|
251:                                 @@caseless_driver_name_map[key.downcase] = value
252:                             end
253:                         end
254: 
255:                         begin
256:                             require @@caseless_driver_name_map[dc] if @@caseless_driver_name_map[dc]
257:                         rescue LoadError => e2
258:                             raise e.class, "Could not find driver #{driver_name} or #{driver_name.downcase} (error: #{e1.message})"
259:                         end
260:                     end
261: 
262:                     # On a filesystem that is not case-sensitive (e.g., HFS+ on Mac OS X),
263:                     # the initial require attempt that loads the driver may succeed even
264:                     # though the lettercase of driver_name doesn't match the actual
265:                     # filename. If that happens, const_get will fail and it become
266:                     # necessary to look though the list of constants and look for a
267:                     # caseless match.  The result of this match provides the constant
268:                     # with the proper lettercase -- which can be used to generate the
269:                     # driver handle.
270: 
271:                     dr = nil
272:                     begin
273:                         dr = DBI::DBD.const_get(driver_name.intern)
274:                     rescue NameError
275:                         # caseless look for constants to find actual constant
276:                         dc = driver_name.downcase
277:                         found = DBI::DBD.constants.find { |e| e.downcase == dc }
278:                         dr = DBI::DBD.const_get(found.intern) unless found.nil?
279:                     end
280: 
281:                     # If dr is nil at this point, it means the underlying driver
282:                     # failed to load.  This usually means it's not installed, but
283:                     # can fail for other reasons.
284:                     if dr.nil?
285:                         err = "Unable to load driver '#{driver_name}'"
286:                         raise DBI::InterfaceError, err
287:                     end
288: 
289:                     dbd_dr = dr::Driver.new
290:                     drh = DBI::DriverHandle.new(dbd_dr, @@convert_types)
291:                     drh.driver_name = dr.driver_name
292:                     # FIXME trace
293:                     # drh.trace(@@trace_mode, @@trace_output)
294:                     @@driver_map[driver_name] = [drh, dbd_dr]
295:                     return driver_name 
296:                 else
297:                     return driver_name
298:                 end
299:             end
300:         rescue LoadError, NameError
301:             if $SAFE >= 1
302:                 raise InterfaceError, "Could not load driver (#{$!.message}). Note that in SAFE mode >= 1, driver URLs have to be case sensitive!"
303:             else
304:                 raise InterfaceError, "Could not load driver (#{$!.message})"
305:             end
306:         end