[web2py] Re: problem with request.date and db.table.update_or_insert
Is this a field to update the date when an entry is updated/inserted? Can you post your code? On Dec 15, 5:00 am, Daniel Aguayo Catalán wrote: > Hi, > i have a fieldtype 'date' in a table that I cannot create from using > request.now.date() in the db.table.update_or_insert statement (even if a > change the fieldtype and date value to string)Traceback(most recent call > last):File"/home/danto/web2py/gluon/restricted.py",line204,inrestrictedexecccodeinenvironment > > File"/home/danto/web2py/applications/votomercado/controllers/info.py",line428,inFile"/home/danto/web2py/gluon/globals.py",line162,inself._caller=lambdaf:f()File"/home/danto/web2py/applications/votomercado/controllers/info.py",line176,inhistorico_brand > fecha=date File"/home/danto/web2py/gluon/dal.py",line5617,inupdate_or_insert > record=self(**values)File"/home/danto/web2py/gluon/dal.py",line5502,in__call__return > > self._db(query).select(limitby=(0,1),for_update=for_update).first()File"/home/danto/web2py/gluon/dal.py",line6330,inselectreturn > > self.db._adapter.select(self.query,fields,attributes)File"/home/danto/web2py/gluon/dal.py",line1282,inselect > > rows=response(sql)File"/home/danto/web2py/gluon/dal.py",line1272,inresponseself.execute(sql)File"/home/danto/web2py/gluon/dal.py",line1359,inexecutereturn > self.log_execute(*a, > **b)File"/home/danto/web2py/gluon/dal.py",line1353,inlog_execute > ret=self.cursor.execute(*a, > **b)File"/usr/lib/python2.7/site-packages/pysqlite2/dbapi2.py",line66,inconvert_timestamp > datepart,timepart=val.split(" ")ValueError:need more than1value to unpack > what am I doing wrong? > kind regards
[web2py] Re: problem with request.date and db.table.update_or_insert
> datepart,timepart=val.split(" ")ValueError:need more than1value to unpack It looks like convert_timestamp() in pysqlite2.dbapi2 is expecting a date+time object and receives a date, isn't it?
[web2py] Re: problem with request.date and db.table.update_or_insert
request.date.now() works well in my system (Python 2.6.5, web2py 1.99.3, Linux) Would you post part of the model and controller to see what it does? On 14 dic, 19:43, Daniel Aguayo Catalán wrote: > Alan Etkin escribi :>> datepart,timepart=val.split(" ")ValueError:need more > than1value to unpack > > It looks like convert_timestamp() in pysqlite2.dbapi2 is expecting a > > date+time object and receives a date, isn't it? > > Hi, I forgot to say that the problem exists even if I try to insert a > request.now value. > > If I try to insert a datetime.datetime.now() object the same problem > doesn't show, but then the 'update_or_insert' function see it as a new > entry, doing always an insert
[web2py] Re: problem with request.date and db.table.update_or_insert
> I think you mean request.now.date() (request.date doesn't exist in my Right > dbi('historia', > ... > Field('fecha', 'string') > ) That should be a 'date' field for web2py to handle date information properly. > date = str(datetime.datetime.now()) #NO error1, but doesn't update I cannot reproduce the error in my system (it performs update or insert with date only values, but I am using the "date" field type) A (poor yet somewhat simple to implement) workaround would be storing datetime objects instead of date but filtering just the y/m/d values (with computed fields) so comparisons would match with day precision.
Re: [web2py] Re: problem with request.date and db.table.update_or_insert
Alan Etkin escribió: datepart,timepart=val.split(" ")ValueError:need more than1value to unpack It looks like convert_timestamp() in pysqlite2.dbapi2 is expecting a date+time object and receives a date, isn't it? Hi, I forgot to say that the problem exists even if I try to insert a request.now value. If I try to insert a datetime.datetime.now() object the same problem doesn't show, but then the 'update_or_insert' function see it as a new entry, doing always an insert
Re: [web2py] Re: problem with request.date and db.table.update_or_insert
Daniel Aguayo Catalán escribió: Alan Etkin escribió: datepart,timepart=val.split(" ")ValueError:need more than1value to unpack It looks like convert_timestamp() in pysqlite2.dbapi2 is expecting a date+time object and receives a date, isn't it? Hi, I forgot to say that the problem exists even if I try to insert a request.now value. If I try to insert a datetime.datetime.now() object the same problem doesn't show, but then the 'update_or_insert' function see it as a new entry, doing always an insert in fact, seems that, as you said, convert_timestamp() is always expecting date+time object, not just one of them and "update_or_insert" method uses that for knowing when to update or insert. seems that I can't rely on this method for update_or_insert only based on the date and need to try-except a db.table.update, or there's another way?
Re: [web2py] Re: problem with request.date and db.table.update_or_insert
Alan Etkin escribió: request.date.now() works well in my system (Python 2.6.5, web2py 1.99.3, Linux) I think you mean request.now.date() (request.date doesn't exist in my system, web2py 1.99.3 with python 2.7.2 on gnu/linux too) Would you post part of the model and controller to see what it does? of course: MODEL: dbi = db_informes.define_table dbi('historia', Field('brand_id', 'integer'), Field('brand_name'), Field('positivos', 'integer'), Field('negativos', 'integer'), Field('nulos', 'integer'), Field('total_votos', compute = lambda v: v['positivos'] + v['negativos'] + v['nulos'] ), Field('fecha', 'string') ) FUNCTION def historico_brand(): import datetime #date = datetime.datetime.now() #error1: "need more than 1 value to unpack" #date = request.now.date() #error1: "need more than 1 value to unpack" #date = datetime.datetime.now().date() #error1: "need more than 1 value to unpack" date = str(datetime.datetime.now()) #NO error1, but doesn't update (always insert)' for b in db(db.brand).select(db.brand.id, db.brand.name): data = db((db.brand.id == b.id) & (db.address.brand == db.brand.id) & (db.address.id == db.rec.address) & (db.rec.id == db.vote_attribute.rec) ).select() t = f = n = 0 for d in data: if d.vote_attribute.vote == True: t += 1 elif d.vote_attribute.vote == False: f += 1 else: n += 1 db_informes.historia.update_or_insert( brand_id = b.id, brand_name = b.name, positivos = t, negativos = f, nulos = n, fecha = date ) return True On 14 dic, 19:43, Daniel Aguayo Catalán wrote: Alan Etkin escribi :>> datepart,timepart=val.split(" ")ValueError:need more than1value to unpack It looks like convert_timestamp() in pysqlite2.dbapi2 is expecting a date+time object and receives a date, isn't it? Hi, I forgot to say that the problem exists even if I try to insert a request.now value. If I try to insert a datetime.datetime.now() object the same problem doesn't show, but then the 'update_or_insert' function see it as a new entry, doing always an insert
Re: [web2py] Re: problem with request.date and db.table.update_or_insert
Alan Etkin escribió: dbi('historia', ... Field('fecha', 'string') ) That should be a 'date' field for web2py to handle date information properly. I changed that later. I was using the 'date' type originally when the issue came up. date = str(datetime.datetime.now()) #NO error1, but doesn't update I cannot reproduce the error in my system (it performs update or insert with date only values, but I am using the "date" field type) A (poor yet somewhat simple to implement) workaround would be storing datetime objects instead of date but filtering just the y/m/d values (with computed fields) so comparisons would match with day precision. I droped and rebuilded the database (well, web2py). now it works. Thank you very much for you time :)