File "C:\web2py\gluon\packages\dal\pydal\adapters\base.py", line 412, in execute
rv = self.cursor.execute(command, *args[1:], **kwargs)
OperationalError: parser stack overflow
Function argument list
(self=<pydal.adapters.sqlite.SQLite object>, *args=('SELECT "WCEL"."id", "WCEL."it.."."item140" = \'0\')) LIMIT 1 OFFSET 0;',), **kwargs={})
Hi guys,I am trying to write a row with 140 fields into the database, with the following script:controller:WCEL={item1:value1,item2:value2,.......item140:value140}db.WCEL.update_or_insert(**(WCEL))model:db = DAL('sqlite://storage.sqlite1')db.define_table('WCEL',Field('item1'),Field('item2),......Field('item139'),Field('item140'))but I am getting the following error:<class 'sqlite3.OperationalError'> parser stack overflow
File "C:\web2py\gluon\packages\dal\pydal\adapters\base.py", line 412, in execute
rv = self.cursor.execute(command, *args[1:], **kwargs)
OperationalError: parser stack overflowFunction argument list
(self=<pydal.adapters.sqlite.SQLite object>, *args=('SELECT "WCEL"."id", "WCEL."it.."."item140" = \'0\')) LIMIT 1 OFFSET 0;',), **kwargs={})
I tried the same set of 140 fields by importing from a csv, it was successful.db.WCEL.import_from_csv_file(open('WCEL.csv', 'r'))
(db.mytable.field1 == 'value 1') & (db.mytable.field2 == 'value 2') & ... & (db.mytable.field140 == 'value 140')
(((mytable.field1 = 'value 1') AND (mytable.field2 = 'value 2')) AND (mytable.field3 = 'value 3'))
record = db(manually_generated_raw_SQL).select(db.WCEL.id, limitby=(0, 1)).first()
if not record:
db.WCEL.insert(**WCEL)
With 140 fields, you get queries nested 140 levels deep in parentheses, which SQLite cannot handle. Of course, all of the nested parentheses are not really necessary, so if you want to first check for the existence of a record, one option is to avoid using .update_and_insert() and instead write your own code to check for record existence. You code would have to manually construct the "WHERE" clause of the SQL query. The logic then might look something like:
record = db(manually_generated_raw_SQL).select(db.WCEL.id, limitby=(0, 1)).first()
if not record:
db.WCEL.insert(**WCEL)
str(reduce(lambda a, b: a & b, [db.WCEL[f] == v for f, v in iteritems(WCEL)])).replace('(', '').replace(')', '')