Skip to content

Commit a70544b

Browse files
committed
Made transaction isolation level settings easier to understand
1 parent 4967d08 commit a70544b

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

ext/pdo_firebird/firebird_driver.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -761,51 +761,49 @@ static bool php_firebird_begin_transaction(pdo_dbh_t *dbh, bool is_auto_commit_t
761761
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
762762

763763
/* isc_xxx are all 1 byte. */
764-
char tpb[5] = { isc_tpb_version3 }, *ptpb = tpb + 1;
764+
char tpb[4] = { isc_tpb_version3 };
765+
size_t tpb_size;
766+
767+
/* access mode. writable or readonly */
768+
tpb[1] = H->is_writable_txn ? isc_tpb_write : isc_tpb_read;
765769

766770
if (is_auto_commit_txn) {
767771
/*
768-
* In autocommit mode, we need to always read the latest information, that is,
769-
* expect phantom reads, so we set read committed.
772+
* In autocommit mode, we need to always read the latest information, so we set `read committed`.
770773
*/
771-
*ptpb++ = isc_tpb_read_committed;
772-
*ptpb++ = isc_tpb_rec_version;
774+
tpb[2] = isc_tpb_read_committed;
775+
/* Not wait to commit indeterminate data. This option required only with `read committed`.*/
776+
tpb[3] = isc_tpb_rec_version;
777+
tpb_size = 4;
773778
} else {
774779
switch (H->txn_isolation_level) {
775780
/*
776-
* firebird's read committed has the option to wait until other transactions
781+
* firebird's `read committed` has the option to wait until other transactions
777782
* commit or rollback if there is indeterminate data.
778783
* Introducing too many configuration values ​​at once can cause confusion, so
779784
* we don't support in PDO that feature yet.
780-
*
781-
* Also, there is information that depending on the settings, it is possible to
782-
* reproduce behavior like read uncommited, but at least with the current firebird
783-
* API, this is not possible.
784785
*/
785786
case PDO_FB_READ_COMMITTED:
786-
*ptpb++ = isc_tpb_read_committed;
787-
*ptpb++ = isc_tpb_rec_version;
787+
tpb[2] = isc_tpb_read_committed;
788+
/* Not wait to commit indeterminate data. This option required only with `read committed`.*/
789+
tpb[3] = isc_tpb_rec_version;
790+
tpb_size = 4;
788791
break;
789792

790793
case PDO_FB_SERIALIZABLE:
791-
*ptpb++ = isc_tpb_consistency;
794+
tpb[2] = isc_tpb_consistency;
795+
tpb_size = 3;
792796
break;
793797

794798
case PDO_FB_REPEATABLE_READ:
795799
default:
796-
*ptpb++ = isc_tpb_concurrency;
800+
tpb[2] = isc_tpb_concurrency;
801+
tpb_size = 3;
797802
break;
798803
}
799804
}
800805

801-
802-
if (H->is_writable_txn) {
803-
*ptpb++ = isc_tpb_write;
804-
} else {
805-
*ptpb++ = isc_tpb_read;
806-
}
807-
808-
if (isc_start_transaction(H->isc_status, &H->tr, 1, &H->db, (unsigned short)(ptpb - tpb), tpb)) {
806+
if (isc_start_transaction(H->isc_status, &H->tr, 1, &H->db, tpb_size, tpb)) {
809807
php_firebird_error(dbh);
810808
return false;
811809
}

0 commit comments

Comments
 (0)