}
bool sqlpg::alias(vector<string> a){
string cmd;
- cmd="select command from alias where nom='"+a[0]+"';";
+ cmd="select command, argc from alias where nom='"+a[0]+"';";
//cout<<"cmd="<<cmd<<endl;
exec(cmd);
if (PQntuples(res)<1)return 0;
- string alias;
- alias=PQgetvalue(res, 0, 0);
- //cout<<"alias="<<alias<<endl;
+ string cmd2;
+ cmd2=PQgetvalue(res, 0, 0);
+ //cout<<"cmd2="<<cmd2<<endl;
int pos=0;
stringstream tmp;
- for(int i=1; i<a.size(); i++){
- for (int j=1; j<=10; j++){// 10 is arbitrarily choosed
- tmp<<"$"<<j;
- int pos=alias.find(tmp.str());
- //cout<<"tmp.str()="<<tmp.str()<<endl;
- if(!((pos==0)||(pos==-1))){
- alias.replace(pos, 2, a[i]);
- //cout<<"pos="<<pos<<", alias="<<alias<<endl;
- }
- tmp.flush();
- }
+ int argc;
+ argc=PQgetvalue(res, 0, 1);
+ char * value[argc];
+ for (int i=0; i<a.size(); i++){
+ value[i]=a[i].c_str();
}
- //cout<<"alias="<<alias<<"\n";
-
- if (PQresultStatus(res)==PGRES_TUPLES_OK){
- exec(alias);
- print();
- return 1;
- };
- return 0;
+ PQexecParams(conn, cmd2.c_str(), argc, NULL, value, NULL, NULL, 0);
+ print();
+ return 1;
}
void sqlpg::compulse(){
string cmd="select * from raw where analyzed='0' order by date asc;";