LCOV - code coverage report
Current view: top level - sql/backends/monet5 - sql_transaction.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 47 51 92.2 %
Date: 2024-11-14 20:04:02 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : /*
      14             :  * authors M Kersten, N Nes
      15             :  * SQL catalog support implementation
      16             :  * This module contains the wrappers around the SQL catalog operations
      17             :  */
      18             : #include "monetdb_config.h"
      19             : #include "sql_transaction.h"
      20             : #include "sql_gencode.h"
      21             : #include "sql_optimizer.h"
      22             : #include "sql_scenario.h"
      23             : #include "sql_mvc.h"
      24             : #include "sql_qc.h"
      25             : #include "sql_optimizer.h"
      26             : #include "mal_namespace.h"
      27             : #include "opt_prelude.h"
      28             : #include "querylog.h"
      29             : #include "mal_builder.h"
      30             : 
      31             : #include "rel_select.h"
      32             : #include "rel_prop.h"
      33             : #include "rel_rel.h"
      34             : #include "rel_exp.h"
      35             : #include "rel_bin.h"
      36             : #include "rel_dump.h"
      37             : #include "orderidx.h"
      38             : 
      39             : #define initcontext() \
      40             :         if ((msg = getSQLContext(cntxt, mb, &sql, NULL)) != NULL)\
      41             :                 return msg;\
      42             :         if ((msg = checkSQLContext(cntxt)) != NULL)\
      43             :                 return msg; \
      44             :         if (strNil(name))\
      45             :                 name = NULL;
      46             : 
      47             : str
      48          13 : SQLtransaction_release(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      49             : {
      50          13 :         mvc *sql = NULL;
      51          13 :         str msg;
      52          13 :         int chain = *getArgReference_int(stk, pci, 1);
      53          13 :         str name = *getArgReference_str(stk, pci, 2);
      54             : 
      55          26 :         initcontext();
      56             : 
      57          13 :         (void) chain;
      58          13 :         if (sql->session->auto_commit)
      59           1 :                 throw(SQL, "sql.trans", SQLSTATE(3BM30) "RELEASE SAVEPOINT: not allowed in auto commit mode");
      60          12 :         return mvc_release(sql, name);
      61             : }
      62             : 
      63             : str
      64         558 : SQLtransaction_commit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      65             : {
      66         558 :         mvc *sql = NULL;
      67         558 :         str msg;
      68         558 :         int chain = *getArgReference_int(stk, pci, 1);
      69         558 :         str name = *getArgReference_str(stk, pci, 2);
      70             : 
      71         606 :         initcontext();
      72             : 
      73         558 :         if (sql->session->auto_commit) {
      74           9 :                 if (name)
      75           2 :                         throw(SQL, "sql.trans", SQLSTATE(3BM30) "SAVEPOINT: not allowed in auto commit mode");
      76           7 :                 throw(SQL, "sql.trans", SQLSTATE(2DM30) "COMMIT: not allowed in auto commit mode");
      77             :         }
      78         549 :         return mvc_commit(sql, chain, name, false);
      79             : }
      80             : 
      81             : str
      82        1084 : SQLtransaction_rollback(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      83             : {
      84        1084 :         mvc *sql = NULL;
      85        1084 :         str msg;
      86        1084 :         int chain = *getArgReference_int(stk, pci, 1);
      87        1084 :         str name = *getArgReference_str(stk, pci, 2);
      88             : 
      89        1102 :         initcontext();
      90             : 
      91        1084 :         if (sql->session->auto_commit)
      92           3 :                 throw(SQL, "sql.trans", SQLSTATE(2DM30) "ROLLBACK: not allowed in auto commit mode");
      93        1081 :         return mvc_rollback(sql, chain, name, false);
      94             : }
      95             : 
      96             : str
      97        1507 : SQLtransaction_begin(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      98             : {
      99        1507 :         mvc *sql = NULL;
     100        1507 :         str msg;
     101        1507 :         int chain = *getArgReference_int(stk, pci, 1);
     102        1507 :         str name = *getArgReference_str(stk, pci, 2);
     103             : 
     104        1507 :         initcontext();
     105             : 
     106        1507 :         (void) chain;
     107        1507 :         if (!sql->session->auto_commit)
     108           5 :                 throw(SQL, "sql.trans", SQLSTATE(25001) "START TRANSACTION: cannot start a transaction within a transaction");
     109        1502 :         if (sql->session->tr->active)
     110        1502 :                 msg = mvc_rollback(sql, 0, NULL, false);
     111        1502 :         if (msg)
     112             :                 return msg;
     113        1502 :         switch (mvc_trans(sql)) {
     114           0 :                 case -1:
     115           0 :                         throw(SQL, "sql.trans", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     116           0 :                 case -3:
     117           0 :                         throw(SQL, "sql.trans", SQLSTATE(42000) "The session's schema was not found, this transaction won't start");
     118             :                 default:
     119        1502 :                         break;
     120             :         }
     121             :         /* set transaction properties after successfully starting */
     122        1502 :         sql->session->auto_commit = 0;
     123        1502 :         sql->session->ac_on_commit = 1;
     124        1502 :         return MAL_SUCCEED;
     125             : }

Generated by: LCOV version 1.14