mysqlxx: development.

This commit is contained in:
Alexey Milovidov 2011-03-16 14:47:51 +00:00
parent 57d7e00376
commit 106f0589fa
2 changed files with 46 additions and 18 deletions

View File

@ -49,6 +49,8 @@ struct EscapeManipResult
std::ostream & operator<< (double value) { return ostr << value; } std::ostream & operator<< (double value) { return ostr << value; }
std::ostream & operator<< (long long 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<< (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) std::ostream & operator<< (const std::string & value)
{ {
@ -155,6 +157,8 @@ public:
std::ostream & operator<< (double value) { return ostr << value; } std::ostream & operator<< (double value) { return ostr << value; }
std::ostream & operator<< (long long 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<< (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) std::ostream & operator<< (const std::string & value)
{ {

View File

@ -1,6 +1,7 @@
#include <iostream> #include <iostream>
#include <mysqlxx/mysqlxx.h> #include <mysqlxx/mysqlxx.h>
#include <Yandex/time2str.h> #include <Yandex/time2str.h>
#include <strconvert/escape_manip.h>
int main(int argc, char ** argv) int main(int argc, char ** argv)
@ -8,6 +9,7 @@ int main(int argc, char ** argv)
mysqlxx::Connection connection("", "127.0.0.1", "root", "qwerty", 3306); mysqlxx::Connection connection("", "127.0.0.1", "root", "qwerty", 3306);
std::cerr << "Connected." << std::endl; std::cerr << "Connected." << std::endl;
{
mysqlxx::Query query = connection.query(); mysqlxx::Query query = connection.query();
query << "SELECT 1 x, '2010-01-01 01:01:01' d"; query << "SELECT 1 x, '2010-01-01 01:01:01' d";
mysqlxx::UseQueryResult result = query.use(); mysqlxx::UseQueryResult result = query.use();
@ -22,13 +24,35 @@ int main(int argc, char ** argv)
<< ", " << row[1].getDateTime() << ", " << row[1].getDateTime()
<< ", " << Yandex::Date2Str(row[1].getDate()) << ", " << Yandex::Date2Str(row[1].getDate())
<< ", " << Yandex::Time2Str(row[1].getDateTime()) << ", " << Yandex::Time2Str(row[1].getDateTime())
<< std::endl; << 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 t1 = row[0];
time_t t2 = row[1]; time_t t2 = row[1];
std::cerr << t1 << ", " << mysqlxx::DateTime(t1) << std::endl; std::cerr << t1 << ", " << mysqlxx::DateTime(t1) << std::endl;
std::cerr << t2 << ", " << mysqlxx::DateTime(t2) << 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; return 0;
} }