Question: how to use kernelopts('assertlevel'=2): in a program that uses Database[SQLite]?

This is an issue I had for long time. Though to ask about it.

Any one who used Database[SQLite] in Maple probably know this.  I'd like to do kernelopts('assertlevel'=2): but this does not work when using Database[SQLite] as it raises assertion failed, due to the way data is read from database and converted to Maple variable.

It happens at the statement 

         variable_to_read := Database[SQLite]:-FetchAll(stmt); 

For an example, the table I have in sql, has many fields. some are strings and some are integers. Lets say I want to read field called run_it corresponding to rowid I enter. So I do this in Maple

local run_it::integer;
.....
counter :=1;

stmt := Database[SQLite]:-Prepare(conn, cat("SELECT run_it FROM PROBLEMS WHERE rowid=",convert(counter,string),";"));    

run_it := Database[SQLite]:-FetchAll(stmt); 

The assetion error happens at the second call above. 

Error, (in dsolver_test:-MAIN_STEP) assertion failed in assignment, expected integer, got Matrix(1, 1, {(1, 1) = 1}, order = C_order, attributes = [source_rtable = (Array(1..1, {(1) = 1}, order = C_order))]) 
 

Once I remove kernelopts('assertlevel'=2): everything works fine with no problems at all. So I been running my program for more than a year now without the assert set.

Since I have hundreds of  such calls, and I do not think try/catch will work here, any one knows of a way to handle this, so I can turn on assertlevel to help catch any other problems some where else in the program, and still use SQLite ?

I could make an example if needed. I would need to create new database file and so on. This will take time.

Maple 2020.2

ps. Database[SQLite] works very well and very fast. I am surprised how fast it reads the data. few thousands records, each is 25 fields, and it does it in few seconds. Good implementation.

Edit

I found that by removing all the type specification on my Maple variables, that I read the SQL data into using FetchAll(stmt);  it now works!

So I am able to now use kernelopts('assertlevel'=2):

So intead of doing  

local local run_it::integer;  and then call SQL, I just now do  local run_it; with no type.  I had to remove the type on many such variables I had.  Now no assertion error any more during the SQL calls.

This works for me for now. I should have done this long time ago, I just did not think about it before. I would have liked to keep the type here.

Edit: I see answer below that allows me to do this by changing assert level just for the call to SQL which is good solution.

 

 

 

Please Wait...