]> git.nothing2do.fr Git - diary-shell.git/commitdiff
updated alias()
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Sun, 23 Jun 2013 19:46:13 +0000 (21:46 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Sun, 23 Jun 2013 19:46:13 +0000 (21:46 +0200)
sqldb.cpp

index fb72715d1a9c81b93dd3bfbb5f88b4000104fe69..d3abf8c7e580d41fa6b55a1e91d5f0c2dea833d0 100644 (file)
--- a/sqldb.cpp
+++ b/sqldb.cpp
@@ -239,36 +239,25 @@ inline int sqlpg::testSQL(PGresult* a){
 }
 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;";