LCOV - code coverage report
Current view: top level - sql/server - rel_trans.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 44 50 88.0 %
Date: 2024-04-26 00:35:57 Functions: 2 2 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             : #include "monetdb_config.h"
      14             : #include "rel_trans.h"
      15             : #include "rel_select.h"
      16             : #include "rel_rel.h"
      17             : #include "rel_exp.h"
      18             : #include "sql_parser.h"
      19             : 
      20             : static sql_rel *
      21        3040 : rel_trans(mvc *sql, int trans_type, int nr, char *name)
      22             : {
      23        3040 :         sql_rel *rel = rel_create(sql->sa);
      24        3040 :         list *exps = new_exp_list(sql->sa);
      25        3040 :         if(!rel || !exps)
      26             :                 return NULL;
      27             : 
      28        3040 :         append(exps, exp_atom_int(sql->sa, nr));
      29        3040 :         if (name)
      30          77 :                 append(exps, exp_atom_clob(sql->sa, name));
      31        3040 :         rel->l = NULL;
      32        3040 :         rel->r = NULL;
      33        3040 :         rel->op = op_ddl;
      34        3040 :         rel->flag = trans_type;
      35        3040 :         rel->exps = exps;
      36        3040 :         rel->card = 0;
      37        3040 :         rel->nrcols = 0;
      38        3040 :         return rel;
      39             : }
      40             : 
      41             : sql_rel *
      42        3040 : rel_transactions(sql_query *query, symbol *s)
      43             : {
      44        3040 :         mvc *sql = query->sql;
      45        3040 :         sql_rel *ret = NULL;
      46             : 
      47        3040 :         switch (s->token) {
      48          12 :         case TR_RELEASE:
      49          12 :                 ret = rel_trans(sql, ddl_release, 0, s->data.sval);
      50          12 :                 break;
      51         511 :         case TR_COMMIT:
      52         511 :                 assert(s->type == type_int);
      53         511 :                 ret = rel_trans(sql, ddl_commit, s->data.i_val, NULL);
      54         511 :                 break;
      55          47 :         case TR_SAVEPOINT:
      56          47 :                 ret = rel_trans(sql, ddl_commit, 0, s->data.sval);
      57          47 :                 break;
      58        1026 :         case TR_ROLLBACK: {
      59        1026 :                 dnode *n = s->data.lval->h;
      60        1026 :                 assert(n->type == type_int);
      61        1026 :                 ret= rel_trans(sql, ddl_rollback, n->data.i_val, n->next->data.sval);
      62        1026 :         }       break;
      63        1444 :         case TR_START:
      64             :         case TR_MODE: {
      65        1444 :                 int tr_mode = s->data.i_val;
      66             : 
      67        1444 :                 assert(s->type == type_int && (tr_mode & tr_append) == 0);
      68        1444 :                 if ((tr_mode & tr_none) == tr_none)
      69           0 :                         return sql_error(sql, 01, SQLSTATE(42000) "Transaction diagnostic not supported");
      70        1444 :                 if ((tr_mode & tr_readonly) == tr_readonly)
      71           0 :                         return sql_error(sql, 01, SQLSTATE(42000) "Readonly transactions not supported");
      72        1444 :                 if ((tr_mode & tr_snapshot) == tr_snapshot && (tr_mode & tr_serializable) == tr_serializable)
      73           0 :                         return sql_error(sql, 01, SQLSTATE(42000) "Cannot set multiple ISO levels on the same transaction");
      74        1444 :                 if ((tr_mode & tr_snapshot) == 0 && (tr_mode & tr_serializable) == 0)
      75           0 :                         tr_mode |= tr_serializable; /* set serializable level by default */
      76        1444 :                 tr_mode &= ~tr_writable; /* all transactions are writable by default */
      77        1444 :                 ret = rel_trans(sql, ddl_trans, tr_mode, NULL);
      78        1444 :         }       break;
      79           0 :         default:
      80           0 :                 return sql_error(sql, 01, SQLSTATE(42000) "Transaction unknown Symbol(%p)->token = %s", s, token2string(s->token));
      81             :         }
      82             :         return ret;
      83             : }

Generated by: LCOV version 1.14