Re: mssql_query & ROLLBACK

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> You can't split a transaction between multiple calls to
> mssql_query. The memory used (in the server and client)
> are cleared between each call.

Are you sure?
Because this denies that:

mssql_query("SELECT @@TRANCOUNT"); // returns 0
mssql_query("BEGIN TRANSACTION");
mssql_query("SELECT @@TRANCOUNT"); // returns 1
mssql_query("INSERT INTO TABLE (DATE) VALUES ('$date')");
mssql_query("SELECT @@TRANCOUNT"); // returns 1 if previous INSERT 
INTO was completed successfully, 0 if not. It looks like an error 
will cause auto ROLLBACK TRANSACTION!

If INSERT INTO is completed successfully, I can call mssql_query
with ROLLBACK/COMMIT TRANSACTION and they work fine.
They don't work only if there was an error during INSERT INTO.

>> I have an opened connection to MS SQL Server 7
>> and I try to do this:
>> 
>> $commit = FALSE;
>> 
>> // SELECT @@TRANCOUNT returns 0 here = OK
>> 
>> if(mssql_query("BEGIN TRANSACTION")) {
>>   
>>   // SELECT @@TRANCOUNT returns 1 here = OK
>> 
>>   if(mssql_query("INSERT INTO TABLE (DATE) VALUES ('$date')")) {
>> 
>>     // ...
>> 
>>     $commit = TRUE;
>>     }
>>   
>>   if($commit) {
>>     mssql_query("COMMIT TRANSACTION");
>>     return TRUE;
>>     }
>>   else {
>>     mssql_query("ROLLBACK TRANSACTION");
>>     return FALSE;
>>     }
>>   }
>> else
>>   return FALSE;
>> 
>> When INSERT is done without errors, everything is OK.
>> But when it is not possible to insert data into a table
>> for any reason, SQL server returns this error message:
>> 
>> The ROLLBACK TRANSACTION request has no corresponding BEGIN 
>> TRANSACTION. (severity 16) in ... .php
>> 
>> But using SELECT @@TRANCOUNT I can check that TRANSACTION
>> is started, I tried to name the transaction, it didn't help.
>> 
>> I thought it is because I can't COMMIT/ROLLBACK empty
>> transaction, but this works fine:
>> 
>> mssql_query("BEGIN TRANSACTION");
>> mssql_query("ROLLBACK TRANSACTION");
>> 
>> What's wrong?!?



--------------------
Chcete ADSL na mesic zdarma?  http://user.centrum.cz/redir.php?url=http://www.in192.cz




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux