Repository: MonetDBSolutions/MonetDBe-Python (language: python)

Issue:
Current monetdbe (0.11) has an issue with function creation
```
SQLException:sql.create_func:42000!CREATE FUNCTION: name 'afunkyfunc' (double) already in use
Traceback (most recent call last):
  File "/home/niels/y.py", line 14, in <module>
    res = cursor.execute(q)
  File "/home/niels/.local/lib/python3.9/site-packages/monetdbe/cursors.py", line 142, in execute
    return self._execute_monetdbe(operation, parameters)
  File "/home/niels/.local/lib/python3.9/site-packages/monetdbe/cursors.py", line 127, in _execute_monetdbe
    self.connection.result, self.rowcount = execute(statement, make_result=True)
  File "/home/niels/.local/lib/python3.9/site-packages/monetdbe/_cffi/internal.py", line 79, in execute
    check_error(lib.monetdbe_execute(statement, p_result, affected_rows))
  File "/home/niels/.local/lib/python3.9/site-packages/monetdbe/_cffi/errors.py", line 59, in check_error
    raise exception(msg)
monetdbe.exceptions.OperationalError: CREATE FUNCTION: name 'afunkyfunc' (double) already in use
```
ie the current monetdbe (0.11) has an issue with function creation, I seem to remember I fixed something for this (on default this is fixed, not sure how the status on jul branch is).
```
import monetdbe
import os
database = '/tmp/test.mdbe'
# Removes the database if it already exists
if os.path.exists(database):
    os.system(f'rm -rf {database}')
with monetdbe.connect(database) as conn:
    #conn.set_autocommit(True)
    cursor = conn.cursor()
    q = "create function afunkyfunc(a double) returns double begin return a/2; end"
    res = cursor.execute(q)
    res = cursor.execute("select afunkyfunc(1.0);")
    print(cursor.fetchone()[0])
```
is the test I used


Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index 74b2c6f..cb3c57c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -105,7 +105,7 @@ celerybeat.pid
 .env
 .venv
 env/
-venv/
+venv*/
 ENV/
 env.bak/
 venv.bak/
diff --git a/Makefile b/Makefile
index ba70526..b0fe973 100644
--- a/Makefile
+++ b/Makefile
@@ -10,20 +10,17 @@ all: test
 
 venv/:
 	python3 -m venv venv
-	venv/bin/pip install --upgrade pip wheel build
+	venv/bin/pip install --upgrade pip wheel build setuptools
 
 venv/installed: venv/
 	venv/bin/pip install -e ".[test]"
 	touch venv/installed
 
 setup: venv/installed
+
 build: venv/installed
 	venv/bin/pyproject-build
 
-build-osx-m1: venv/
-	MONETDB_BRANCH=oct2020 CFLAGS="-I/opt/include -L/opt/lib" venv/bin/pyproject-build
-
-
 test: setup
 	venv/bin/pytest
 
@@ -93,3 +90,23 @@ twine: venv/bin/twine
 
 info: setup
 	venv/bin/python -c "from monetdbe._cffi.util import print_info; print_info()"
+
+venv38/:
+	/opt/homebrew/Cellar/python@3.8/3.8.*/bin/python3.8 -m venv venv38
+
+venv39/:
+	/opt/homebrew/Cellar/python@3.9/3.9.*/bin/python3.9 -m venv venv39
+
+venv310/:
+	/opt/homebrew/Cellar/python@3.10/3.10.*/bin/python3.10 -m venv venv310
+
+osx-m1-all-wheels: venv38/ venv39/ venv310/
+	venv38/bin/pip install --upgrade pip wheel setuptools build
+	venv39/bin/pip install --upgrade pip wheel setuptools build
+	venv310/bin/pip install --upgrade pip wheel setuptools build
+	MONETDB_BRANCH=Jul2021 CFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" venv38/bin/python -m build
+	MONETDB_BRANCH=Jul2021 CFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" venv39/bin/python -m build
+	MONETDB_BRANCH=Jul2021 CFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" venv310/bin/python -m build
+
+osx-m1-wheel: venv/
+	MONETDB_BRANCH=Jul2021 CFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" venv/bin/python -m build


Test patch:
diff --git a/tests/test_regression.py b/tests/test_regression.py
index b6aae4a..17b8950 100644
--- a/tests/test_regression.py
+++ b/tests/test_regression.py
@@ -551,3 +551,15 @@ def test_issue_136_bigint_result(self):
         assert (len(res5) == 1)
         assert (len(res5[0]) == 4)
         con.close()
+
+    def test_issue158_afunkyfunc(self):
+        """
+        the afunkyfunc name should not be taken, but in older monetdbe versions it is.
+        """
+        with monetdbe.connect(":memory:") as conn:
+            # conn.set_autocommit(True)
+            cursor = conn.cursor()
+            q = "create function afunkyfunc(a double) returns double begin return a/2; end"
+            res = cursor.execute(q)
+            res = cursor.execute("select afunkyfunc(1.0);")
+            print(cursor.fetchone()[0])