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