ClickHouse/libs/libmysqlxx/include/mysqlxx/Row.h

70 lines
1.2 KiB
C
Raw Normal View History

2011-03-03 19:57:34 +00:00
#ifndef MYSQLXX_ROW_H
#define MYSQLXX_ROW_H
#include <mysqlxx/Types.h>
#include <mysqlxx/String.h>
#include <mysqlxx/ResultBase.h>
#include <iostream>
namespace mysqlxx
{
class ResultBase;
class Row
{
2011-03-05 16:56:30 +00:00
private:
/** @brief Pointer to bool data member, for use by safe bool conversion operator.
* @see http://www.artima.com/cppsource/safebool.html
* Взято из mysql++.
*/
typedef MYSQL_ROW Row::*private_bool_type;
2011-03-03 19:57:34 +00:00
public:
Row() : row(NULL), res(NULL)
{
}
Row(MYSQL_ROW row_, ResultBase * res_)
: row(row_), res(res_)
{
lengths = mysql_fetch_lengths(&res->getRes());
}
2011-03-04 20:58:19 +00:00
String operator[] (int n) const
2011-03-03 19:57:34 +00:00
{
std::cerr << lengths[0] << std::endl;
return String(row[n], lengths[n]);
}
2011-03-04 20:58:19 +00:00
String operator[] (const char * name) const
2011-03-03 19:57:34 +00:00
{
std::cerr << "???" << std::endl;
unsigned n = res->getNumFields();
MYSQL_FIELDS fields = res->getFields();
for (unsigned i = 0; i < n; ++i)
if (!strcmp(name, fields[i].name))
return operator[](i);
throw Exception(std::string("Unknown column ") + name);
}
2011-03-04 20:58:19 +00:00
String at(size_t n) const
2011-03-03 19:57:34 +00:00
{
return operator[](n);
}
2011-03-05 16:56:30 +00:00
operator private_bool_type() const { return row == NULL ? NULL : &Row::row; }
2011-03-03 19:57:34 +00:00
private:
MYSQL_ROW row;
MYSQL_LENGTHS lengths;
ResultBase * res;
};
}
#endif