Changeset: 3e6bf4b4c303 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3e6bf4b4c303
Modified Files:
        sql/backends/monet5/UDF/pyapi/connection.c
        sql/backends/monet5/UDF/pyapi/pyapi.c
        sql/backends/monet5/UDF/pyapi/pyapi.h
Branch: default
Log Message:

Still need to do dynamic function lookup.


diffs (168 lines):

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
@@ -9,6 +9,9 @@
 #define PyString_FromString PyUnicode_FromString
 #endif
 
+CREATE_SQL_FUNCTION_PTR(void,SQLdestroyResult);
+CREATE_SQL_FUNCTION_PTR(str,SQLstatementIntern);
+
 static PyObject *
 _connection_execute(Py_ConnectionObject *self, PyObject *args)
 {
@@ -207,13 +210,13 @@ PyTypeObject Py_ConnectionType = {
 
 void _connection_cleanup_result(void* output) 
 {
-    SQLdestroyResult((res_table*) output);
+    (*SQLdestroyResult_ptr)((res_table*) output);
 }
 
 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_ptr)(c, &query, "name", 1, 0, result);
     return res;
 }
 
@@ -243,7 +246,8 @@ str _connection_init(void)
 {
     str msg = MAL_SUCCEED;
     _connection_import_array();
-
+    LOAD_SQL_FUNCTION_PTR(SQLdestroyResult);
+    LOAD_SQL_FUNCTION_PTR(SQLstatementIntern);
     if (msg != MAL_SUCCEED) {
         return msg;
     }
diff --git a/sql/backends/monet5/UDF/pyapi/pyapi.c 
b/sql/backends/monet5/UDF/pyapi/pyapi.c
--- a/sql/backends/monet5/UDF/pyapi/pyapi.c
+++ b/sql/backends/monet5/UDF/pyapi/pyapi.c
@@ -34,7 +34,6 @@
 #define PythonUnicodeType char
 #else
 #define PythonUnicodeType Py_UNICODE
-
 #endif
 
 const char* pyapi_enableflag = "embedded_py";
@@ -96,6 +95,17 @@ static char* FunctionBasePath(void) {
     return basepath;
 }
 
+CREATE_SQL_FUNCTION_PTR(str,batbte_dec2_dbl);
+CREATE_SQL_FUNCTION_PTR(str,batsht_dec2_dbl);
+CREATE_SQL_FUNCTION_PTR(str,batint_dec2_dbl);
+CREATE_SQL_FUNCTION_PTR(str,batlng_dec2_dbl);
+CREATE_SQL_FUNCTION_PTR(str,bathge_dec2_dbl);
+CREATE_SQL_FUNCTION_PTR(str,batstr_2time_timestamp);
+CREATE_SQL_FUNCTION_PTR(str,batstr_2time_daytime);
+CREATE_SQL_FUNCTION_PTR(str,batstr_2_date);
+CREATE_SQL_FUNCTION_PTR(str,batdbl_num2dec_lng);
+CREATE_SQL_FUNCTION_PTR(str,SQLbatstr_cast);
+
 static MT_Lock pyapiLock;
 static MT_Lock queryLock;
 static int pyapiInitialized = FALSE;
@@ -1574,6 +1584,16 @@ str
                 return createException(MAL, "pyapi.eval", "Failed to load 
function \"loads\" from Marshal module.");
             }
             PyEval_SaveThread();
