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