Browse code

modules/db_mysql: use autocommit var to start and stop transactions

Juha Heinanen authored on 02/10/2013 17:39:22
Showing 1 changed files
... ...
@@ -509,7 +509,7 @@ int db_mysql_affected_rows(const db1_con_t* _h)
509 509
  */
510 510
 int db_mysql_start_transaction(db1_con_t* _h, db_locking_t _l)
511 511
 {
512
-	str begin_str = str_init("BEGIN");
512
+	str begin_str = str_init("SET autocommit=0");
513 513
 	str lock_start_str = str_init("LOCK TABLES ");
514 514
 	str lock_end_str  = str_init(" WRITE");
515 515
 	str lock_str = {0, 0};
... ...
@@ -611,7 +611,8 @@ int db_mysql_unlock_tables(db1_con_t* _h)
611 611
  */
612 612
 int db_mysql_end_transaction(db1_con_t* _h)
613 613
 {
614
-	str query_str = str_init("COMMIT");
614
+	str commit_query_str = str_init("COMMIT");
615
+	str set_query_str = str_init("SET autocommit=1");
615 616
 
616 617
 	if (!_h) {
617 618
 		LM_ERR("invalid parameter value\n");
... ...
@@ -623,7 +624,13 @@ int db_mysql_end_transaction(db1_con_t* _h)
623 624
 		return -1;
624 625
 	}
625 626
 
626
-	if (db_mysql_raw_query(_h, &query_str, NULL) < 0)
627
+	if (db_mysql_raw_query(_h, &commit_query_str, NULL) < 0)
628
+	{
629
+		LM_ERR("executing raw_query\n");
630
+		return -1;
631
+	}
632
+
633
+	if (db_mysql_raw_query(_h, &set_query_str, NULL) < 0)
627 634
 	{
628 635
 		LM_ERR("executing raw_query\n");
629 636
 		return -1;
... ...
@@ -647,7 +654,8 @@ int db_mysql_end_transaction(db1_con_t* _h)
647 654
  */
648 655
 int db_mysql_abort_transaction(db1_con_t* _h)
649 656
 {
650
-	str query_str = str_init("ROLLBACK");
657
+	str rollback_query_str = str_init("ROLLBACK");
658
+	str set_query_str = str_init("SET autocommit=1");
651 659
 	int ret;
652 660
 
653 661
 	if (!_h) {
... ...
@@ -665,7 +673,14 @@ int db_mysql_abort_transaction(db1_con_t* _h)
665 673
  	   transaction now or all future starts will fail */
666 674
 	CON_TRANSACTION(_h) = 0;
667 675
 
668
-	if (db_mysql_raw_query(_h, &query_str, NULL) < 0)
676
+	if (db_mysql_raw_query(_h, &rollback_query_str, NULL) < 0)
677
+	{
678
+		LM_ERR("executing raw_query\n");
679
+		ret = -1;
680
+		goto done;
681
+	}
682
+
683
+	if (db_mysql_raw_query(_h, &set_query_str, NULL) < 0)
669 684
 	{
670 685
 		LM_ERR("executing raw_query\n");
671 686
 		ret = -1;