سؤال

I am currently using Javascript to connect to my database (I know it's not the best way but this is the way it was done and it is out of my hands to change it)

This is what I'm doing:

function changeCode(textfield1, textfield2, textfield3){

if(emptyFields(textfield1, textfield1, textfield1) == false){
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring = "DSN=dsn_prod;UID=usuid;PWD=usuid";

connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

var code= new String();
var client= new String();
var post= new String();
code= document.getElementById(textfield1).value;
client = document.getElementById(textfield2).value;
post= document.getElementById(textfield3).value;    

var r=confirm("Are you sure you wish to change code?");
if(r==true){
    rs.Open("update agen set c_it ="+code+" where n_client = "+client+" and c_post_client='"+post+"'",connection);
    rs.close;
    rs.Open("update clie set c_it="+code+" where n_client = "+client+" and c_post_client='"+post+"'",connection);
    rs.close;
    rs.Open("update ncli set c_it="+code+" where n_client= "+client+" and c_post_client='"+post+"'",connection);
    rs.close;
    rs.Open("update foli set c_it="+code+" where c_it <> "+code+" and n_client = "+client+" and c_post_client='"+post+"'",connection);
    rs.close;
    connection.close;
    }


}

}

Is there a way to make all this into one big query instead of opening and closing the recordset multiple times?

Thanks!

هل كانت مفيدة؟

المحلول

After giving it some thought I realized that it was really simple. The best way to do this is using a BEGIN and END statements to run a bunch of queries together:

rs.Open("BEGIN update agen set c_it ="+code+" where n_client = "+client+" and c_post_client='"+post+"'; update clie set c_it="+code+" where n_client = "+client+" and c_post_client='"+post+"'; update ncli set c_it="+code+" where n_client= "+client+" and c_post_client='"+post+"'; update foli set c_it="+code+" where c_it <> "+code+" and n_client = "+client+" and c_post_client='"+post+"';END;",connection);

Hope this helps anyone

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top