Thread: Include a C++ variable in MySQL Query
hello, trying sql query in software, , need use user input (more precisely, input incomming network, thats half revelant)
have tried libmysqlclient , mysql++, first *close quote* + variable + *open quote* (got forum post) , seccond *close quote* << mysqlpp::quote_only << variable ); (got official doccumentation
both give me errors operator used.
here mysqlpp code right now.
sssql.cpp
sssql.hcode:bool sssql::checklogin(mysqlpp::string user, mysqlpp::string pass) { mysqlpp::string userinput = user; mysqlpp::string passcompare = pass; mysqlpp::connection conn(false); if (conn.connect(database, server, user, password)) { mysqlpp::query query = conn.query("select `password` `account` `user` = " << mysqlpp::quote_only << userinput); mysqlpp::storequeryresult res = query.store(); if (res == userinput) { std::cout << "login succesfull."; } else { std::cout << "login failled."; } } }
and build errors.code:#ifndef sssql_h #define sssql_h //#include "my_global.h" // include file first avoid problems #include "mysql.h" // mysql include file #define server "localhost" #define user "root" #define password "pc" #define database "pcnviolagame" #include <stdio.h> #include <string> #include <iostream> #include <mysql++.h> class sssql { public: sssql(); virtual ~sssql(); bool connectdb(); bool checklogin(mysqlpp::string, mysqlpp::string); protected: private: }; #endif // sssql_h
code:/home/pierrick/programming/netsandbox/sssql/sssql.cpp|78|warning: "/*" within comment [-wcomment]| /home/pierrick/programming/netsandbox/sssql/sssql.cpp||in member function ‘bool sssql::checklogin(mysqlpp::string, mysqlpp::string)’:| /home/pierrick/programming/netsandbox/sssql/sssql.cpp|24|error: no match ‘operator<<’ in ‘"select `password` `account` `user` = " << (mysqlpp::quote_only_type0)0u’| /home/pierrick/programming/netsandbox/sssql/sssql.cpp|24|note: candidates are:| /usr/include/mysql++/datetime.h|217|note: std::ostream& mysqlpp::operator<<(std::ostream&, const mysqlpp::datetime&)| /usr/include/mysql++/datetime.h|217|note: no known conversion argument 1 ‘const char [49]’ ‘std::ostream& {aka std::basic_ostream<char>&}’| /usr/include/mysql++/datetime.h|339|note: std::ostream& mysqlpp::operator<<(std::ostream&, const mysqlpp::date&)| /usr/include/mysql++/datetime.h|339|note: no known conversion argument 1 ‘const char [49]’ ‘std::ostream& {aka std::basic_ostream<char>&}’| /usr/include/mysql++/datetime.h|456|note: std::ostream& mysqlpp::operator<<(std::ostream&, const mysqlpp::time&)| /usr/include/mysql++/datetime.h|456|note: no known conversion argument 1 ‘const char [49]’ ‘std::ostream& {aka std::basic_ostream<char>&}’| /usr/include/mysql++/null.h|350|note: template<class type, class behavior> std::ostream& mysqlpp::operator<<(std::ostream&, const mysqlpp::null<type, behavior>&)| /usr/include/mysql++/tiny_int.h|303|note: template<class vt> std::ostream& mysqlpp::operator<<(std::ostream&, mysqlpp::tiny_int<vt>)| /usr/include/mysql++/mystring.h|657|note: std::ostream& mysqlpp::operator<<(std::ostream&, const mysqlpp::string&)| /usr/include/mysql++/mystring.h|657|note: no known conversion argument 1 ‘const char [49]’ ‘std::ostream& {aka std::basic_ostream<char>&}’| /usr/include/mysql++/mystring.h|696|note: char mysqlpp::operator<<(mysqlpp::string, char)| /usr/include/mysql++/mystring.h|696|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|696|note: char mysqlpp::operator<<(char, mysqlpp::string)| /usr/include/mysql++/mystring.h|696|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|697|note: int mysqlpp::operator<<(mysqlpp::string, int)| /usr/include/mysql++/mystring.h|697|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|697|note: int mysqlpp::operator<<(int, mysqlpp::string)| /usr/include/mysql++/mystring.h|697|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|698|note: short int mysqlpp::operator<<(mysqlpp::string, short int)| /usr/include/mysql++/mystring.h|698|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|698|note: short int mysqlpp::operator<<(short int, mysqlpp::string)| /usr/include/mysql++/mystring.h|698|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|699|note: long int mysqlpp::operator<<(mysqlpp::string, long int)| /usr/include/mysql++/mystring.h|699|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|699|note: long int mysqlpp::operator<<(long int, mysqlpp::string)| /usr/include/mysql++/mystring.h|699|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|701|note: unsigned char mysqlpp::operator<<(mysqlpp::string, unsigned char)| /usr/include/mysql++/mystring.h|701|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|701|note: unsigned char mysqlpp::operator<<(unsigned char, mysqlpp::string)| /usr/include/mysql++/mystring.h|701|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|702|note: unsigned int mysqlpp::operator<<(mysqlpp::string, unsigned int)| /usr/include/mysql++/mystring.h|702|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|702|note: unsigned int mysqlpp::operator<<(unsigned int, mysqlpp::string)| /usr/include/mysql++/mystring.h|702|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|703|note: short unsigned int mysqlpp::operator<<(mysqlpp::string, short unsigned int)| /usr/include/mysql++/mystring.h|703|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|703|note: short unsigned int mysqlpp::operator<<(short unsigned int, mysqlpp::string)| /usr/include/mysql++/mystring.h|703|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|704|note: long unsigned int mysqlpp::operator<<(mysqlpp::string, long unsigned int)| /usr/include/mysql++/mystring.h|704|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|704|note: long unsigned int mysqlpp::operator<<(long unsigned int, mysqlpp::string)| /usr/include/mysql++/mystring.h|704|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|711|note: mysqlpp::longlong mysqlpp::operator<<(mysqlpp::string, mysqlpp::longlong)| /usr/include/mysql++/mystring.h|711|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|711|note: mysqlpp::longlong mysqlpp::operator<<(mysqlpp::longlong, mysqlpp::string)| /usr/include/mysql++/mystring.h|711|note: no known conversion argument 2 ‘mysqlpp::quote_only_type0’ ‘mysqlpp::string’| /usr/include/mysql++/mystring.h|712|note: mysqlpp::ulonglong mysqlpp::operator<<(mysqlpp::string, mysqlpp::ulonglong)| /usr/include/mysql++/mystring.h|712|note: no known conversion argument 1 ‘const char [49]’ ‘mysqlpp::string’| ||more errors follow not being shown.| ||edit max errors limit in compiler options...| ||=== build finished: 50 errors, 1 warnings ===|
create string query , add variable strcat.
if variable number (int, float, double, etc.), convert text snprintf.
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Include a C++ variable in MySQL Query
Ubuntu
Comments
Post a Comment