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#ifndef MAL_BACKEND_H
10#define MAL_BACKEND_H
11
12#include "streams.h"
13#include "mal.h"
14#include "mal_client.h"
15#include "sql_mvc.h"
16#include "sql_qc.h"
17
18/*
19 * The back-end structure collects the information needed to support
20 * compilation and execution of the SQL code against the Monet Version 5
21 * back end. Note that the back-end can be called upon by the front-end
22 * to handle specific tasks, such as catalog management (sql_mvc)
23 * and query execution (sql_qc). For this purpose, the front-end needs
24 * access to operations defined in the back-end, in particular for
25 * freeing the stack and code segment.
26 */
27
28typedef enum output_format {
29 OFMT_CSV = 0,
30 OFMT_JSON = 1,
31 OFMT_NONE = 3
32} ofmt;
33
34/* The cur_append variable on an insert/update/delete on a partitioned table, tracks the current MAL variable holding
35 * the total number of rows affected. The first_statement_generated looks if the first of the sub-statements was
36 * generated or not */
37
38typedef struct backend {
39 char language; /* 'S' or 's' or 'X' */
40 char depth;
41 bool first_statement_generated;
42 mvc *mvc;
43 stream *out;
44 ofmt output_format; /* csv, json */
45 Client client;
46 MalBlkPtr mb; /* needed during mal generation */
47 int mvc_var;
48 int cur_append;
49 int vtop; /* top of the variable stack before the current function */
50 cq *q; /* pointer to the cached query */
51} backend;
52
53extern backend *backend_reset(backend *b);
54extern backend *backend_create(mvc *m, Client c);
55extern void backend_destroy(backend *b);
56
57#endif /*MAL_BACKEND_H*/
58