Thread: [Modeling-users] Strange date conversion in fetch qualifier
Status: Abandoned
Brought to you by:
sbigaret
From: <luk...@po...> - 2003-12-01 08:42:33
|
Hi I've got some problem with conditions that using dates. The following examlple shows this. ERD: MaWychowawce Klasa|<<--------------->|Nauczyciel -----| |------------ |attr: DataUrodzenia code: --------------------------------------------------------------------- warunek=3D'MaWychowawce.DataUrodzenia > '+str(DateTime(1970,1,1)) print warunek klasy=3DEC.fetch('Klasa',qualifier=3Dwarunek) --------------------------------------------------------------------- Printed qualifier look like this: MaWychowawce.DataUrodzenia > 1970-01-01 00:00:00.00 I've tried with: MaWychowawce.DataUrodzenia > '1970-01-01 00:00:00.00' bu= t it also didn't work Conditions on another attributes in 'Nauczyciel' works perfectly. error --------------------------------------- Couldn't evaluate expression SELECT DISTINCT t0.KLASA_ID, t0.NAZWA, t0.PROFIL, t0.WYCHOWAWCA_ID FROM KLASA t0 INNER JOIN NAUCZYCIEL t1 ON t0.WYCHOWAWCA_ID=3Dt1.NAUCZYCIEL_ID WHERE t1.DATA_URODZENIA > '1970'. Rea= son: libpq.OperationalError:ERROR: bad timestamp external representation '1970= ' Traceback (most recent call last): File "<stdin>", line 1, in ? File "Baza.py", line 45, in PobierzDane klasy=3DEC.fetch('Klasa',qualifier=3Dwarunek) File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EditingContext.py", line 1419,= in fetch return self.objectsWithFetchSpecification(fs) File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EditingContext.py", line 1302,= in objectsWithFetchSpecification objects=3Dself.parentObjectStore().objectsWithFetchSpecification(fs, = ec) File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\ObjectStoreCoordinator.py", li= ne 434, in objectsWithFetchSpecification return store.objectsWithFetchSpecification(aFetchSpecification, anEditingContext) File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\DatabaseContext.py", line 1817= , in objectsWithFetchSpecification anEditingContext) File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\DatabaseChannel.py", line 394,= in selectObjectsWithFetchSpecification entity) File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\DatabaseAdaptors\AbstractDBAPI2Adapto= rLa yer\AbstractDBAPI2AdaptorChannel.py", line 297, in selectAttributes raise GeneralAdaptorException, msg Modeling.Adaptor.GeneralAdaptorException: Couldn't evaluate expression SELECT DISTINCT t0.KLASA_ID, t0.NAZWA, t0.PROFIL, t0.WYCHOWAWCA_ID FROM KLASA t0 INNER JO IN NAUCZYCIEL t1 ON t0.WYCHOWAWCA_ID=3Dt1.NAUCZYCIEL_ID WHERE t1.DATA_URODZENIA > '1970'. Reason: libpq.OperationalError:ERROR: Bad timestamp external representation '1970' ------------------------------------ Is there any explanation? **************************** * =A3ukasz =A3akomy * luk...@po... **************************** |
From: Mario R. <ma...@ru...> - 2003-12-01 17:16:32
|
Hi Lukasz, not clear to me why you are concatenating the qualifer string the way you are. Using mx.DateTime for date fields, I can then do this in my qualifier to include a condition on the date value of the table column "createdate" for the fetch: q_part_whatever =3D ' ... ' q_date =3D 'createdate<"%s"' %(customObject.getCreatedate()) qualifier =3D ' AND '.join([ q_part_whatever, q_date]) This works. Not sure if there is a nicer way to do it though. This reminds me of a problem that I meant to report though: - I create an object with a date attribute (value for attribute set with mx.DateTime.now()), but without doing ec.saveChanges() - then if I fetch the object with ec.fetch('MyClass', qualifier =3D 'createdate=3D=3D"%s"' = %(myObject.getDateattr()) ) the fetch does not return the newly created object. This may be a bug, but I can confirm after playing with it further. Cheers, mario > Hi > > I've got some problem with conditions that using dates. The following > examlple shows this. > > ERD: > MaWychowawce > Klasa|<<--------------->|Nauczyciel > -----| |------------ > |attr: DataUrodzenia > > code: > --------------------------------------------------------------------- > warunek=3D'MaWychowawce.DataUrodzenia > '+str(DateTime(1970,1,1)) > print warunek > klasy=3DEC.fetch('Klasa',qualifier=3Dwarunek) > --------------------------------------------------------------------- > > Printed qualifier look like this: MaWychowawce.DataUrodzenia > =20 > 1970-01-01 > 00:00:00.00 > I've tried with: MaWychowawce.DataUrodzenia > '1970-01-01 00:00:00.00' = =20 > but > it also didn't work > Conditions on another attributes in 'Nauczyciel' works perfectly. > > error > --------------------------------------- > Couldn't evaluate expression SELECT DISTINCT t0.KLASA_ID, t0.NAZWA, > t0.PROFIL, t0.WYCHOWAWCA_ID FROM KLASA t0 INNER JOIN NAUCZYCIEL t1 ON > t0.WYCHOWAWCA_ID=3Dt1.NAUCZYCIEL_ID WHERE t1.DATA_URODZENIA > '1970'. =20= > Reason: > libpq.OperationalError:ERROR: bad timestamp external representation =20= > '1970' > > Traceback (most recent call last): > File "<stdin>", line 1, in ? > File "Baza.py", line 45, in PobierzDane > klasy=3DEC.fetch('Klasa',qualifier=3Dwarunek) > File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EditingContext.py", line =20= > 1419, in > fetch > return self.objectsWithFetchSpecification(fs) > File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EditingContext.py", line =20= > 1302, in > objectsWithFetchSpecification > objects=3Dself.parentObjectStore().objectsWithFetchSpecification(fs,= =20 > ec) > File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\ObjectStoreCoordinator.py", = =20 > line > 434, in objectsWithFetchSpecification > return store.objectsWithFetchSpecification(aFetchSpecification, > anEditingContext) > File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\DatabaseContext.py", line =20= > 1817, > in objectsWithFetchSpecification > anEditingContext) > File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\DatabaseChannel.py", line =20= > 394, in > selectObjectsWithFetchSpecification > entity) > File > = "C:\PROGRA~1\Zope2.6.2\bin\Modeling\DatabaseAdaptors\AbstractDBAPI2Adap=20= > torLa > yer\AbstractDBAPI2AdaptorChannel.py", line 297, in selectAttributes > raise GeneralAdaptorException, msg > Modeling.Adaptor.GeneralAdaptorException: Couldn't evaluate expression > SELECT DISTINCT t0.KLASA_ID, t0.NAZWA, t0.PROFIL, t0.WYCHOWAWCA_ID = FROM > KLASA t0 INNER JO > IN NAUCZYCIEL t1 ON t0.WYCHOWAWCA_ID=3Dt1.NAUCZYCIEL_ID WHERE > t1.DATA_URODZENIA > '1970'. Reason: libpq.OperationalError:ERROR: Bad > timestamp external representation '1970' > ------------------------------------ > > Is there any explanation? > > > **************************** > * =A3ukasz =A3akomy > * luk...@po... > **************************** > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Modeling-users mailing list > Mod...@li... > https://lists.sourceforge.net/lists/listinfo/modeling-users |
From: Sebastien B. <sbi...@us...> - 2003-12-02 17:16:14
|
Mario Ruggier <ma...@ru...> wrote: > [...] > This reminds me of a problem that I meant to report though: > - I create an object with a date attribute (value for attribute set with > mx.DateTime.now()), but without doing ec.saveChanges() > - then if I fetch the object with > ec.fetch('MyClass', > qualifier =3D 'createdate=3D=3D"%s"' %(myObject.getDateattr()= ) ) > the fetch does not return the newly created object. > This may be a bug, but I can confirm after playing with it further. This would help if you had a working test case, yes ;)=20 -- S=E9bastien. |
From: Mario R. <ma...@ru...> - 2003-12-04 05:59:33
|
> Mario Ruggier <ma...@ru...> wrote: >> [...] >> This reminds me of a problem that I meant to report though: >> - I create an object with a date attribute (value for attribute set >> with >> mx.DateTime.now()), but without doing ec.saveChanges() >> - then if I fetch the object with >> ec.fetch('MyClass', >> qualifier = 'createdate=="%s"' %(myObject.getDateattr()) ) >> the fetch does not return the newly created object. >> This may be a bug, but I can confirm after playing with it further. > > This would help if you had a working test case, yes ;) Fair enough ;) I have made a simple object with just a DateTime attribute, so in the pymodel it looks like : Entity('MyObj', properties=[ ADateTime('createdate',displayLabel='Date',isRequired=1), ] ) Then I made the following test that uses it: def test_0_FetchUnSavedDateTime(self): ec = EditingContext() o = MyObj() test_datetime = mx.DateTime.now() q = 'createdate=="%s"' %(test_datetime) o.setCreatedate(test_datetime) ec.insert(o) ec.saveChanges() print test_datetime, print ec.fetch('MyObj',qualifier=q)[0] o2 = MyObj() test_datetime2 = mx.DateTime.now() q2 = 'createdate=="%s"' %(test_datetime2) o2.setCreatedate(test_datetime2) ec.insert(o2) #ec.saveChanges() print test_datetime2, print ec.fetch('MyObj',qualifier=q2)[0] The first fetch is OK, the second is not. This is with SQLite and Modleing CVS. Cheers, mario |
From: Sebastien B. <sbi...@us...> - 2003-12-02 17:13:10
|
Hi, It was not clear to me why this was not working for you until I realized that the following statement: >>> ec.fetch('Writer', "birthday>1970-01-01 00:00:00.00") leads exactly to what you describe (libpq.OperationalError:ERROR: bad timestamp external representation '1970'). You've found a bug here, the QualifierPaser has not detected that the qualifier string you passed to it has a syntax error. Those two are correct, however, and should work as you expect: ec.fetch('Writer', 'birthday>"1970-01-01 00:00:00.00"') ec.fetch('Writer', 'birthday>"%s"' % str(DateTime(1970,01,01))) --and yes, this is a limitation of the parser, it only accepts double quo= tes around strings in qualifiers. Hopefully this solves the problem. If you still have difficulties, please tell. And thanks for reporting, I'll try to correct the bug in the parser f= or the next release. -- S=E9bastien. |