mshepanski / quince

QUeries IN C++ Expressions
Boost Software License 1.0
31 stars 18 forks source link

Timestamps fail with binary format error when used in where clause with Postgresql #4

Closed ja11sop closed 9 years ago

ja11sop commented 9 years ago

NOTE: I am using the Postgresql backend.

Given a table, patients with columns, id (serial), forename (string), surname (string) and date_of_birth (boost::posix_time::ptime):

struct patient
{
    quince::serial                  id;                  // primary key
    std::string                     forename;
    std::string                     surname;
    boost::posix_time::ptime        date_of_birth;
};
QUINCE_MAP_CLASS(patient, (id)(forename)(surname)(date_of_birth))

The following query compiles:

    // Forename == std::string
    // Surname == std::string
    // Timestamp == boost::posix_time::ptime

        quince::query<patient>
            PatientQuery
                = Patients_
                    .where(     Patients_->forename      == Forename
                            &&  Patients_->surname       == Surname
                            &&  Patients_->date_of_birth == Timestamp );

    auto Patient = PatientQuery.begin();

but fails at runtime with error:

  what():  dbms-detected error: ERROR:  incorrect binary data format in bind parameter 3
 (most recent SQL command was `DECLARE cursor_2 CURSOR WITH HOLD FOR SELECT "patients"."id" AS r$14, "patients"."forename" AS r$15, "patients"."surname" AS r$16, CAST ("patients"."date_of_birth" AS text) AS r$17 FROM "patients" WHERE (("patients"."forename" = $1) AND ("patients"."surname" = $2) AND ("patients"."date_of_birth" = $3)')
Aborted

Note the error is referring to the date_of_birth value.

A semi-equivalent manual query direct to the DB works fine, for example:

SELECT "patients"."id", 
       "patients"."forename",
       "patients"."surname", 
       CAST ("patients"."date_of_birth" AS text)
FROM "patients" 
WHERE ( ( ("patients"."forename" = 'FirstName') 
    AND ("patients"."surname" = 'LastName') ) 
    AND ("patients"."date_of_birth" = '1990-11-24 00:00:00' ) )
mshepanski commented 9 years ago

I have made a fix on the "dev" branch of quince and quince_postgresql.

@ja11sop, could you please check it out and see whether it does what you need? If it does, I will then merge it to main.

ja11sop commented 9 years ago

I just tried this and it appears to work as expected. I think the merge should be fine. Many thanks!

mshepanski commented 9 years ago

Merged to main. Thanks for the bug report.