ss>>y>>"-">>m>>"-">>d>>" ">>h>>":">>m>>":">>s>>".">>x;
return ss.str();*/
}
-int main(int argc, char *argv[])
+int main(int argc, char * argv[])
{
- cout << "Début du programme '" << argv[0] << "'." << endl;
+ cout << "Début du programme '" << argv[0] << "'. argc="<<argc<<endl;
clog<<"======================start=================================\n";
sqlpg diary;
string tmp, rep, shell="? ";
int hm;
+ bool print=false;
+ string t="p";
+ if (argc>1){
+ if (argv[1]==string("p")){
+ print=true;
+ }
+ };
+ clog<<"print="<<print<<endl;
do{
clog<<"======================again=================================\n";
- diary.getvar();// you can update var and it affect the actual session (I know, it's a useless thing)
+ diary.getvar();// you can update var and it affect the actual session (I know, it's a CPU consuming thing)
hm=diary.hmRecord();
cout<<hm<<shell;
getline(cin,rep,'\n');
else if (words[0]=="!") {
string a=rep.substr(2);
diary.exec(a);
- //diary.print();
+ if(print)diary.print();
+ }
+ else if (diary.alias(words)){
+ if(print)diary.print();
}
- else if (diary.alias(words));
else {
/*vector<string>::iterator it;
it = words.begin();
it = words.insert (it, "default");
diary.alias(words);*/
diary.insert(words);
+ if(print)diary.print();
}
words.clear();
}while(1);
-clog<<"Fin du programme\n";
+clog<<"=====================Fin du programme===========================\n";
return 0;
}
cout<<endl;
}
-void sqlpg::exec(string a){
+PGresult* sqlpg::exec(string a){
clog<<"exec(string["<<a<<"])\n";
res2=PQexecParams(conn, a.c_str(), 0, NULL, 0, NULL, NULL, 0);
- if (!((PQresultStatus(res2) == PGRES_COMMAND_OK)||(PQresultStatus(res2) == PGRES_TUPLES_OK)))
- {
- cout<<"PQerrorMessage(conn) : "<< PQerrorMessage(conn)<<endl;
- cout<<"PQresStatus(res2)="<<PQresStatus(PQresultStatus(res2))<<endl;
- };
+ testSQL(res2);
+ return res2;
}
-void sqlpg::exec(vector<string> a){
+PGresult* sqlpg::exec(vector<string> a){
clog<<"exec(vector<string>: a.size()=="<<a.size()<<"\n";
/*const char *paramValues[1];
int paramLengths[1];
}
res=PQexecParams(conn, a[0].c_str(), argc, NULL, value, length, binary, 0);
testSQL(res);
- print();
+ //print();
clog<<"exec(vector<string>) finish\n";
}
inline int sqlpg::testSQL(PGresult* a){
if (!((PQresultStatus(a) == PGRES_COMMAND_OK)||(PQresultStatus(a) == PGRES_TUPLES_OK)))
{
- cout<<"PQerrorMessage(conn): "<< PQerrorMessage(conn)<<endl;
- cout<<"PQresStatus(res)="<<PQresStatus(PQresultStatus(a))<<endl;
+ cerr<<"PQerrorMessage(conn): "<< PQerrorMessage(conn)<<endl;
+ cerr<<"PQresStatus(res)="<<PQresStatus(PQresultStatus(a))<<endl;
};
}
bool sqlpg::alias(vector<string> a){
res=PQexecPrepared(conn, "selectalias", argca, valuea, lengtha, binarya, 0);
testSQL(res);
if (PQntuples(res)!=1){
- cerr<<"alias end pqntuples(res)="<<PQntuples(res)<<endl;
+ cerr<<"alias end more than one alias found ! (pqntuples(res)="<<PQntuples(res)<<")\n";
return 0;
}
string cmd2;
clog<<"PQprepart done(cmd2="<<cmd2<<" argc="<<argc<<"\n";
testSQL(res);
res=PQexecPrepared(conn, "execalias", argc, value, length, binary, 0);
- clog<<"PQexecPrepared done argc="<<argc<<endl;
+ clog<<"PQexecPrepared done.\n";
testSQL(res);
- print(); //I prefer to type 'p' (otherwise, I have to add a column in database)
+ //print();
exec("DEALLOCATE execalias");
clog<<"alias() end here\n";
return 1;
testSQL(res);
if (PQntuples(res)!=1){
cerr<<"alias end pqntuples(res)="<<PQntuples(res)<<endl;
- return 0;
+ return;
}
string cmd2;
cmd2=PQgetvalue(res, 0, 0);
int hmRecord();// How Many records in "raw" table
void printvar();
inline int testSQL(PGresult*);// test if all gone good
- void exec(std::vector<std::string>);// first string is for SQL command, other are to replace %1,%2, etc...
- void exec(std::string);
+ PGresult* exec(std::vector<std::string>);// first string is for SQL command, other are to replace %1,%2, etc...
+ PGresult* exec(std::string);
bool alias(std::vector<std::string>);
void compulse();//populate table words
void connect(std::string, std::string);//connect with user and service (credential in database)