Forum OpenACS Q&A: Re: querying multiple datababe server..

Collapse
Posted by Jonathan Ellis on
here is a proc that will let you use the 4.x DB api with a non-default pool. it only lets you use the one pool, not a set of pools like you normally get, and you can't nest db_force_pool calls. (but you could with just a little more work on how it renames the old db_nth_pool_name.)

you could obviously integrate this with the db_ api in a less hackish manner, but this works as proof of concept. :)

proc db_force_pool {poolname code_block} {
    global db_state
    array set db_state_old [array get db_state]
    set db_state(handles) [list]
    set db_state(n_handles_used) 0

    rename db_nth_pool_name db_nth_pool_name_before_dbfp
    proc db_nth_pool_name {n} "
        return $poolname
    "

    if [catch {
        uplevel $code_block
    } err] {
        ns_log error "$err while executing $code_block in db_force_pool"
    }

    db_release_unused_handles
    rename db_nth_pool_name ""
    rename db_nth_pool_name_before_dbfp db_nth_pool_name
    array set db_state [array get db_state_old]
}
(remember that to keep ACS from grabbing all your pools, you have to put the subset you want it to use in ns/server/$server_name/acs/database.)