Changeset: d64bf688bd70 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d64bf688bd70
Modified Files:
sql/backends/monet5/Tests/pyapi34.sql
sql/backends/monet5/UDF/pyapi/connection.c
Branch: Jul2017
Log Message:
Allow unicode loopback queries in Python 2.
diffs (67 lines):
diff --git a/sql/backends/monet5/Tests/pyapi34.sql
b/sql/backends/monet5/Tests/pyapi34.sql
--- a/sql/backends/monet5/Tests/pyapi34.sql
+++ b/sql/backends/monet5/Tests/pyapi34.sql
@@ -5,7 +5,7 @@ CREATE TABLE booleans(a BOOLEAN);
INSERT INTO booleans VALUES (1), (0), (1);
CREATE FUNCTION pyapi34a(inp BOOLEAN) RETURNS BOOLEAN LANGUAGE PYTHON {
- results = _conn.execute('SELECT * FROM booleans;')
+ results = _conn.execute(u'SELECT * FROM booleans;')
return {'result': numpy.logical_xor(inp, results['a']) };
};
diff --git a/sql/backends/monet5/UDF/pyapi/connection.c
b/sql/backends/monet5/UDF/pyapi/connection.c
--- a/sql/backends/monet5/UDF/pyapi/connection.c
+++ b/sql/backends/monet5/UDF/pyapi/connection.c
@@ -19,28 +19,40 @@ CREATE_SQL_FUNCTION_PTR(str, create_tabl
static PyObject *_connection_execute(Py_ConnectionObject *self, PyObject *args)
{
- if (!PyString_CheckExact(args)) {
+ char *query = NULL;
+#ifndef IS_PY3K
+ if (PyUnicode_CheckExact(args)) {
+ PyObject* str = PyUnicode_AsUTF8String(args);
+ if (!str) {
+ PyErr_Format(PyExc_Exception, "Unicode failure.");
+ return NULL;
+ }
+ query = GDKstrdup(((PyStringObject *)str)->ob_sval);
+ Py_DECREF(str);
+ } else
+#endif
+ if (PyString_CheckExact(args)) {
+#ifndef IS_PY3K
+ query = GDKstrdup(((PyStringObject *)args)->ob_sval);
+#else
+ query = GDKstrdup(PyUnicode_AsUTF8(args));
+#endif
+ } else {
PyErr_Format(PyExc_TypeError,
"expected a query string, but got an
object of type %s",
Py_TYPE(args)->tp_name);
return NULL;
}
+ if (!query) {
+ PyErr_Format(PyExc_Exception, "%s", MAL_MALLOC_FAIL);
+ return NULL;
+ }
if (!self->mapped) {
// This is not a mapped process, so we can just directly
execute the
// query here
PyObject *result;
res_table *output = NULL;
char *res = NULL;
- char *query;
-#ifndef IS_PY3K
- query = GDKstrdup(((PyStringObject *)args)->ob_sval);
-#else
- query = GDKstrdup(PyUnicode_AsUTF8(args));
-#endif
- if (!query) {
- PyErr_Format(PyExc_Exception, MAL_MALLOC_FAIL);
- return NULL;
- }
Py_BEGIN_ALLOW_THREADS;
res = _connection_query(self->cntxt, query, &output);
Py_END_ALLOW_THREADS;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list