LCOV - code coverage report
Current view: top level - sql/backends/monet5 - sql_transaction.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 40 61 65.6 %
Date: 2021-10-13 02:24:04 Functions: 4 5 80.0 %

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

Generated by: LCOV version 1.14