31
31
#include "php_pdo_firebird.h"
32
32
#include "php_pdo_firebird_int.h"
33
33
34
- static int firebird_alloc_prepare_stmt (pdo_dbh_t * , const zend_string * , XSQLDA * , isc_stmt_handle * ,
35
- HashTable * );
34
+ static int firebird_alloc_prepare_stmt (pdo_dbh_t * , const zend_string * , XSQLDA * , isc_stmt_handle * , HashTable * );
35
+ static bool _firebird_commit_transaction (pdo_dbh_t * dbh , bool retain );
36
+ static bool _firebird_rollback_transaction (pdo_dbh_t * dbh , bool retain );
36
37
37
38
const char CHR_LETTER = 1 ;
38
39
const char CHR_DIGIT = 2 ;
@@ -477,13 +478,9 @@ static void firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
477
478
478
479
if (H -> tr ) {
479
480
if (dbh -> auto_commit ) {
480
- if (isc_commit_transaction (H -> isc_status , & H -> tr )) {
481
- RECORD_ERROR (dbh );
482
- }
481
+ _firebird_commit_transaction (dbh , false);
483
482
} else {
484
- if (isc_rollback_transaction (H -> isc_status , & H -> tr )) {
485
- RECORD_ERROR (dbh );
486
- }
483
+ _firebird_rollback_transaction (dbh , false);
487
484
}
488
485
}
489
486
H -> in_manually_txn = 0 ;
@@ -649,9 +646,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) /*
649
646
650
647
/* commit if we're in auto_commit mode */
651
648
if (dbh -> auto_commit && !H -> in_manually_txn ) {
652
- if (isc_commit_retaining (H -> isc_status , & H -> tr )) {
653
- RECORD_ERROR (dbh );
654
- }
649
+ _firebird_commit_transaction (dbh , true);
655
650
}
656
651
657
652
free_statement :
@@ -703,8 +698,8 @@ static zend_string* firebird_handle_quoter(pdo_dbh_t *dbh, const zend_string *un
703
698
}
704
699
/* }}} */
705
700
706
- /* firebird_begin_transaction */
707
- static bool firebird_begin_transaction (pdo_dbh_t * dbh ) /* {{{ */
701
+ /* _firebird_begin_transaction */
702
+ static bool _firebird_begin_transaction (pdo_dbh_t * dbh ) /* {{{ */
708
703
{
709
704
pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
710
705
char tpb [8 ] = { isc_tpb_version3 }, * ptpb = tpb + 1 ;
@@ -757,16 +752,15 @@ static bool firebird_begin_transaction(pdo_dbh_t *dbh) /* {{{ */
757
752
/* }}} */
758
753
759
754
/* called by PDO to start a transaction */
760
- static bool firebird_handle_begin (pdo_dbh_t * dbh ) /* {{{ */
755
+ static bool firebird_handle_manually_begin (pdo_dbh_t * dbh ) /* {{{ */
761
756
{
762
757
pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
763
758
764
- if (dbh -> auto_commit && H -> tr && isc_commit_transaction (H -> isc_status , & H -> tr )) {
765
- RECORD_ERROR (dbh );
759
+ if (dbh -> auto_commit && H -> tr && !_firebird_commit_transaction (dbh , false)) {
766
760
return false;
767
761
}
768
762
769
- if (!firebird_begin_transaction (dbh )) {
763
+ if (!_firebird_begin_transaction (dbh )) {
770
764
return false;
771
765
}
772
766
@@ -775,12 +769,12 @@ static bool firebird_handle_begin(pdo_dbh_t *dbh) /* {{{ */
775
769
}
776
770
/* }}} */
777
771
778
- /* called by PDO to commit a transaction */
779
- static bool firebird_handle_commit (pdo_dbh_t * dbh ) /* {{{ */
772
+ /* _firebird_commit_transaction */
773
+ static bool _firebird_commit_transaction (pdo_dbh_t * dbh , bool retain ) /* {{{ */
780
774
{
781
775
pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
782
776
783
- if (dbh -> auto_commit ) {
777
+ if (retain ) {
784
778
if (isc_commit_retaining (H -> isc_status , & H -> tr )) {
785
779
RECORD_ERROR (dbh );
786
780
return false;
@@ -791,17 +785,31 @@ static bool firebird_handle_commit(pdo_dbh_t *dbh) /* {{{ */
791
785
return false;
792
786
}
793
787
}
788
+
789
+ return true;
790
+ }
791
+ /* }}} */
792
+
793
+ /* called by PDO to commit a transaction */
794
+ static bool firebird_handle_manually_commit (pdo_dbh_t * dbh ) /* {{{ */
795
+ {
796
+ pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
797
+
798
+ if (!_firebird_commit_transaction (dbh , dbh -> auto_commit )) {
799
+ return false;
800
+ }
801
+
794
802
H -> in_manually_txn = 0 ;
795
803
return true;
796
804
}
797
805
/* }}} */
798
806
799
- /* called by PDO to rollback a transaction */
800
- static bool firebird_handle_rollback (pdo_dbh_t * dbh ) /* {{{ */
807
+ /* _firebird_rollback_transaction */
808
+ static bool _firebird_rollback_transaction (pdo_dbh_t * dbh , bool retain ) /* {{{ */
801
809
{
802
810
pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
803
811
804
- if (dbh -> auto_commit ) {
812
+ if (retain ) {
805
813
if (isc_rollback_retaining (H -> isc_status , & H -> tr )) {
806
814
RECORD_ERROR (dbh );
807
815
return false;
@@ -812,6 +820,20 @@ static bool firebird_handle_rollback(pdo_dbh_t *dbh) /* {{{ */
812
820
return false;
813
821
}
814
822
}
823
+
824
+ return true;
825
+ }
826
+ /* }}} */
827
+
828
+ /* called by PDO to rollback a transaction */
829
+ static bool firebird_handle_manually_rollback (pdo_dbh_t * dbh ) /* {{{ */
830
+ {
831
+ pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
832
+
833
+ if (!_firebird_rollback_transaction (dbh , dbh -> auto_commit )) {
834
+ return false;
835
+ }
836
+
815
837
H -> in_manually_txn = 0 ;
816
838
return true;
817
839
}
@@ -879,12 +901,12 @@ static bool firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *
879
901
H -> last_app_error = "Cannot enable auto-commit while a transaction is already open" ;
880
902
return false;
881
903
}
882
- if (!H -> tr && !firebird_begin_transaction (dbh )) {
904
+ if (!H -> tr && !_firebird_begin_transaction (dbh )) {
883
905
return false;
884
906
}
885
907
} else {
886
908
/* close the transaction */
887
- if (H -> tr && isc_commit_transaction ( H -> isc_status , & H -> tr )) {
909
+ if (H -> tr && ! _firebird_commit_transaction ( dbh , false )) {
888
910
return false;
889
911
}
890
912
H -> in_manually_txn = 0 ;
@@ -1042,8 +1064,8 @@ static void pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval
1042
1064
}
1043
1065
/* }}} */
1044
1066
1045
- /* {{{ firebird_in_transaction */
1046
- static bool firebird_in_transaction (pdo_dbh_t * dbh )
1067
+ /* {{{ firebird_in_manually_transaction */
1068
+ static bool firebird_in_manually_transaction (pdo_dbh_t * dbh )
1047
1069
{
1048
1070
pdo_firebird_db_handle * H = (pdo_firebird_db_handle * )dbh -> driver_data ;
1049
1071
return H -> tr && H -> in_manually_txn ;
@@ -1055,17 +1077,17 @@ static const struct pdo_dbh_methods firebird_methods = { /* {{{ */
1055
1077
firebird_handle_preparer ,
1056
1078
firebird_handle_doer ,
1057
1079
firebird_handle_quoter ,
1058
- firebird_handle_begin ,
1059
- firebird_handle_commit ,
1060
- firebird_handle_rollback ,
1080
+ firebird_handle_manually_begin ,
1081
+ firebird_handle_manually_commit ,
1082
+ firebird_handle_manually_rollback ,
1061
1083
firebird_handle_set_attribute ,
1062
1084
NULL , /* last_id not supported */
1063
1085
pdo_firebird_fetch_error_func ,
1064
1086
firebird_handle_get_attribute ,
1065
1087
NULL , /* check_liveness */
1066
1088
NULL , /* get driver methods */
1067
1089
NULL , /* request shutdown */
1068
- firebird_in_transaction ,
1090
+ firebird_in_manually_transaction ,
1069
1091
NULL /* get gc */
1070
1092
};
1071
1093
/* }}} */
@@ -1148,7 +1170,7 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /*
1148
1170
1149
1171
H -> in_manually_txn = 0 ;
1150
1172
if (dbh -> auto_commit && !H -> tr ) {
1151
- ret = firebird_begin_transaction (dbh );
1173
+ ret = _firebird_begin_transaction (dbh );
1152
1174
}
1153
1175
1154
1176
if (!ret ) {
0 commit comments