1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V.
7 */
8
9/*
10 * @f sql_scenario
11 * @t SQL catwalk management
12 * @a N. Nes, M.L. Kersten
13 * @+ SQL scenario
14 * The SQL scenario implementation is a derivative of the MAL session scenario.
15 *
16 * It is also the first version that uses state records attached to
17 * the client record. They are initialized as part of the initialization
18 * phase of the scenario.
19 *
20 */
21/*
22 * @+ Scenario routines
23 * Before we are can process SQL statements the global catalog
24 * should be initialized. Thereafter, each time a client enters
25 * we update its context descriptor to denote an SQL scenario.
26 */
27#include "monetdb_config.h"
28#include "mal_backend.h"
29#include "sql_assert.h"
30#include "sql_scenario.h"
31/*
32 * Assertion errors detected during the execution of a code block
33 * raises an exception. An debugger dump is generated upon request
34 * to ease debugging.
35 */
36str
37SQLassert(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
38{
39 bit *flg = getArgReference_bit(stk, pci, 1);
40 str *msg = getArgReference_str(stk, pci, 2);
41 const char *sqlstate = SQLSTATE(M0M29) ;
42 (void) sqlstate;
43 (void) cntxt;
44 (void) mb;
45 if (*flg) {
46 if (strlen(*msg) > 6 &&
47 (*msg)[5] == '!' &&
48 (isdigit((unsigned char) (*msg)[0]) ||
49 ('A' <= (*msg)[0] && (*msg)[0] <= 'Z')) &&
50 (isdigit((unsigned char) (*msg)[1]) ||
51 ('A' <= (*msg)[1] && (*msg)[1] <= 'Z')) &&
52 (isdigit((unsigned char) (*msg)[2]) ||
53 ('A' <= (*msg)[2] && (*msg)[2] <= 'Z')) &&
54 (isdigit((unsigned char) (*msg)[3]) ||
55 ('A' <= (*msg)[3] && (*msg)[3] <= 'Z')) &&
56 (isdigit((unsigned char) (*msg)[4]) ||
57 ('A' <= (*msg)[4] && (*msg)[4] <= 'Z')))
58 sqlstate = "";
59 throw(SQL, "assert", SQLSTATE(M0M29) "%s", *msg);
60 }
61 return MAL_SUCCEED;
62}
63
64str
65SQLassertInt(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
66{
67 int *flg = getArgReference_int(stk, pci, 1);
68 str *msg = getArgReference_str(stk, pci, 2);
69 const char *sqlstate = SQLSTATE(M0M29) ;
70 (void) sqlstate;
71 (void) cntxt;
72 (void) mb;
73 if (*flg) {
74 if (strlen(*msg) > 6 &&
75 (*msg)[5] == '!' &&
76 (isdigit((unsigned char) (*msg)[0]) ||
77 ('A' <= (*msg)[0] && (*msg)[0] <= 'Z')) &&
78 (isdigit((unsigned char) (*msg)[1]) ||
79 ('A' <= (*msg)[1] && (*msg)[1] <= 'Z')) &&
80 (isdigit((unsigned char) (*msg)[2]) ||
81 ('A' <= (*msg)[2] && (*msg)[2] <= 'Z')) &&
82 (isdigit((unsigned char) (*msg)[3]) ||
83 ('A' <= (*msg)[3] && (*msg)[3] <= 'Z')) &&
84 (isdigit((unsigned char) (*msg)[4]) ||
85 ('A' <= (*msg)[4] && (*msg)[4] <= 'Z')))
86 sqlstate = "";
87 throw(SQL, "assert", SQLSTATE(M0M29) "%s", *msg);
88 }
89 return MAL_SUCCEED;
90}
91
92str
93SQLassertLng(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
94{
95 lng *flg = getArgReference_lng(stk, pci, 1);
96 str *msg = getArgReference_str(stk, pci, 2);
97 const char *sqlstate = SQLSTATE(M0M29) ;
98 (void) sqlstate;
99 (void) cntxt;
100 (void) mb;
101 if (*flg) {
102 if (strlen(*msg) > 6 &&
103 (*msg)[5] == '!' &&
104 (isdigit((unsigned char) (*msg)[0]) ||
105 ('A' <= (*msg)[0] && (*msg)[0] <= 'Z')) &&
106 (isdigit((unsigned char) (*msg)[1]) ||
107 ('A' <= (*msg)[1] && (*msg)[1] <= 'Z')) &&
108 (isdigit((unsigned char) (*msg)[2]) ||
109 ('A' <= (*msg)[2] && (*msg)[2] <= 'Z')) &&
110 (isdigit((unsigned char) (*msg)[3]) ||
111 ('A' <= (*msg)[3] && (*msg)[3] <= 'Z')) &&
112 (isdigit((unsigned char) (*msg)[4]) ||
113 ('A' <= (*msg)[4] && (*msg)[4] <= 'Z')))
114 sqlstate = "";
115 throw(SQL, "assert", SQLSTATE(M0M29) "%s", *msg);
116 }
117 return MAL_SUCCEED;
118}
119
120#ifdef HAVE_HGE
121str
122SQLassertHge(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){
123 hge *flg = getArgReference_hge(stk,pci, 1);
124 str *msg = getArgReference_str(stk,pci, 2);
125 (void) cntxt;
126 (void)mb;
127 if (*flg){
128 const char *sqlstate = SQLSTATE(M0M29) ;
129 (void) sqlstate;
130 if (strlen(*msg) > 6 && (*msg)[5] == '!' &&
131 (isdigit((unsigned char) (*msg)[0]) ||
132 ('A' <= (*msg)[0] && (*msg)[0] <= 'Z')) &&
133 (isdigit((unsigned char) (*msg)[1]) ||
134 ('A' <= (*msg)[1] && (*msg)[1] <= 'Z')) &&
135 (isdigit((unsigned char) (*msg)[2]) ||
136 ('A' <= (*msg)[2] && (*msg)[2] <= 'Z')) &&
137 (isdigit((unsigned char) (*msg)[3]) ||
138 ('A' <= (*msg)[3] && (*msg)[3] <= 'Z')) &&
139 (isdigit((unsigned char) (*msg)[4]) ||
140 ('A' <= (*msg)[4] && (*msg)[4] <= 'Z')))
141 sqlstate = "";
142 throw(SQL, "assert", SQLSTATE(M0M29) "%s", *msg);
143 }
144 return MAL_SUCCEED;
145}
146#endif
147