|
|
What this is
This file is included in the DevDaily.com
"Ruby Source Code
Warehouse" project. The intent of this project is to help you "Learn
Ruby by Example" TM.
Other links
The source code
# Apache::DBI
# Copyright (C) 2004 MoonWolf
# All rights reserved.
require 'dbi'
module DBI
@@connection = {}
class << self
alias _connect connect
def connect(driver_url, user=nil, auth=nil, params=nil, &p)
key = [driver_url, user, auth, params]
unless connection=@@connection[key]
connection = DBI::_connect(driver_url, user, auth, params)
@@connection[key] = connection
end
if block_given?
yield connection
else
connection
end
end
end
class DatabaseHandle
@@prepared = {}
alias _prepare prepare
def prepare(stmt)
key = [self, stmt]
unless sth=@@prepared[key]
sth = self._prepare(stmt)
@@prepared[key] = sth
end
if block_given?
yield sth
else
sth
end
end
alias _disconnect disconnect
def disconnect
nil
end
end # DatabaseHandle
end # DBI
|