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-10-03 20:03:20 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        3157 : rel_trans(mvc *sql, int trans_type, int nr, char *name)
      22             : {
      23        3157 :         sql_rel *rel = rel_create(sql->sa);
      24        3157 :         list *exps = new_exp_list(sql->sa);
      25        3157 :         if(!rel || !exps)
      26             :                 return NULL;
      27             : 
      28        3157 :         append(exps, exp_atom_int(sql->sa, nr));
      29        3157 :         if (name)
      30          79 :                 append(exps, exp_atom_clob(sql->sa, name));
      31        3157 :         rel->l = NULL;
      32        3157 :         rel->r = NULL;
      33        3157 :         rel->op = op_ddl;
      34        3157 :         rel->flag = trans_type;
      35        3157 :         rel->exps = exps;
      36        3157 :         rel->card = 0;
      37        3157 :         rel->nrcols = 0;
      38        3157 :         return rel;
      39             : }
      40             : 
      41             : sql_rel *
      42        3157 : rel_transactions(sql_query *query, symbol *s)
      43             : {
      44        3157 :         mvc *sql = query->sql;
      45        3157 :         sql_rel *ret = NULL;
      46             : 
      47        3157 :         switch (s->token) {
      48          13 :         case TR_RELEASE:
      49          13 :                 ret = rel_trans(sql, ddl_release, 0, s->data.sval);
      50          13 :                 break;
      51         508 :         case TR_COMMIT:
      52         508 :                 assert(s->type == type_int);
      53         508 :                 ret = rel_trans(sql, ddl_commit, s->data.i_val, NULL);
      54         508 :                 break;
      55          48 :         case TR_SAVEPOINT:
      56          48 :                 ret = rel_trans(sql, ddl_commit, 0, s->data.sval);
      57          48 :                 break;
      58        1082 :         case TR_ROLLBACK: {
      59        1082 :                 dnode *n = s->data.lval->h;
      60        1082 :                 assert(n->type == type_int);
      61        1082 :                 ret= rel_trans(sql, ddl_rollback, n->data.i_val, n->next->data.sval);
      62        1082 :         }       break;
      63        1506 :         case TR_START:
      64             :         case TR_MODE: {
      65        1506 :                 int tr_mode = s->data.i_val;
      66             : 
      67        1506 :                 assert(s->type == type_int && (tr_mode & tr_append) == 0);
      68        1506 :                 if ((tr_mode & tr_none) == tr_none)
      69           0 :                         return sql_error(sql, 01, SQLSTATE(42000) "Transaction diagnostic not supported");
      70        1506 :                 if ((tr_mode & tr_readonly) == tr_readonly)
      71           0 :                         return sql_error(sql, 01, SQLSTATE(42000) "Readonly transactions not supported");
      72        1506 :                 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        1506 :                 if ((tr_mode & tr_snapshot) == 0 && (tr_mode & tr_serializable) == 0)
      75           0 :                         tr_mode |= tr_serializable; /* set serializable level by default */
      76        1506 :                 tr_mode &= ~tr_writable; /* all transactions are writable by default */
      77        1506 :                 ret = rel_trans(sql, ddl_trans, tr_mode, NULL);
      78        1506 :         }       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