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 "mal_backend.h"
15 : #include "sql_strimps.h"
16 :
17 : static str
18 0 : sql_load_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, BAT **b)
19 : {
20 0 : mvc *m = NULL;
21 0 : str msg = getSQLContext(cntxt, mb, &m, NULL);
22 0 : str sch,tbl,col;
23 0 : sql_schema *s;
24 0 : sql_table *t;
25 0 : sql_column *c;
26 :
27 0 : if (msg != MAL_SUCCEED || (msg = checkSQLContext(cntxt)) != NULL)
28 0 : return msg;
29 :
30 0 : sch = *getArgReference_str(stk, pci, 1);
31 0 : tbl = *getArgReference_str(stk, pci, 2);
32 0 : col = *getArgReference_str(stk, pci, 3);
33 :
34 0 : if (strNil(sch))
35 0 : throw(SQL, "sql.createstrimps", SQLSTATE(42000) "Schema name cannot be NULL");
36 0 : if (strNil(tbl))
37 0 : throw(SQL, "sql.createstrimps", SQLSTATE(42000) "Table name cannot be NULL");
38 0 : if (strNil(col))
39 0 : throw(SQL, "sql.createstrimps", SQLSTATE(42000) "Column name cannot be NULL");
40 :
41 0 : if (!(s = mvc_bind_schema(m, sch)))
42 0 : throw(SQL, "sql.createstrimps", SQLSTATE(3FOOO) "Unknown schema %s", sch);
43 :
44 0 : if (!mvc_schema_privs(m, s))
45 0 : throw(SQL, "sql.createstrimps", SQLSTATE(42000) "Access denied for %s to schema '%s'",
46 : get_string_global_var(m, "current_user"), s->base.name);
47 0 : if (!(t = mvc_bind_table(m, s, tbl)))
48 0 : throw(SQL, "sql.createstrimps", SQLSTATE(42S02) "Unknown table %s.%s", sch, tbl);
49 0 : if (!isTable(t))
50 0 : throw(SQL, "sql.createstrimps", SQLSTATE(42000) "%s '%s' is not persistent",
51 0 : TABLE_TYPE_DESCRIPTION(t->type, t->properties), t->base.name);
52 0 : if (!(c = mvc_bind_column(m, t, col)))
53 0 : throw(SQL, "sql.createstrimps", SQLSTATE(38000) "Unknown column %s.%s.%s", sch, tbl, col);
54 :
55 0 : sqlstore *store = m->session->tr->store;
56 0 : *b = store->storage_api.bind_col(m->session->tr, c, RDONLY);
57 0 : if (*b == 0)
58 0 : throw(SQL, "sql.createstrimps", SQLSTATE(HY005) "Cannot access column %s", col);
59 :
60 : return msg;
61 :
62 : }
63 :
64 : str
65 0 : sql_createstrimps(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
66 : {
67 0 : BAT *b, *s;
68 0 : gdk_return res;
69 0 : str msg = MAL_SUCCEED;
70 :
71 0 : if ((msg = sql_load_bat(cntxt, mb, stk, pci, &b)) != MAL_SUCCEED)
72 : return msg;
73 :
74 0 : if (!(s = BATdense(0, 0, b->batCount))) {
75 0 : BBPunfix(b->batCacheid);
76 0 : throw(SQL, "sql.createstrimps", SQLSTATE(HY013) MAL_MALLOC_FAIL);
77 : }
78 :
79 0 : res = STRMPcreate(b, s);
80 0 : BBPunfix(b->batCacheid);
81 0 : BBPunfix(s->batCacheid);
82 0 : if (res != GDK_SUCCEED)
83 0 : throw(SQL, "sql.createstrimps", GDK_EXCEPTION);
84 :
85 : return MAL_SUCCEED;
86 : }
87 :
88 : /* str */
89 : /* sql_strimpfilter(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) */
90 : /* { */
91 : /* BAT *b; */
92 : /* if (sql_load_bat(cntxt, mb, stk, pci, &b) != MAL_SUCCEED) */
93 : /* throw(SQL, "sql.createstrimps", SQLSTATE(HY002) OPERATION_FAILED); */
94 :
95 : /* return MAL_SUCCEED; */
96 : /* } */
|