Changeset: ea33fe35a14c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ea33fe35a14c
Modified Files:
gdk/gdk_system.h
monetdb5/extras/pyapi/connection.c
monetdb5/extras/pyapi/pyapi.c
sql/backends/monet5/Tests/pyapi25.sql
sql/backends/monet5/Tests/pyapi25.stable.err
sql/backends/monet5/Tests/pyapi25.stable.out
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_execute.h
Branch: pyapi
Log Message:
Only allow readonly statements in loopback queries.
diffs (260 lines):
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -129,7 +129,7 @@ typedef struct {
if (forked_process) break; \
TEMDEBUG fprintf(stderr, "#%s: locking %s...\n", (n),
(l)->name); \
pthread_mutex_lock(&(l)->lock); \
- if (forked_process) fprintf(stderr, "#%s: locking %s
complete\n", \
+ TEMDEBUG fprintf(stderr, "#%s: locking %s complete\n", \
(n), (l)->name); \
} while (0)
#define MT_lock_unset(l, n) \
@@ -347,7 +347,7 @@ typedef struct {
if (forked_process) break; \
TEMDEBUG fprintf(stderr, "#%s: sema %s down...\n",(n),
(s)->name); \
pthread_sema_down(&(s)->sema); \
- if (forked_process) fprintf(stderr, "#%s: sema %s down
complete\n", \
+ TEMDEBUG fprintf(stderr, "#%s: sema %s down complete\n", \
(n), (s)->name); \
} while (0)
diff --git a/monetdb5/extras/pyapi/connection.c
b/monetdb5/extras/pyapi/connection.c
--- a/monetdb5/extras/pyapi/connection.c
+++ b/monetdb5/extras/pyapi/connection.c
@@ -130,7 +130,7 @@ static void _connection_cleanup_result(v
static char* _connection_query(Client cntxt, char* query, res_table** result) {
str res = MAL_SUCCEED;
Client c = cntxt;
- res = SQLstatementIntern(c, &query, "name", 1, 0, result);
+ res = SQLstatementIntern_wrapped(c, &query, "name", 1, 0, 1, 1, result);
return res;
}
diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c
--- a/monetdb5/extras/pyapi/pyapi.c
+++ b/monetdb5/extras/pyapi/pyapi.c
@@ -15,7 +15,6 @@
#include "sql_catalog.h"
#include "pyapi.h"
#include "connection.h"
-#include "mal_dataflow.h"
// Python library
#undef _GNU_SOURCE
diff --git a/sql/backends/monet5/Tests/pyapi25.sql
b/sql/backends/monet5/Tests/pyapi25.sql
--- a/sql/backends/monet5/Tests/pyapi25.sql
+++ b/sql/backends/monet5/Tests/pyapi25.sql
@@ -23,18 +23,29 @@ DROP FUNCTION pyapi09;
DROP TABLE pyapi09table;
DROP TABLE pyapi09multiplication;
-# Update table?
+# Update table is not allowed, test whether that works properly and throws an
error.
+CREATE TABLE pyapi09multiplication(i integer);
+INSERT INTO pyapi09multiplication VALUES (3);
CREATE TABLE pyapi09table(i integer);
INSERT INTO pyapi09table VALUES (1), (2), (3), (4);
-CREATE TABLE pyapi09multiplication(i integer);
-INSERT INTO pyapi09multiplication VALUES (3);
CREATE FUNCTION pyapi09(i integer) returns integer
language PYTHON
{
- _conn.execute('UPDATE pyapi09multiplication SET i=20;')
+ _conn.execute('CREATE TABLE mytable(i INTEGER);')
return i
};
+
+SELECT * FROM pyapi09multiplication; # 3
+SELECT pyapi09(i) FROM pyapi09table;
+ROLLBACK;
+
+START TRANSACTION;
+CREATE TABLE pyapi09multiplication(i integer);
+INSERT INTO pyapi09multiplication VALUES (3);
+CREATE TABLE pyapi09table(i integer);
+INSERT INTO pyapi09table VALUES (1), (2), (3), (4);
+
CREATE FUNCTION pyapi09map(i integer) returns integer
language PYTHON_MAP
{
@@ -43,15 +54,5 @@ language PYTHON_MAP
};
SELECT * FROM pyapi09multiplication; # 3
-SELECT pyapi09(i) FROM pyapi09table;
-SELECT * FROM pyapi09multiplication; # 20
SELECT pyapi09map(i) FROM pyapi09table;
-SELECT * FROM pyapi09multiplication; # 20, update in PYTHON_MAP does not work
(we should probably disable it)
-
-DROP FUNCTION pyapi09;
-DROP FUNCTION pyapi09map;
-DROP TABLE pyapi09table;
-DROP TABLE pyapi09multiplication;
-
ROLLBACK;
-
diff --git a/sql/backends/monet5/Tests/pyapi25.stable.err
b/sql/backends/monet5/Tests/pyapi25.stable.err
--- a/sql/backends/monet5/Tests/pyapi25.stable.err
+++ b/sql/backends/monet5/Tests/pyapi25.stable.err
@@ -31,6 +31,24 @@ stderr of test 'pyapi25` in directory 's
# 14:54:29 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e"
"--host=/var/tmp/mtest-32200" "--port=34132"
# 14:54:29 >
+MAPI = (monetdb) /var/tmp/mtest-32688/.s.monetdb.38881
+QUERY = SELECT pyapi09(i) FROM pyapi09table;
+ERROR = !Python exception
+ !
+ ! 1. def pyfun(i,_columns,_column_types,_conn):
+ !> 2. _conn.execute('CREATE TABLE mytable(i INTEGER);')
+ ! 3. return i
+ ! 4.
+ !SQL Query Failed: ParseException:SQLparser:Mode set to readonly, but
received token 1
+MAPI = (monetdb) /var/tmp/mtest-32688/.s.monetdb.38881
+QUERY = SELECT pyapi09map(i) FROM pyapi09table;
+ERROR = !MALException:pyapi.eval:Python exception
+ !
+ ! 1. def pyfun(i,_columns,_column_types,_conn):
+ !> 2. _conn.execute('UPDATE pyapi09multiplication SET i=10;')
+ ! 3. return i
+ ! 4.
+ !SQL Query Failed: ParseException:SQLparser:Mode set to readonly, but
received token 69
# 14:54:30 >
# 14:54:30 > "Done."
diff --git a/sql/backends/monet5/Tests/pyapi25.stable.out
b/sql/backends/monet5/Tests/pyapi25.stable.out
--- a/sql/backends/monet5/Tests/pyapi25.stable.out
+++ b/sql/backends/monet5/Tests/pyapi25.stable.out
@@ -64,12 +64,12 @@ Ready.
#DROP FUNCTION pyapi09;
#DROP TABLE pyapi09table;
#DROP TABLE pyapi09multiplication;
+#CREATE TABLE pyapi09multiplication(i integer);
+#INSERT INTO pyapi09multiplication VALUES (3);
+[ 1 ]
#CREATE TABLE pyapi09table(i integer);
#INSERT INTO pyapi09table VALUES (1), (2), (3), (4);
[ 4 ]
-#CREATE TABLE pyapi09multiplication(i integer);
-#INSERT INTO pyapi09multiplication VALUES (3);
-[ 1 ]
#CREATE FUNCTION pyapi09(i integer) returns integer
#language PYTHON
#{
@@ -88,40 +88,20 @@ Ready.
% int # type
% 1 # length
[ 3 ]
-#SELECT pyapi09(i) FROM pyapi09table;
-% sys.L # table_name
-% pyapi09_i # name
-% int # type
-% 1 # length
+#ROLLBACK;
+#START TRANSACTION;
+#CREATE TABLE pyapi09multiplication(i integer);
+#INSERT INTO pyapi09multiplication VALUES (3);
[ 1 ]
-[ 2 ]
-[ 3 ]
+#CREATE TABLE pyapi09table(i integer);
+#INSERT INTO pyapi09table VALUES (1), (2), (3), (4);
[ 4 ]
#SELECT * FROM pyapi09multiplication;
% sys.pyapi09multiplication # table_name
% i # name
% int # type
-% 2 # length
-[ 20 ]
-#SELECT pyapi09map(i) FROM pyapi09table;
-% sys.L # table_name
-% pyapi09map_i # name
-% int # type
% 1 # length
-[ 1 ]
-[ 2 ]
[ 3 ]
-[ 4 ]
-#SELECT * FROM pyapi09multiplication;
-% sys.pyapi09multiplication # table_name
-% i # name
-% int # type
-% 2 # length
-[ 20 ]
-#DROP FUNCTION pyapi09;
-#DROP FUNCTION pyapi09map;
-#DROP TABLE pyapi09table;
-#DROP TABLE pyapi09multiplication;
#ROLLBACK;
# 14:54:30 >
diff --git a/sql/backends/monet5/sql_execute.c
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -43,6 +43,13 @@
/* #define _SQL_COMPILE */
+
+str
+SQLstatementIntern(Client c, str *expr, str nme, int execute, bit output,
res_table **result)
+{
+ return SQLstatementIntern_wrapped(c, expr, nme, execute, output, 0, 0,
result);
+}
+
/*
* BEWARE: SQLstatementIntern only commits after all statements found
* in expr are executed, when autocommit mode is enabled.
@@ -51,7 +58,7 @@
* is executed within the client context specified. This leads to context
juggling.
*/
str
-SQLstatementIntern(Client c, str *expr, str nme, int execute, bit output,
res_table **result)
+SQLstatementIntern_wrapped(Client c, str *expr, str nme, int execute, bit
output, bit readonly, bit singlestatement, res_table **result)
{
int status = 0;
int err = 0;
@@ -155,7 +162,21 @@ SQLstatementIntern(Client c, str *expr,
c->glb = oldglb;
goto endofcompile;
}
-
+ if (readonly) {
+ switch (m->sym->token) {
+ case SQL_SELECT:
+ case SQL_JOIN:
+ case SQL_CROSS:
+ case SQL_UNION:
+ case SQL_EXCEPT:
+ case SQL_INTERSECT:
+ break;
+ default:
+ msg = createException(PARSE,
"SQLparser", "Mode set to readonly, but received token %d", m->sym->token);
+ sqlcleanup(m, err);
+ goto endofcompile;
+ }
+ }
/*
* We have dealt with the first parsing step and advanced the
input reader
* to the next statement (if any).
@@ -225,6 +246,8 @@ SQLstatementIntern(Client c, str *expr,
#endif
assert(c->glb == 0 || c->glb == oldglb); /* detect leak
*/
c->glb = oldglb;
+
+ if (singlestatement) break;
}
if (m->results && result) { /* return all results sets */
*result = m->results;
diff --git a/sql/backends/monet5/sql_execute.h
b/sql/backends/monet5/sql_execute.h
--- a/sql/backends/monet5/sql_execute.h
+++ b/sql/backends/monet5/sql_execute.h
@@ -11,6 +11,7 @@
#include "sql.h"
sql5_export str SQLstatementREST(Client c, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
+sql5_export str SQLstatementIntern_wrapped(Client c, str *expr, str nme, int
execute, bit output, bit readonly, bit singlestatement, res_table **result);
sql5_export str SQLstatementIntern(Client c, str *expr, str nme, int execute,
bit output, res_table **result);
sql5_export str SQLexecutePrepared(Client c, backend *be, cq *q);
sql5_export str SQLengineIntern(Client c, backend *be);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list