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 : /*
14 : * @f sql_scenario
15 : * @t SQL catwalk management
16 : * @a N. Nes, M.L. Kersten
17 : * @+ SQL scenario
18 : * The SQL scenario implementation is a derivative of the MAL session scenario.
19 : *
20 : * It is also the first version that uses state records attached to
21 : * the client record. They are initialized as part of the initialization
22 : * phase of the scenario.
23 : *
24 : */
25 : /*
26 : * @+ Scenario routines
27 : * Before we are can process SQL statements the global catalog
28 : * should be initialized. Thereafter, each time a client enters
29 : * we update its context descriptor to denote an SQL scenario.
30 : */
31 : #include "monetdb_config.h"
32 : #include "mal_backend.h"
33 : #include "sql_assert.h"
34 : #include "sql_scenario.h"
35 : /*
36 : * Assertion errors detected during the execution of a code block
37 : * raise an exception. A debugger dump is generated upon request
38 : * to ease debugging.
39 : */
40 : static inline str
41 38311 : do_assert(bool flg, const char *msg)
42 : {
43 38311 : if (flg) {
44 263 : if (strlen(msg) > 6 &&
45 263 : msg[5] == '!' &&
46 224 : (isdigit((unsigned char) msg[0]) ||
47 224 : isupper((unsigned char) msg[0])) &&
48 224 : (isdigit((unsigned char) msg[1]) ||
49 224 : isupper((unsigned char) msg[1])) &&
50 224 : (isdigit((unsigned char) msg[2]) ||
51 224 : isupper((unsigned char) msg[2])) &&
52 224 : (isdigit((unsigned char) msg[3]) ||
53 224 : isupper((unsigned char) msg[3])) &&
54 224 : (isdigit((unsigned char) msg[4]) ||
55 : isupper((unsigned char) msg[4])))
56 224 : throw(SQL, "assert", "%s", msg); /* includes state */
57 39 : throw(SQL, "assert", SQLSTATE(M0M29) "%s", msg);
58 : }
59 : return MAL_SUCCEED;
60 : }
61 : str
62 26359 : SQLassert(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
63 : {
64 26359 : (void) cntxt;
65 26359 : (void) mb;
66 26359 : return do_assert((bool) *getArgReference_bit(stk, pci, 1),
67 26359 : *getArgReference_str(stk, pci, 2));
68 : }
69 :
70 : str
71 0 : SQLassertInt(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
72 : {
73 0 : (void) cntxt;
74 0 : (void) mb;
75 0 : return do_assert((bool) *getArgReference_int(stk, pci, 1),
76 0 : *getArgReference_str(stk, pci, 2));
77 : }
78 :
79 : str
80 11994 : SQLassertLng(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
81 : {
82 11994 : (void) cntxt;
83 11994 : (void) mb;
84 11994 : return do_assert((bool) *getArgReference_lng(stk, pci, 1),
85 11994 : *getArgReference_str(stk, pci, 2));
86 : }
87 :
88 : #ifdef HAVE_HGE
89 : str
90 0 : SQLassertHge(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
91 : {
92 0 : (void) cntxt;
93 0 : (void) mb;
94 0 : return do_assert((bool) *getArgReference_hge(stk, pci, 1),
95 0 : *getArgReference_str(stk, pci, 2));
96 : }
97 : #endif
|