I have database with a single table Person
which has a name(str)
and age(int)
columns. So, I create simple validate function for my sqlite3.connection
def adult(age):
return age > 18
And with following code, it works fine
connection = sqlite3.connect(r'C:\Dev\Garbage\database.db')
with connection:
connection.create_function('adult', 1, adult)
cursor = connection.cursor()
persons = cursor.execute('select "p"."name", "p"."age" from "Person" "p" where adult("p"."age")').fetchall()
for person in persons:
print(person)
But if I change adult
like this
def adult(age):
return 1 / 0
I will get sqlite3.OperationalError: user-defined function raised exception
.
In my project, it might be a huge amount of functions and I'd like to know - is there any way to know which function raised an exception? Or get ZeroDivisionError: division by zero
instead of this.