Bill 2 years ago
commit 2cd65e121a

@ -243,8 +243,8 @@ RESERVED = MatchFirst([
WITHIN, WITHIN,
INTO, INTO,
]) ])
L_INLINE = Literal("<k>").suppress() L_INLINE = Literal("<sql>").suppress()
R_INLINE = Literal("</k>").suppress() R_INLINE = Literal("</sql>").suppress()
LBRACE = Literal("{").suppress() LBRACE = Literal("{").suppress()
RBRACE = Literal("}").suppress() RBRACE = Literal("}").suppress()
LSB = Literal("[").suppress() LSB = Literal("[").suppress()

@ -66,7 +66,7 @@ def parser(literal_string, ident, sqlserver=False):
var_name = ~RESERVED + ident var_name = ~RESERVED + ident
inline_kblock = (L_INLINE + SkipTo(R_INLINE, include=True))("c") inline_sqlblock = (L_INLINE + SkipTo(R_INLINE, include=True))("sql")
# EXPRESSIONS # EXPRESSIONS
expr = Forward() expr = Forward()
column_type, column_definition, column_def_references = get_column_type( column_type, column_definition, column_def_references = get_column_type(
@ -570,7 +570,8 @@ def parser(literal_string, ident, sqlserver=False):
| assign("default character set", EQ + var_name) | assign("default character set", EQ + var_name)
| assign("default charset", EQ + var_name) | assign("default charset", EQ + var_name)
) )
+ Optional(AS.suppress() + infix_notation(query, [])("query")) + Optional(AS.suppress() + query("query"))
# investigate why infix_notation(query, []) eats up the rest of queries
)("create_table") )("create_table")
create_view = ( create_view = (
@ -724,7 +725,7 @@ def parser(literal_string, ident, sqlserver=False):
)("stmts"), ";") )("stmts"), ";")
other_stmt = ( other_stmt = (
inline_kblock inline_sqlblock
| udf | udf
) ("stmts") ) ("stmts")

@ -9,7 +9,6 @@ from engine.utils import (base62alp, base62uuid, enlist, get_innermost,
get_legal_name) get_legal_name)
from reconstruct.storage import ColRef, Context, TableInfo from reconstruct.storage import ColRef, Context, TableInfo
class ast_node: class ast_node:
header = [] header = []
types = dict() types = dict()
@ -1536,6 +1535,24 @@ class udf(ast_node):
else: else:
return udf.ReturnPattern.bulk_return return udf.ReturnPattern.bulk_return
class passthru_sql(ast_node):
name = 'sql'
first_order = name
import re
# escapestr = r'''(?:((?:[^;"']|"[^"]*"|'[^']*')+)|(?:--[^\r\n]*[\r|\n])+)'''
# escape_comment = fr'''(?:{escapestr}|{escapestr}*-{escapestr}*)'''
seprator = re.compile(r'''((?:[^;"']|"[^"]*"|'[^']*')+)''')
def __init__(self, _, node, context:Context):
sqls = passthru_sql.seprator.split(node['sql'])
for sql in sqls:
sq = sql.strip(' \t\n\r;')
if sq:
context.queries.append('Q' + sql + ';')
lq = sq.lower()
if lq.startswith('select'):
context.queries.append('O')
class user_module_function(OperatorBase): class user_module_function(OperatorBase):
def __init__(self, name, nargs, ret_type, context : Context): def __init__(self, name, nargs, ret_type, context : Context):
super().__init__(name, nargs, lambda *_: ret_type, call=fn_behavior) super().__init__(name, nargs, lambda *_: ret_type, call=fn_behavior)

@ -197,7 +197,7 @@ inline constexpr static unsigned char monetdbe_type_szs[] = {
constexpr uint32_t output_buffer_size = 65536; constexpr uint32_t output_buffer_size = 65536;
void print_monetdb_results(Server* srv, const char* sep = " ", const char* end = "\n", void print_monetdb_results(Server* srv, const char* sep = " ", const char* end = "\n",
uint32_t limit = std::numeric_limits<uint32_t>::max()) { uint32_t limit = std::numeric_limits<uint32_t>::max()) {
if (!srv->haserror() && limit){ if (!srv->haserror() && srv->cnt && limit){
char buffer[output_buffer_size]; char buffer[output_buffer_size];
auto _res = static_cast<monetdbe_result*> (srv->res); auto _res = static_cast<monetdbe_result*> (srv->res);
const auto& ncols = _res->ncols; const auto& ncols = _res->ncols;
@ -209,6 +209,7 @@ void print_monetdb_results(Server* srv, const char* sep = " ", const char* end =
const char* err_msg = nullptr; const char* err_msg = nullptr;
for(uint32_t i = 0; i < ncols; ++i){ for(uint32_t i = 0; i < ncols; ++i){
err_msg = monetdbe_result_fetch(_res, &cols[i], i); err_msg = monetdbe_result_fetch(_res, &cols[i], i);
if(err_msg) { free(cols); return; }
col_data[i] = static_cast<char *>(cols[i]->data); col_data[i] = static_cast<char *>(cols[i]->data);
prtfns[i] = monetdbe_prtfns[cols[i]->type]; prtfns[i] = monetdbe_prtfns[cols[i]->type];
szs [i] = monetdbe_type_szs[cols[i]->type]; szs [i] = monetdbe_type_szs[cols[i]->type];

Loading…
Cancel
Save