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