Skip to content

Poco::Data::RowFormatter generate exception if the first column of first row is null #1242

@victor-tsang

Description

@victor-tsang

Poco::Data::RowFormatter generate exception if the first column of first row is null.

Can reproduce the error using the following code:

//
//
// To build: clang++ -I/usr/local/include -L/usr/local/lib  -o test main.cpp -lPocoFoundation -lPocoData -lPocoDataSQLite
//
//


#include<iostream>

#include<Poco/Data/Session.h>
#include<Poco/Data/SQLite/Connector.h>
#include<Poco/Data/RecordSet.h>
#include<Poco/Data/Statement.h>
#include<Poco/Exception.h>

using Poco::Data::Keywords::now;

int main()
{
  int stage=0;

  try
  {
    Poco::Data::SQLite::Connector::registerConnector();
    Poco::Data::Session session(Poco::Data::SQLite::Connector::KEY,":memory:");

    stage=1;
    session<<"create table Abc( a text, b text);", now;

    stage=2;
    //session<<"insert into Abc(a,b) values('Hello','world');",now;
    session<<"insert into Abc(a,b) values(null,'world');",now;
    session<<"insert into Abc(a,b) values('Hello','world');",now;

    stage=3;
    Poco::Data::Statement statement(session);

    stage=4;
    statement<<"select a,b from Abc;",now;

    stage=5;
    Poco::Data::RecordSet recordSet(statement);

    stage=6;
    // Will generate exception if the first column of first row is null.
    std::cout<<recordSet;
    // Will see from the console:
    // Exception at stage 6:
    // Illegal state: All values are empty.
  }
  catch(Poco::Exception &e)
  {
    std::cout<<"Exception at stage "<<stage<<":"<<std::ends;
    std::cout<<e.displayText()<<std::ends;
  }

  return 0;
}


Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions