mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
mysqlxx: development.
This commit is contained in:
parent
57d7e00376
commit
106f0589fa
@ -49,6 +49,8 @@ struct EscapeManipResult
|
||||
std::ostream & operator<< (double value) { return ostr << value; }
|
||||
std::ostream & operator<< (long long value) { return ostr << value; }
|
||||
std::ostream & operator<< (unsigned long long value) { return ostr << value; }
|
||||
std::ostream & operator<< (Date value) { return ostr << value; }
|
||||
std::ostream & operator<< (DateTime value) { return ostr << value; }
|
||||
|
||||
std::ostream & operator<< (const std::string & value)
|
||||
{
|
||||
@ -155,6 +157,8 @@ public:
|
||||
std::ostream & operator<< (double value) { return ostr << value; }
|
||||
std::ostream & operator<< (long long value) { return ostr << value; }
|
||||
std::ostream & operator<< (unsigned long long value) { return ostr << value; }
|
||||
std::ostream & operator<< (Date value) { return ostr << '\'' << value << '\''; }
|
||||
std::ostream & operator<< (DateTime value) { return ostr << '\'' << value << '\''; }
|
||||
|
||||
std::ostream & operator<< (const std::string & value)
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <mysqlxx/mysqlxx.h>
|
||||
#include <Yandex/time2str.h>
|
||||
#include <strconvert/escape_manip.h>
|
||||
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
@ -8,26 +9,49 @@ int main(int argc, char ** argv)
|
||||
mysqlxx::Connection connection("", "127.0.0.1", "root", "qwerty", 3306);
|
||||
std::cerr << "Connected." << std::endl;
|
||||
|
||||
mysqlxx::Query query = connection.query();
|
||||
query << "SELECT 1 x, '2010-01-01 01:01:01' d";
|
||||
mysqlxx::UseQueryResult result = query.use();
|
||||
std::cerr << "use() called." << std::endl;
|
||||
|
||||
while (mysqlxx::Row row = result.fetch())
|
||||
{
|
||||
std::cerr << "Fetched row." << std::endl;
|
||||
std::cerr << row[0] << ", " << row["x"] << std::endl;
|
||||
std::cerr << row[1] << ", " << row["d"]
|
||||
<< ", " << row[1].getDate()
|
||||
<< ", " << row[1].getDateTime()
|
||||
<< ", " << Yandex::Date2Str(row[1].getDate())
|
||||
<< ", " << Yandex::Time2Str(row[1].getDateTime())
|
||||
<< std::endl;
|
||||
mysqlxx::Query query = connection.query();
|
||||
query << "SELECT 1 x, '2010-01-01 01:01:01' d";
|
||||
mysqlxx::UseQueryResult result = query.use();
|
||||
std::cerr << "use() called." << std::endl;
|
||||
|
||||
time_t t1 = row[0];
|
||||
time_t t2 = row[1];
|
||||
std::cerr << t1 << ", " << mysqlxx::DateTime(t1) << std::endl;
|
||||
std::cerr << t2 << ", " << mysqlxx::DateTime(t2) << std::endl;
|
||||
while (mysqlxx::Row row = result.fetch())
|
||||
{
|
||||
std::cerr << "Fetched row." << std::endl;
|
||||
std::cerr << row[0] << ", " << row["x"] << std::endl;
|
||||
std::cerr << row[1] << ", " << row["d"]
|
||||
<< ", " << row[1].getDate()
|
||||
<< ", " << row[1].getDateTime()
|
||||
<< ", " << Yandex::Date2Str(row[1].getDate())
|
||||
<< ", " << Yandex::Time2Str(row[1].getDateTime())
|
||||
<< std::endl
|
||||
<< mysqlxx::escape << row[1].getDate() << ", " << mysqlxx::escape << row[1].getDateTime() << std::endl
|
||||
<< mysqlxx::quote << row[1].getDate() << ", " << mysqlxx::quote << row[1].getDateTime() << std::endl
|
||||
<< strconvert::escape_file << row[1].getDate() << ", " << strconvert::escape_file << row[1].getDateTime() << std::endl
|
||||
<< strconvert::quote_fast << row[1].getDate() << ", " << strconvert::quote_fast << row[1].getDateTime() << std::endl
|
||||
;
|
||||
|
||||
time_t t1 = row[0];
|
||||
time_t t2 = row[1];
|
||||
std::cerr << t1 << ", " << mysqlxx::DateTime(t1) << std::endl;
|
||||
std::cerr << t2 << ", " << mysqlxx::DateTime(t2) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
mysqlxx::Query query = connection.query();
|
||||
query << "SELECT 1234567890 abc, 12345.67890 def UNION ALL SELECT 9876543210, 98765.43210";
|
||||
mysqlxx::StoreQueryResult result = query.store();
|
||||
|
||||
std::cerr << result.at(0)["abc"].getUInt() << ", " << result.at(0)["def"].getDouble() << std::endl
|
||||
<< result.at(1)["abc"].getUInt() << ", " << result.at(1)["def"].getDouble() << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
mysqlxx::UseQueryResult result = connection.query("SELECT 'abc\\\\def' x").use();
|
||||
mysqlxx::Row row = result.fetch();
|
||||
std::cerr << row << std::endl;
|
||||
std::cerr << mysqlxx::escape << row << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user