Home > Back-end >  Delphil used to use transactions
Delphil used to use transactions

Time:09-24

Qry:=TAdoQuery. Create (nil);
Qry. Connection:=conn.
qry. Connection. BeginTrans;
For I:=0 to TFilePathList. Do the count - 1
The begin
STRM. LoadFromFile (TFilePathList [I]);
Qry. SQL. The add (' insert into test (PIC) values (: PIC) ');
Qry. The Parameters. ParseSQL (qry. SQL. Text, true);
Qry. The Parameters. ParamByName (' PIC). LoadFromStream (STRM, ftBlob);
end;
Qry. ExecSQL;
qry.Connection.Com mitTrans;
Why always last one data store?
If the above storage using transaction (below is the reference is essentially transactions), red font is I use transactions, or no, you did a great god ideas?

For I:=1 to 10000 do
The begin
Name:=QuotedStr (' easyboot + InttoStr (I));
SqlStr=SqlStr + Format (' insert into MyTest (Name) values (% s) ', [Name]);
end;
ADOConnection1. Open;
ADOConnection1. BeginTrans;
ADOCommand1.Com mandText:=SqlStr;
ADOCommand1. The Execute ();
ADOConnection1.Com mitTrans;

CodePudding user response:

Qry. ExecSQL;
Put a loop inside! You put out is always the last one, of course!

CodePudding user response:

Qry. ExecSQL;
Put a loop inside!
The qry. SQL. add (' insert into test (PIC) values (: PIC) '); Don't have to ADD,
Qry. SQL. Text:="insert into test (PIC) values (: PIC) '; As if there is no efficiency increases,

CodePudding user response:

refer to the second floor caitom7 response:
qry. ExecSQL;
Put a loop inside!
The qry. SQL. add (' insert into test (PIC) values (: PIC) '); Don't have to ADD,
Qry. SQL. Text:="insert into test (PIC) values (: PIC) '; As if there is no efficiency increases,


If you don't put it there is wrong, rather than the efficiency problem, as for you is to use the ADD or Text that is another problem! The individual feels small data quantity both makes no difference,

CodePudding user response:

So try to modify the original code can only perform (last) time,

 qry. Connection. BeginTrans; 
For I:=0 to TFilePathList. Do the count - 1
The begin
STRM. LoadFromFile (TFilePathList [I]);
Qry. SQL. The add (' insert into test (PIC) values (: PIC) ');
Qry. The Parameters. ParseSQL (qry. SQL. Text, true);
Qry. The Parameters. ParamByName (' PIC). LoadFromStream (STRM, ftBlob);
Qry. ExecSQL;
end;
Qry.Connection.Com mitTrans;



Good transaction, the code is as follows:
 
Try
ADOCon. BeginTrans;//transaction
For I:=0 to n do
The begin
SQL:='InSetrt... ';//generates SQL statement
ADOCon. Execute (SQL);//in the execution queue
end;
ADOCon.Com mitTrans;//to commit the transaction
Result:=True;
Except,
On E: the Exception do
The begin
ADOCon. RollbackTrans;//transaction rollback
Err:=E.M essage.
end;
end;

CodePudding user response:

Remind: transaction processing of SQL batch do not too much, influence the speed and efficiency, because the transaction mechanism, error is returned,

CodePudding user response:

Qry:=TAdoQuery. Create (nil);
Qry. Connection:=conn.

For I:=0 to TFilePathList. Do the count - 1
The begin
STRM. LoadFromFile (TFilePathList [I]);
Qry. SQL. The add (' insert into test (PIC) values (: PIC) ');
Qry. The Parameters. ParseSQL (qry. SQL. Text, true);
Qry. The Parameters. ParamByName (' PIC). LoadFromStream (STRM, ftBlob);
end;
//actually, transaction here more meaningful!
//let the server to respond to your affairs, allocation of resources, a transaction volume is not too big
//will think this efficiency higher point
Qry. Connection. BeginTrans;
Qry. ExecSQL;
Qry.Connection.Com mitTrans;

CodePudding user response:

For I:=0 to TFilePathList. Do the count - 1
The begin
STRM. LoadFromFile (TFilePathList [I]);
Qry. SQL. The add (' insert into test (PIC) values (: PIC) ');
Qry. The Parameters. ParseSQL (qry. SQL. Text, true);
Qry. The Parameters. ParamByName (' PIC). LoadFromStream (STRM, ftBlob);
//write wrong, change the
//actually, transaction here more meaningful!
//let the server to respond to your affairs, allocation of resources, a transaction volume is not too big
//will think this efficiency higher point
Qry. Connection. BeginTrans;
Qry. ExecSQL;
Qry.Connection.Com mitTrans;
end;

CodePudding user response:

Execsql, outside the loop on the inside
  • Related