I want to create a little client for Evernote.
I got the consumer key and secret from the site and wrote this code:
struct user_data {
std::string login;
std::string pass;
};
struct evernote_data {
user_data user;
std::string consumer_key;
std::string consumer_secret;
};
struct service_data
{
std::string host;
std::string path;
int port;
};
void connect(const evernote_data& account, const service_data& service)
{
try
{
boost::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory());
boost::shared_ptr<TSSLSocket> sslSocket=sslSocketFactory->createSocket(service.host, service.port);
boost::shared_ptr<TBufferedTransport> bufferedTransport(new TBufferedTransport(sslSocket));
boost::shared_ptr<TTransport> http_client(new THttpClient(bufferedTransport, service.host, service.path));
http_client->open();
boost::shared_ptr<TBinaryProtocol> user_store_protocol(new TBinaryProtocol(http_client));
evernote::edam::UserStoreClient user_store(user_store_protocol, user_store_protocol);
evernote::edam::AuthenticationResult auth_result;
user_store.authenticate(auth_result, account.user.login, account.user.pass, account.consumer_key, account.consumer_secret);
cout << "Some info: " ;
cout << auth_result.user.username << endl << auth_result.user.name << endl << auth_result.user.email << endl;
}
catch(evernote::edam::EDAMUserException& error)
{
cout << "catch EDAMUserException" << endl;
cout << "ErrorCode: " << error.errorCode << endl;
cout << "What: " << error.what() << endl;
cout << "Parameter: " << error.parameter << endl;
}
catch(::apache::thrift::TException& error)
{
cout << "catch thrift::TException " << endl;
cout << "What: " << error.what() << endl;
}
catch(...)
{
cout << "boom !!!" << endl;
}
}
int main()
{
const user_data user = { "**Login**", "**password**"};
const evernote_data account = { user, "***Key***", "**Secret**" };
const service_data service = {"sandbox.evernote.com", "/edam/user", 443 };
connect(account, service);
std::cout << "Exit" << std::endl;
cin.get();
return 0;
}
Program output:
Catch EDAMUserException
ErrorCode: 8
What: Default TException.
Parameter: consumerKey
And always catch error about wrong consumer key. What am I doing wrong?
Third party developers can't use UserStore#authenticate since last November.
http://dev.evernote.com/documentation/reference/UserStore.html#Fn_UserStore_authenticate
Please use OAuth instead.
http://dev.evernote.com/start/core/authentication.php
Related
#define MYSQLPP_MYSQL_HEADERS_BURIED
#include <mysql++/mysql++.h>
#include <iostream>
#include "/home/sulli313/Project4/Film.h"
void Film::showList(){
std::cout << "\n-----------------------------------" << std::endl;
std::cout << " Query Application " << std::endl;
std::cout << "-----------------------------------" << std::endl;
std::cout << " 1 All letter name actors" << std::endl;
std::cout << " 2 First # PG-13 and Above" << std::endl;
std::cout << " 3 All active/inactive users by store" << std::endl;
std::cout << " 4 Actor Movie titles and ids" << std::endl;
std::cout << "-1 Exit" << std::endl;
std::cout << "-----------------------------------" << std::endl;
std::cout << ">> Enter your choice:" << std::endl;
}
void Film::showOne(){
mysqlpp::Connection myDB("cse278F2022", "localhost", "cse278F2022",
"raspberrySeltzer");
// Create a query
mysqlpp::Query query = myDB.query();
std::cout << "Please enter a Letter A-Z!" << std::endl;
std::string letter;
std::cin >> letter;
///////////////////////////////////Do this part/////////////////////////////////////////////
//if(letter)
query << "SELECT first_name, last_name "
<< "FROM actor "
<< "WHERE first_name "
<< "LIKE '" + letter + "%'";
// << "WHERE code = \"IST\"";
query.parse();
mysqlpp::StoreQueryResult result = query.store();
std::cout << "Here is your selection!\n" << std::endl;
std::cout << "--First/Last Names of Actors Whos First ";
std::cout << "Name Stars With " + letter + "--\n" << std::endl;
std::cout << std::left << std::setw(12) << "First Name" <<
std::setw(10) << "Last Name" << std::endl;
std::cout << "------------------------" << std::endl;
for (const auto & row : result) {
std::cout << std::left << std::setw(12) << row[0].c_str();
std::cout << std::setw(5) << row[1] << std::endl;
}
std::cout << "\n" << "to continue, press enter..." << std::endl;
showList();
}
void Film::showTwo(){
mysqlpp::Connection myDB("cse278F2022", "localhost", "cse278F2022",
"raspberrySeltzer");
//Selecting the second option's query
std::cout << "Please type a limit 1-30!" << std::endl;
std::string limit;
std::cin >> limit;
mysqlpp::Query query = myDB.query();
query << "SELECT title "
<< "FROM film "
<< "WHERE rating = 'PG-13' "
<< "OR rating = 'R' "
<< "OR rating = 'NC-17' "
<< "LIMIT " + limit + " ";
query.parse();
mysqlpp::StoreQueryResult result = query.store();
std::cout << "Here is your selection!\n" << std::endl;
std::cout << "--First "+ limit +" Titles PG-13 to NC-17--\n" << std::endl;
std::cout << std::left <<std::setw(20)<< "Title" << std::endl;
std::cout << "------------------------------" <<std::endl;
for (const auto & row : result) {
std::cout << std::left << std::setw(20) << row[0].c_str()<< std::endl;
}
std::cout << "\n" << "to continue, press enter..." << std::endl;
showList();
}
void Film::showThree(){
mysqlpp::Connection myDB("cse278F2022", "localhost", "cse278F2022",
"raspberrySeltzer");
//bind variable
std::cout << "Please type 1 for active and 0 for inactive!" << std::endl;
std::string active;
std::cin >> active;
if(active != "1" && active != "0"){
std::cout << "Wrong!" << std::endl;
std::cout << "Please type 1 for active and 0 for inactive!" << std::endl;
std::cin >> active;
}
//Selecting the second option's query
mysqlpp::Query query = myDB.query();
query << "SELECT Count(*) "
<< "FROM customer "
<< "WHERE active = '"+ active + "' "
<< "GROUP BY store_id";
query.parse();
mysqlpp::StoreQueryResult result = query.store();
std::cout << "Here is your selection!\n" << std::endl;
if(active == "1"){
std::cout << "--Count of All Active Users Grouped by Store Id--\n" << std::endl;
std::cout << std::left <<std::setw(20)<< "Active User Ids" << std::endl;
std::cout << "--------------------" <<std::endl;
} else {
std::cout << "--Count of All Inactive Users Grouped by Store Id--\n" << std::endl;
std::cout << std::left <<std::setw(20)<< "Inactive User Ids" << std::endl;
std::cout << "--------------------" <<std::endl;
}
for (const auto & row : result) {
std::cout << std::left << std::setw(20) << row[0].c_str()<< std::endl;
}
std::cout << "\n" << "to continue, press enter..." << std::endl;
showList();
}
void Film::showFour(){
mysqlpp::Connection myDB("cse278F2022", "localhost", "cse278F2022",
"raspberrySeltzer");
//bind variable
std::cout << "Please type an actor id that is 1-200!" << std::endl;
std::string act_id;
std::cin >> act_id;
//Selecting the second option's query
mysqlpp::Query query = myDB.query();
query << "SELECT film.title, film.film_id, film_actor.actor_id "
<< "FROM film, film_actor "
<< "WHERE film_actor.actor_id = "+ act_id +" "
<< "GROUP BY title "
<< "LIMIT 20";
query.parse();
mysqlpp::StoreQueryResult result = query.store();
std::cout << "Here is your selection!\n" << std::endl;
std::cout << "--First 20 Titles and IDs of Actor Id 25--\n" << std::endl;
std::cout << std::left <<std::setw(22)<< "Title" <<
std::setw(10)<< "Film_id" << std::setw(0)<<"Actor_id" << std::endl;
std::cout << "----------------------------------------" <<std::endl;
for (const auto & row : result) {
std::cout << std::left<<std::setw(22)<< row[0].c_str() << std::setw(10) << row[1] << std::setw(0) << row[2].c_str() << std::endl;
}
std::cout << "\n" << "to continue, press enter..." << std::endl;
showList();
}
#ifndef FILM_H
#define FILM_H
#include <iostream>
#include <string>
class Film {
public:
void showList();
void showOne();
void showTwo();
void showThree();
void showFour();
private:
};
#endif
// Copyright
// Purpose: Project 4
// Date 11/25/2022
// Author: Colton Sullivan
#define MYSQLPP_MYSQL_HEADERS_BURIED
#include <mysql++/mysql++.h>
#include <iostream>
#include "/home/sulli313/Project4/Film.h"
int main() {
int choice;
showList();
std::cin >> choice;
if (choice == -1) {
std::cout << "Bye!" << std::endl;
}
while (choice != -1) {
while ( choice > 4 || choice < -1 || choice == 0 ) {
std::cout << "The wrong choice!!!" << std::endl;
std::cout << "" << std::endl;
std::cout << "to continue, press enter...";
showList();
std::cin >> choice;
}
if ( choice == 1 ) {
showOne();
}
if ( choice == 2 ) {
showTwo;
}
if ( choice == 3 ) {
showThree;
}
if ( choice == 4 ) {
showFour;
}
std::cin >> choice;
if ( choice == -1 ) {
std::cout << "Bye!" << std::endl;
}
}
}
When trying to switch the original program to object oriented programming, I ran into the problem of the error "Invalid use of non-static member function" popping up for the showOne, showTwo, showThree, showFour and showList functions.
If there is a way to access the functions that are created in the Film.cpp/Film.h files and use them in the QueryApp.cpp file to run that as the main, please let me know.
I have tried switching it from Film::showOne, Film::showTwo...etc to showOne(); and Film::showOne(); but either the same Invalid use of non-static member function error will show or it will say that it has not be declared in this scope.
Your showSomething() functions are all member functions of the Film type. In particular, because they are not marked as static, they are non-static member functions. That means they operate on an instance of Film:
class C {
public:
void a(); // <- non-static member function
static void b(); // <- static member function
};
void foo() {
C::b(); // okay, doesn't need an object
C::a(); // not okay, needs an object
C object; // instance of C
object.a(); // okay
object.b(); // also okay
}
Typically you would give your object some state information or it raises the question why you have a non-static member function to begin with. If you don't need state, make them free functions (i.e., functions that are not member functions) or make them static.
In your case, I suppose it would be helpful to create a database connection in your Film's constructor so you can use the database member in all the functions that need a database connection to function.
Something like this:
class Film {
private:
mysqlpp::Connection myDB;
public:
Film() : myDB("x", "localhost", "y", "z") {}
// ...
};
Forgive me if this is an obvious fix as I am very much a novice when it comes to C++.
For my assignment, we were given some starter code that simulates a command-line crypto trading platform. Originally, you would be prompted to type in commands 1 to 6 to do things like print exchange stats, make an offer, print the wallet and such. For my assignment, I've been asked to create an advisor bot that takes in string commands such as 'help' and processes this to return the appropriate output.
Naturally, since there was already a system in place to do this with integers as inputs, I tried to tweak the functions (I didn't do a lot yet) so they take string commands instead and output accordingly.
Before anything else, I would like to know why the function getUserOption and input is underlined red in the while loop of the init function, but in the actual function there are no errors:
This is the contents of the header file
#pragma once
#include <vector>
#include "OrderBookEntry.h"
#include "OrderBook.h"
#include "Wallet.h"
#include <string>
using namespace std;
class MerkelMain
{
public:
MerkelMain();
/** Call this to start the sim */
void init();
private:
void advisorBot();
void printHelp();
void printMarketStats();
void enterAsk();
void enterBid();
void printWallet();
void gotoNextTimeframe();
std::string getUserOption();
void processUserOption(string userOption);
void printCurrentTime();
std::string currentTime;
// OrderBook orderBook{"20200317.csv"};
OrderBook orderBook{"20200601.csv"};
Wallet wallet;
};
This is the cpp file
#include "MerkelMain.h"
#include <iostream>
#include <vector>
#include "OrderBookEntry.h"
#include "CSVReader.h"
#include <string>
using namespace std;
MerkelMain::MerkelMain()
{
}
void MerkelMain::init()
{
int input;
currentTime = orderBook.getEarliestTime();
wallet.insertCurrency("BTC", 10);
while(true)
{
advisorBot();
input = getUserOption();
processUserOption(input);
}
}
void MerkelMain::advisorBot()
{
std::cout << "Please enter a command, or help for a list of commands" << std::endl;
std::cout << "============== " << std::endl;
std::cout << "Current time is: " << currentTime << std::endl;
}
/*void MerkelMain::printMenu()
{
// 1 print help
std::cout << "1: Print help " << std::endl;
// 2 print exchange stats
std::cout << "2: Print exchange stats" << std::endl;
// 3 make an offer
std::cout << "3: Make an offer " << std::endl;
// 4 make a bid
std::cout << "4: Make a bid " << std::endl;
// 5 print wallet
std::cout << "5: Print wallet " << std::endl;
// 6 continue
std::cout << "6: Continue " << std::endl;
std::cout << "============== " << std::endl;
std::cout << "Current time is: " << currentTime << std::endl;
}*/
void MerkelMain::printHelp()
{
std::cout << " The available commands are help, help cmd, prod, min, max, avg, predict, time, step " << std::endl;
}
void MerkelMain::printMarketStats()
{
for (std::string const& p : orderBook.getKnownProducts())
{
std::cout << "Product: " << p << std::endl;
std::vector<OrderBookEntry> entries = orderBook.getOrders(OrderBookType::ask,
p, currentTime);
std::cout << "Asks seen: " << entries.size() << std::endl;
std::cout << "Max ask: " << OrderBook::getHighPrice(entries) << std::endl;
std::cout << "Min ask: " << OrderBook::getLowPrice(entries) << std::endl;
}
}
void MerkelMain::enterAsk()
{
std::cout << "Make an ask - enter the amount: product,price, amount, eg ETH/BTC,200,0.5" << std::endl;
std::string input;
std::getline(std::cin, input);
std::vector<std::string> tokens = CSVReader::tokenise(input, ',');
if (tokens.size() != 3)
{
std::cout << "MerkelMain::enterAsk Bad input! " << input << std::endl;
}
else {
try {
OrderBookEntry obe = CSVReader::stringsToOBE(
tokens[1],
tokens[2],
currentTime,
tokens[0],
OrderBookType::ask
);
obe.username = "simuser";
if (wallet.canFulfillOrder(obe))
{
std::cout << "Wallet looks good. " << std::endl;
orderBook.insertOrder(obe);
}
else {
std::cout << "Wallet has insufficient funds . " << std::endl;
}
}catch (const std::exception& e)
{
std::cout << " MerkelMain::enterAsk Bad input " << std::endl;
}
}
}
void MerkelMain::enterBid()
{
std::cout << "Make an bid - enter the amount: product,price, amount, eg ETH/BTC,200,0.5" << std::endl;
std::string input;
std::getline(std::cin, input);
std::vector<std::string> tokens = CSVReader::tokenise(input, ',');
if (tokens.size() != 3)
{
std::cout << "MerkelMain::enterBid Bad input! " << input << std::endl;
}
else {
try {
OrderBookEntry obe = CSVReader::stringsToOBE(
tokens[1],
tokens[2],
currentTime,
tokens[0],
OrderBookType::bid
);
obe.username = "simuser";
if (wallet.canFulfillOrder(obe))
{
std::cout << "Wallet looks good. " << std::endl;
orderBook.insertOrder(obe);
}
else {
std::cout << "Wallet has insufficient funds . " << std::endl;
}
}catch (const std::exception& e)
{
std::cout << " MerkelMain::enterBid Bad input " << std::endl;
}
}
}
void MerkelMain::printWallet()
{
std::cout << wallet.toString() << std::endl;
}
void MerkelMain::gotoNextTimeframe()
{
std::cout << "Going to next time frame. " << std::endl;
for (std::string p : orderBook.getKnownProducts())
{
std::cout << "matching " << p << std::endl;
std::vector<OrderBookEntry> sales = orderBook.matchAsksToBids(p, currentTime);
std::cout << "Sales: " << sales.size() << std::endl;
for (OrderBookEntry& sale : sales)
{
std::cout << "Sale price: " << sale.price << " amount " << sale.amount << std::endl;
if (sale.username == "simuser")
{
// update the wallet
wallet.processSale(sale);
}
}
}
currentTime = orderBook.getNextTime(currentTime);
}
std::string MerkelMain::getUserOption()
{
std::string userOption = "";
std::string line;
//std::cout << "Type in 1-6" << std::endl;
std::getline(std::cin, line);
try{
userOption = std::stoi(line);
}catch(const std::exception& e)
{
//
}
std::cout << "You chose: " << userOption << std::endl;
return userOption;
}
void printCurrentTime()
{
std::cout << "Current time is: " << currentTime << std::endl;
}
void MerkelMain::processUserOption(string userOption)
{
if (userOption == "help")
{
printHelp();
}
if (userOption == "help cmd")
{
printMarketStats();
}
if (userOption == "prod")
{
enterAsk();
}
if (userOption == "min")
{
enterBid();
}
if (userOption == "max")
{
printWallet();
}
if (userOption == "avg")
{
gotoNextTimeframe();
}
if (userOption == "predict")
{
enterAsk();
}
if (userOption == "time")
{
enterBid();
}
if (userOption == "step")
{
gotoNextTimeframe();
}
}
Your getUserOption() function returns a std::string. This means when you wrote:
input = getUserOption();
In the above statement the right hand side is of type std::string. On the other hand, the left hand side is of type int. So there is mismatch in the type of left hand side and right hand side expressions. Hence the error.
You can solve this by changing the type of variable input to std::string. So replace int input; by:
std::string input; //type changed to std::string
When the program enters in the if and then break, empty cout-s are printed again.
void Person::ShowRecords()
{
std::ifstream data("Input.txt");
while (true)
{
if (!data.good())
{
break;
}
Person person;
data >> person;
std::cout << "First Name: " << person.getFirstName() << "\n";
std::cout << "Last Name: " << person.getLastName() << "\n";
std::cout << "Phone number: " << person.getNumber() << "\n";
std::cout << "EGN: " << person.getEGN() << "\n\n";
}
}
I really think that the most didactic way of tackling stream input is:
while (true) {
// Read
// Check (if fail then break)
// Use
}
Notice the pattern: infinite loop with Read/Check/Use. Check is where we can exit the loop. First you read, than you check if the reading operation was successful or failed, than you can use the data or exit based on that.
Adapting this to your case:
void Person::ShowRecords()
{
std::ifstream data("Input.txt");
while (true) {
// Read
Person person;
data >> person;
// Check
if (!data) {
break;
}
// Use
std::cout << "First Name: " << person.getFirstName() << "\n";
std::cout << "Last Name: " << person.getLastName() << "\n";
std::cout << "Phone number: " << person.getNumber() << "\n";
std::cout << "EGN: " << person.getEGN() << "\n\n";
}
}
The non didactic and probably more idiomatic way is:
void Person::ShowRecords()
{
std::ifstream data("Input.txt");
Person person;
while (data >> person) { // Read and, immediately after, Check
std::cout << "First Name: " << person.getFirstName() << "\n"; // Use
std::cout << "Last Name: " << person.getLastName() << "\n";
std::cout << "Phone number: " << person.getNumber() << "\n";
std::cout << "EGN: " << person.getEGN() << "\n\n";
}
}
I am using the zebra linux sdk for scanner to capture the barcode that is scanned.
I want to listen to the OnBarcodeEvent and capture the code.
I have tried the sample console-app code and gui app code
I have called the
::ExecCommand( CMD_REGISTER_FOR_EVENTS , inXml, outXml, &eStatus);
The OnBarcodeEvent doesn't get invoked when I scan a bar code.
Code provided below.
void SampleEventListener::connect_corescanner()
{
cout <<"connect_corescanner startp"<< endl;
int iScannerType = SCANNER_TYPE_ALL;
StatusID eStatus ;
::Open(this, SCANNER_TYPE_ALL , &eStatus );
std::cout << "Open eStatus line 634 ConsoleSampleEventListener.cpp" << ": " << eStatus << std::endl;
if ( eStatus != STATUS_OK )
{
cout <<eStatus<< endl;
cout <<"can't connect to the corescanner. "<< endl;
exit(0);
}
// register for all events //
std::string inXml;
std::ostringstream oss;
oss << "<inArgs>" << std::endl;
oss << " <cmdArgs>" << std::endl;
oss << " <arg-int>6</arg-int>" << std::endl;
oss << " <arg-int>1,2,4,8,16,32</arg-int>" << std::endl;
oss << " </cmdArgs>" << std::endl;
oss << "</inArgs>" ;
inXml = oss.str();
std::string outXml;
::ExecCommand( CMD_REGISTER_FOR_EVENTS , inXml, outXml, &eStatus);
std::cout << "ExecCommand eStatus line 658 ConsoleSampleEventListener.cpp" << ": " << eStatus << std::endl;
if( eStatus != STATUS_OK ){
cout <<"unable to register for events"<< endl;
exit(-1);
}
cout <<"subscribe to events successful."<< outXml;
cout <<"\nsubscribe to events successful."<< endl;
cout <<"connect_corescanner endp\n"<< endl;
}
void SampleEventListener::OnBarcodeEvent(short int eventType, std::string & pscanData)
{
cout << "Barcode Detected" << endl;
cout << "Out XML" << endl;
cout << pscanData << endl;
}
I'm trying to control the connect method timeout, but I didn't find the appropriate mean.
Just to be clear, I'm not talking about the Idle connection timeout(ConnectTimeoutOption).
The scenario I need to deal with is a database gone away, and my server has to cope with that. My current handling of things is that I'm pinging the server, and If I notice that the ping failed, I'm suspending the queries for 100 seconds. After that I'm trying to reestablish the connection. The problem is that if the database is still dead, than the connect method takes about 20 seconds to answer (can be simulated by just pulling the network cable), which is way too much for me.
This should work for you
#include <mysql++.h>
#include <cstdio>
int main()
{
mysqlpp::Connection conn;
conn.set_option(new mysqlpp::ReconnectOption(true));
conn.set_option(new mysqlpp::ConnectTimeoutOption(5));
const std::string db="mysql_cpp_data";
const std::string query_text="SELECT count(*) as total FROM stock";
conn.connect(db.c_str(), "somehost", "user", "pass");
try
{
mysqlpp::Query query=conn.query();
query << query_text;
mysqlpp::StoreQueryResult res=query.store();
std::cout << "Has " << (*res.begin())[0] << " rows\n";
}
catch(const mysqlpp::BadQuery &e)
{
std::cout << "EXCEPTION: " << e.what() << std::endl;
}
std::cout << "Make database go away now and press a key\n";
getchar();
try
{
mysqlpp::Query query=conn.query();
query << query_text;
mysqlpp::StoreQueryResult res=query.store();
std::cout << "Has " << (*res.begin())[0] << " rows\n";
}
catch(const mysqlpp::BadQuery &e)
{
std::cout << "EXCEPTION: " << e.what() << std::endl;
std::cout << "Make database come back now and press a key\n";
getchar();
while(!conn.ping())
{
sleep(1);
std::cout << "Waiting for DB to come back\n";
}
if(!conn.select_db(db))
{
std::cout << "Failed to change DB\n";
}
}
try
{
mysqlpp::Query query=conn.query();
query=conn.query();
query << query_text;
mysqlpp::StoreQueryResult res=query.store();
std::cout << "Has " << (*res.begin())[0] << " rows\n";
}
catch(const mysqlpp::BadQuery &e)
{
std::cout << "EXCEPTION: " << e.what() << " " << e.errnum() << std::endl;
}
return 0;
}
try this out.
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmdline.h>
#include <mysql++.h>
#define DBS "library"
#define USR "root"
#define PAS "rootsman"
using namespace std;
using namespace mysqlpp;
int main(int argc, char *argv[]) {
//for true cgi but in this case it works, kind of baffling!
mysqlpp::examples::CommandLine cmdline(argc, argv, USR, PAS);
if (!cmdline) return 1;
mysqlpp::Connection conn(true);
conn.set_option(new mysqlpp::ReconnectOption(true));
conn.set_option(new mysqlpp::ConnectTimeoutOption(5));
conn.connect(DBS, cmdline.server(), cmdline.user(), cmdline.pass());
try {
mysqlpp::String sql("select firstname from person");
mysqlpp::Query query = conn.query(sql);
mysqlpp::StoreQueryResult res = query.store();
mysqlpp::StoreQueryResult::const_iterator it;
int count = 1;
for (it = res.begin(); it != res.end(); ++it) {
mysqlpp::Row row = *it;
cout << count << "\t" << row[0] << endl;
++count;
}
} catch (const mysqlpp::BadQuery& bq) {
cerr << "query error: " << bq.what() << endl;
return -1;
}
cout << "\nmake database fly away now by pressing a key>" << endl;
getchar();
try {
mysqlpp::Query query = conn.query();
mysqlpp::String sql("select count(*) as total from person");
query << sql;
mysqlpp::StoreQueryResult res = query.store();
cout << "has " << (*res.begin())[0] << " rows" << endl;
} catch (mysqlpp::BadQuery& e) {
cerr << "\n bad query 2>" << e.what() << endl;
cout << "\nmake database fly back now by pressing enter>" << endl;
while (!conn.ping()) {
//sleep(1);
cout << "\nwaiting for database to fly back>" << endl;
}
if (!conn.select_db(DBS)) {
cerr << "\nfailed to reconnect" << endl;
}
}
try {
mysqlpp::Query query = conn.query();
//this is how my relation and its attributes looks like
String sql("insert into person(firstname,lastname,gender,love,angry,"
"forgiving) values('joy57/qxx','crimson','male','high','medium','high');");
query << sql;
query.execute();
cerr << "\n **inserted successfully**\n" << endl;
} catch (mysqlpp::BadQuery& e) {
cerr << "bad query 3>" << e.what() << e.errnum() << endl;
return -1;
}
cerr << "Jesus helps me when i stumble and fall" << endl;
return 0;
}