Forum OpenACS Development: Response to Is this a bug with the QD?

Collapse
Posted by Dan Wickstrom on
This is not a bug. It's just a side-effect of executing a query in the context of an uplevel. The proc "ec_create_new_session_if_necessary" does an uplevel before doing the query, so the QD is fooled into thinking that the query is executing from within index.tcl. You could fix this by putting the correct query in the index-postgresql.xql file in the www directory, but that might be kind of confusing. A better way to fix this would be to use db_map to fetch the query outside the scope of the uplevel, and then later pass it into the db_dml statement inside the uplevel. Since the proc in question has a long uplevel section, it might be easier to pass the sql to the db_dml statement via an upvar. Something like the following:

ad_proc -private ec_create_new_session_if_necessary {
    {more_url_vars_exported ""}
    {cookie_requirement "cookies_are_required"}
} { Create a new session if needed } {
    uplevel "set _ec_more_url_vars_exported "$more_url_vars_exported""
    uplevel "set _ec_cookie_requirement     "$cookie_requirement""
    upvar __sql sql
    set sql [db_map insert_user_session_sql]
    uplevel {

        if { $user_session_id == 0 } {
            if {![info exists usca_p]} {

                # first time we've seen this visitor
                # no previous attempt made
                
                set user_session_id [db_nextval "ec_user_session_sequence"]
                ## use ACS 4 faster sessions
                ## set user_session_id [ad_conn session_id]
                
                set ip_address      [ns_conn peeraddr]
                set http_user_agent [ecGetUserAgentHeader]
                
                # we should be able to get rid of this in ACS 4, but
                # we need to examine longevity of ad_sessions

                db_dml insert_user_session $__sql

Now change the name of your query within the .xql file to "insert_user_session_sql", and everything should work okay.