Pierrick584
March 17th, 2012, 04:27 PM
Hello, i am trying to do a SQL query in my software, and i need it to use user input (more precisely, input incomming from network, but thats half revelant)
i have tried with libmysqlclient and mysql++, the first with the *close quote* + variable + *open quote* (got that from a forum post) and the seccond *close quote* << mysqlpp::quote_only << variable ); (got that from the official doccumentation
Both give me errors about the operator used.
Here is my mysqlpp code right now.
sssql.cpp
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` FROM `account` WHERE `user` = " << mysqlpp::quote_only << userinput);
mysqlpp::StoreQueryResult res = query.store();
if (res == userinput)
{
std::cout << "Login Succesfull.";
}
else
{
std::cout << "Login Failled.";
}
}
}
sssql.h
#ifndef SSSQL_H
#define SSSQL_H
//#include "my_global.h" // Include this file first to 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
and the build errors.
/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 for ‘operator<<’ in ‘"SELECT `password` FROM `account` WHERE `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 for argument 1 from ‘const char [49]’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘mysqlpp::String’|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 1 warnings ===|
i have tried with libmysqlclient and mysql++, the first with the *close quote* + variable + *open quote* (got that from a forum post) and the seccond *close quote* << mysqlpp::quote_only << variable ); (got that from the official doccumentation
Both give me errors about the operator used.
Here is my mysqlpp code right now.
sssql.cpp
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` FROM `account` WHERE `user` = " << mysqlpp::quote_only << userinput);
mysqlpp::StoreQueryResult res = query.store();
if (res == userinput)
{
std::cout << "Login Succesfull.";
}
else
{
std::cout << "Login Failled.";
}
}
}
sssql.h
#ifndef SSSQL_H
#define SSSQL_H
//#include "my_global.h" // Include this file first to 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
and the build errors.
/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 for ‘operator<<’ in ‘"SELECT `password` FROM `account` WHERE `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 for argument 1 from ‘const char [49]’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘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 for argument 2 from ‘mysqlpp::quote_only_type0’ to ‘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 for argument 1 from ‘const char [49]’ to ‘mysqlpp::String’|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 1 warnings ===|