Exemplo n.º 1
0
bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& 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;

	if (_metadata.metaColumn(static_cast<Poco::UInt32>(pos)).type() != Poco::Data::MetaColumn::FDT_BLOB)
		throw MySQLException("Extractor: not a blob");

  unsigned long length= 0;
  MYSQL_BIND bind = { 0 };
  bind.buffer= 0;
  bind.buffer_length= 0;
  bind.length= &length;
  if ( ! _stmt.fetchColumn(pos, &bind) )
    return false;

  std::vector<char> data(length);
  bind.buffer = &data[0];
  bind.buffer_length= length;
  if ( ! _stmt.fetchColumn(pos, &bind) )
    return false;

  val.assignRaw(&data[0], length);
	return true;
}
bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& 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;
	
	if (_metadata.metaColumn(static_cast<Poco::UInt32>(pos)).type() != Poco::Data::MetaColumn::FDT_BLOB)
		throw MySQLException("Extractor: not a blob");
	
	val.assignRaw(_metadata.rawData(pos), _metadata.length(pos));
	return true;
}