4

I'm a newbie with the POCO libraries. I need to read a DateTime field from an SQL Server (connected using ODBC Native Client). I have no problems reading strings or numbers, however Dates or Timestamps are giving me a difficult time... I'm not really sure if I should use a Poco::Timestamp to accomplish this. Apparently not.

#include <vector>
#include <iostream>

#define POCO_STATIC

#include <Poco/DateTime.h>
#include <Poco/DateTimeFormat.h>
#include <Poco/DateTimeFormatter.h>
#include <Poco/SharedPtr.h>
#include <Poco/Tuple.h>
#include <Poco/Data/SessionFactory.h>
#include <Poco/Data/Session.h>
#include <Poco/Data/ODBC/Connector.h>

using namespace Poco::Data;

int main() {
    typedef Poco::Tuple<std::string, Poco::Timestamp> Event;
    typedef std::vector<Event> Events;

    Poco::Data::ODBC::Connector::registerConnector();
    Session session("ODBC", "DSN=TestSNAC");

    Events events;

    Statement select(session);
    select << "select Name, StartDate from Events order by Name", into(events), now;

    for (Events::const_iterator it = events.begin(); it != events.end(); it++) {
        std::string date(Poco::DateTimeFormatter::format(it->get<1>(), "%b %e, %Y"));

        std::cout << " Name: " << it->get<0>() 
                  << " Start: " << date << std::endl;
    }

    return 0;
}

I'm getting the following error during compiling on line 27 (that is the one that starts with 'select << "select Name...):

error C2664: 'bool Poco::Data::AbstractExtractor::extract(size_t,Poco::Int8 &)' : cannot convert parameter 2 from 'Poco::Timestamp' to 'Poco::Int8 &'

Thank you so much...

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982

1 Answers1

3

Ok, it seems like currently I cannot read Dates or Times from a database. I found this comment at the Poco forum:

Support for Date, Time and DateTime is in SVN trunk and will be introduced in 1.5. release.

This link is included to get the latest release of the Extractor class: http://poco.svn.sourceforge.net/viewvc/poco/poco/trunk/Data/ODBC/src/Extractor.cpp?revision=1904&view=markup

In this class I can see references to two new classes Poco::Data:Date and Poco::Data::Time.

You can read the original post here: http://pocoproject.org/forum/viewtopic.php?f=12&t=5492&p=9272&hilit=data+datetime#p9272

I will get the latest release and try.

Thank you