+                       LOAD_SQL_FUNCTION_PTR(batbte_dec2_dbl);
+                       LOAD_SQL_FUNCTION_PTR(batsht_dec2_dbl);
+                       LOAD_SQL_FUNCTION_PTR(batint_dec2_dbl);
+                       LOAD_SQL_FUNCTION_PTR(batlng_dec2_dbl);
+                       LOAD_SQL_FUNCTION_PTR(bathge_dec2_dbl);
+                       LOAD_SQL_FUNCTION_PTR(batstr_2time_timestamp);
+                       LOAD_SQL_FUNCTION_PTR(batstr_2time_daytime);
+                       LOAD_SQL_FUNCTION_PTR(batstr_2_date);
+                       LOAD_SQL_FUNCTION_PTR(batdbl_num2dec_lng);
+                       LOAD_SQL_FUNCTION_PTR(SQLbatstr_cast);
             if (msg != MAL_SUCCEED) {
                 MT_lock_unset(&pyapiLock);
                 return msg;
@@ -2627,7 +2647,7 @@ str ConvertFromSQLType(Client cntxt, BAT
         stk->stk[6].val.ival = digits;
         stk->stk[6].vtype = TYPE_int;
 
-        res = SQLbatstr_cast(cntxt, &mb, stk, pci);
+        res = (*SQLbatstr_cast_ptr)(cntxt, &mb, stk, pci);
 
         if (res == MAL_SUCCEED) {
             *ret_bat = BATdescriptor(stk->stk[0].val.bval);
@@ -2649,20 +2669,20 @@ str ConvertFromSQLType(Client cntxt, BAT
         switch(bat_type) 
         {
             case TYPE_bte:
-                res = batbte_dec2_dbl(&result, &hpos, &b->batCacheid);
+                res = (*batbte_dec2_dbl_ptr)(&result, &hpos, &b->batCacheid);
                 break;
             case TYPE_sht:
-                res = batsht_dec2_dbl(&result, &hpos, &b->batCacheid);
+                res = (*batsht_dec2_dbl_ptr)(&result, &hpos, &b->batCacheid);
                 break;
             case TYPE_int:
-                res = batint_dec2_dbl(&result, &hpos, &b->batCacheid);
+                res = (*batint_dec2_dbl_ptr)(&result, &hpos, &b->batCacheid);
                 break;
             case TYPE_lng:
-                res = batlng_dec2_dbl(&result, &hpos, &b->batCacheid);
+                res = (*batlng_dec2_dbl_ptr)(&result, &hpos, &b->batCacheid);
                 break;
 #ifdef HAVE_HGE
             case TYPE_hge:
-                res = bathge_dec2_dbl(&result, &hpos, &b->batCacheid);
+                res = (*bathge_dec2_dbl_ptr)(&result, &hpos, &b->batCacheid);
                 break;
 #endif
             default: 
@@ -2694,16 +2714,16 @@ ConvertToSQLType(Client cntxt, BAT *b, s
     switch(sql_subtype->type->eclass)
     {
         case EC_TIMESTAMP:
-            res = batstr_2time_timestamp(&result_bat, &b->batCacheid, &digits);
+            res = (*batstr_2time_timestamp_ptr)(&result_bat, &b->batCacheid, 
&digits);
             break;
         case EC_TIME:
-            res = batstr_2time_daytime(&result_bat, &b->batCacheid, &digits);
+            res = (*batstr_2time_daytime_ptr)(&result_bat, &b->batCacheid, 
&digits);
             break;
         case EC_DATE:
-            res = batstr_2_date(&result_bat, &b->batCacheid);
+            res = (*batstr_2_date_ptr)(&result_bat, &b->batCacheid);
             break;
         case EC_DEC:
-            res = batdbl_num2dec_lng(&result_bat, &b->batCacheid, &digits, 
&scale);
+            res = (*batdbl_num2dec_lng_ptr)(&result_bat, &b->batCacheid, 
&digits, &scale);
             break;
         default: 
             return createException(MAL, "pyapi.eval", "Convert To SQL Type: 
Unrecognized SQL type %s (%d).", sql_subtype->type->sqlname, 
sql_subtype->type->eclass);
diff --git a/sql/backends/monet5/UDF/pyapi/pyapi.h 
b/sql/backends/monet5/UDF/pyapi/pyapi.h
--- a/sql/backends/monet5/UDF/pyapi/pyapi.h
+++ b/sql/backends/monet5/UDF/pyapi/pyapi.h
@@ -101,4 +101,23 @@ pyapi_export str PyAPIprelude(void *ret)
 
 int PyAPIEnabled(void);
 
+#ifdef WIN32
+#define CREATE_SQL_FUNCTION_PTR(retval, fcnname)     \
+   typedef retval (*fcnname##_ptr_tpe)();            \
+   fcnname##_ptr_tpe fcnname##_ptr = NULL;
+
+#define LOAD_SQL_FUNCTION_PTR(fcnname)                                         
    \
+    fcnname##_ptr = (fcnname##_ptr_tpe) getAddress(NULL, "lib_sql.dll", NULL, 
#fcnname, 0); \
+    if (fcnname##_ptr == NULL) {                                               
            \
+        msg = createException(MAL, "pyapi.eval", "Failed to load function %s", 
#fcnname);  \
+    }
+#else
+#define CREATE_SQL_FUNCTION_PTR(retval, fcnname)     \
+   typedef retval (*fcnname##_ptr_tpe)();            \
+   fcnname##_ptr_tpe fcnname##_ptr = (fcnname##_ptr_tpe)fcnname;
+
+#define LOAD_SQL_FUNCTION_PTR(fcnname) (void) fcnname
+#endif
+
+
 #endif /* _PYPI_LIB_ */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to