Forum OpenACS Q&A: Problem with TCL

Collapse
Posted by Kabowei Oki on
Hi All,

I'm a newbie to TCL and aol server. I'm faced with this problem where contents are displayed to the wrong user.

The contents read from the database are binded onto http using

ns_adp_puts "var myVar = \"$someVar;\""

This page gets submitted and the resulting output is for a previous submission for a different user.

Can some one please come to my rescue. Thank in advance.

Kab

Collapse
2: Re: Problem with TCL (response to 1)
Posted by Jim Lynch on
Right now I can only say there's not enough information... can you post the actual code (the .tcl and the .adp at least) for the page you're viewing?
Collapse
3: Re: Problem with TCL (response to 1)
Posted by Kabowei Oki on
if {"$type" == "xxx"} {
set temp "select * from TABLE A"

if [catch {set selection [ns_db select $db $t_select] } errMsg ] {
ns_log Notice "Error Occured reading Table A $errMsg"
ns_db flush $db
ns_db releasehandle $db
ns_returnredirect "$redirectPage"
set t_abort "1"
ns_adp_abort
}
while { [ns_db getrow $db $selection ] } {
set someVariable [ns_set get $selection "date"]
set anotherVariable [ns_set get $selection "someValue"]
set t_var [concat $someVariable*$anotherVariable]
lappend record $t_var
}
}

if {"$type" == "yyy"} {
set temp "select * from TABLE B"


if [catch {set selection [ns_db select $db $t_select] } errMsg ] {
ns_log Notice "Error with select Table B $errMsg"
ns_db flush $db
ns_db releasehandle $db
ns_returnredirect "$redirectPage"
set t_abort "1"
ns_adp_abort
}
while { [ns_db getrow $db $selection ] } {
set someVariable [ns_set get $selection "date"]
set anotherVariable [ns_set get $selection "some_id"
set t_var [concat $someVariable*$anotherVariable]
lappend record $t_var

}
}

set result [join $record ","]

ns_db releasehandle $db

ns_puts "var output = \"$result;\""

Collapse
4: Re: Problem with TCL (response to 1)
Posted by Kabowei Oki on
function onLoad() {

if (some_expression){
    var out= '';
    var output = '';
    if (cookieType == 'xxx') {
      getA();
    }
    if (cookieType == 'yyy'){
      getB();
}

    data = new Array();
    var rows = output.split(',');
    if (rows.length == 1){
        data[0]= rows;
    }
    else {
        data = rows;
    }

}


function getA(){
    test_output += '<table cellspacing="0" cellpadding="1" border="1" align="center">'

    for (c=0; c<data.length; c++){
        outputRow(data[c], 7);
    }
    test_output += ('</table>');
}

function getB(){
    test_output += '<table cellspacing="0" cellpadding="1" border="1" align="center">'
    for (c=0; c<data.length; c++){
        outputRow(data[c], 3);
    }
    test_output  += ('</table>');
}