В настоящее время я использую Javascript для подключения к моей базе данных (я знаю, что это не лучший способ, но это так, как это было сделано, и это не в моих силах изменить его)
Это то, что я делаю:
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;
}
}
}
Есть ли способ сделать все это одним крупным запросом вместо того, чтобы открывать и закрывать набор записей несколько раз?
Благодарю!
Подумав, я понял, что это действительно просто. Лучший способ сделать это - использовать инструкции BEGIN
и END
для одновременного запуска кучи запросов:
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);
Надеюсь, это поможет кому угодно