Overview
Features
Download
Documentation
Community
Add-Ons & Services

Exception issue in MySQL string Extractor::extract

Please post support and help requests here.

Exception issue in MySQL string Extractor::extract

Postby gmorehead » 24 Jun 2013, 22:41

I'm having a problem extracting strings from a MySQL database.

I'm getting a MySQLException("Extractor: not a string"); with the follwing code:

Code: Select all
string resource;
*_ses << "SELECT (resource) FROM `cps`", into(resource), now;


As a hack/test I commented out the test from Data/MySQL/src/Extractor.cpp

Code: Select all
bool Extractor::extract(std::size_t pos, std::string& val)
{
   if (_metadata.columnsReturned() <= pos)
        throw MySQLException("Extractor: attempt to extract more paremeters, than query result contain");

    if (_metadata.isNull(static_cast<Poco::UInt32>(pos)))
        return false;

//  Hack/Test, getting an unexpected exception.
//   if (_metadata.metaColumn(static_cast<Poco::UInt32>(pos)).type() != Poco::Data::MetaColumn::FDT_STRING)
//      throw MySQLException("Extractor: not a string");

   val.assign(_metadata.rawData(pos), _metadata.length(pos));
   return true;
}


And my code works.

The test appears to be valid, however the meta type does not appear to be correct.

Has anybody else seen this? Am I doing something wrong?

Thanks.
gmorehead
 
Posts: 8
Joined: 08 Jun 2012, 17:04

Re: Exception issue in MySQL string Extractor::extract

Postby alex » 25 Jun 2013, 04:44

Well, the type of the column is whatever mysql_fetch_fields() returns for it; for string it would have to be MYSQL_TYPE_STRING or MYSQL_TYPE_VAR_STRING. Not sure what version you are using, but I don't think that part was changed recently.
alex
 
Posts: 1145
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Exception issue in MySQL string Extractor::extract

Postby gmorehead » 25 Jun 2013, 14:31

I'm using Poco version 1.4.6 and MySQL version 5.5.31

MySQL workbench shows the "resource" column to be of type "text". I would assume this would return a field type of MYSQL_TYPE_VAR_STRING or MYSQL_TYPE_STRING, but it's not?
gmorehead
 
Posts: 8
Joined: 08 Jun 2012, 17:04

Re: Exception issue in MySQL string Extractor::extract

Postby alex » 25 Jun 2013, 14:45

I suspect it is MYSQL_TYPE_VARCHAR, which is mapped to FDT_UNKNOWN, in 1.4.6 directly, in 1.5.x indirectly. I think it's a bug.
alex
 
Posts: 1145
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Exception issue in MySQL string Extractor::extract

Postby gmorehead » 25 Jun 2013, 15:12

Thanks, I'll verify your assumption and let you know.
gmorehead
 
Posts: 8
Joined: 08 Jun 2012, 17:04

Re: Exception issue in MySQL string Extractor::extract

Postby gmorehead » 25 Jun 2013, 21:27

The following code:
Code: Select all
string resource;
*_ses << "SELECT (resource) FROM `cps`", into(resource), now;

Is generating a MySQL field type of MYSQL_TYPE_BLOB any idea why?
gmorehead
 
Posts: 8
Joined: 08 Jun 2012, 17:04

Re: Exception issue in MySQL string Extractor::extract

Postby alex » 25 Jun 2013, 22:31

Because that's what the mysql_fetch_fields() API call returns. It would be a good question to post on a MySQL forum.
alex
 
Posts: 1145
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Exception issue in MySQL string Extractor::extract

Postby gmorehead » 26 Jun 2013, 15:30

Is there an example from somebody who has used this method for retrieving string data from MySQL? Or am I the only one who has attempted to use this code?
gmorehead
 
Posts: 8
Joined: 08 Jun 2012, 17:04

Re: Exception issue in MySQL string Extractor::extract

Postby alex » 26 Jun 2013, 16:30

Actually, there is a pending pull request that fixes this problem. I did not have time to go through all the details of the request for 1.5.2 and I don't know if Günter plans to incorporate it in 1.4.x which is at the end of life.
alex
 
Posts: 1145
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Exception issue in MySQL string Extractor::extract

Postby gmorehead » 26 Jun 2013, 16:50

Awesome. We will add it to our install for the time being.
Last edited by gmorehead on 26 Jun 2013, 17:23, edited 1 time in total.
gmorehead
 
Posts: 8
Joined: 08 Jun 2012, 17:04

Next

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest