]> git.nothing2do.fr Git - diary-shell.git/commitdiff
I've cleaned my main
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Tue, 23 Jul 2013 13:26:46 +0000 (15:26 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Tue, 23 Jul 2013 13:26:46 +0000 (15:26 +0200)
alias.sql
main.cpp
sqldb.cpp

index b6702a79d6b181eef7f2e1320ec47f722e5f1d0e..9852214177ea7fd4e308d9bbc108eb311b6ffe52 100644 (file)
--- a/alias.sql
+++ b/alias.sql
@@ -1,4 +1,4 @@
-insert into alias (nom, cmd, argc, help) values ('tables', 'select tablename from pg_tables', 0, 'list table (every table...)');
+insert into alias (nom, cmd, argc, help) values ('tables', 'select tablename from pg_tables where tableowner=current_user', 0, 'list table (every table...)');
 INSERT INTO alias (nom, cmd, argc, help) VALUES ('ls', 'select id,texte from raw order by date asc;', 0, 'list id,text of every records');
 insert into alias (nom, cmd, argc, help) values ('ls', 'select * from raw where id=$1 order by date asc;', 1, 'print id,date,text of one record');
 insert into alias (nom, cmd, argc, help) values ('ls', 'select * from raw where date between $1 and $2 order by date asc;', 2, 'liste record with date between $1 and $2');
@@ -16,3 +16,4 @@ insert into alias (nom, cmd, argc, help) values ('help', 'select argc from alias
 insert into alias (nom, cmd, argc, help) values ('help', 'select help from alias where nom=$1 and argc=$2', 2, 'print help for only one alias (as "nom" and "argc" is a key)');
 insert into alias (nom, cmd, argc, help) values ('print', 'select cmd,inf from alias where nom=$1 and argc=$2', 2, 'print SQL command of an alias (...)');
 insert into alias (nom, cmd, argc, inf, help) values ('default', 'INSERT INTO raw (date, texte) VALUES ($1::timestamp, $2::text);', 2 , '1', 'default command');
+insert into alias (nom, cmd, argc, inf, help) values ('aliasadd', 'insert into alias (nom, argc, cmd) values ( $1, $2, $3 );', 3, '1', 'add alias (with form : aliasadd "name" "argc" "SQL")');
index e80db5519fc87a50c57c0c18374b8da3dd771459..23a1b99fc7cfd847f40c0ffefcbe50aaf55398df 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
     int hm;
     diary.getvar();
 do{
-    clog<<"again\n";
+    clog<<"======================again=================================\n";
     hm=diary.hmRecord();
     cout<<hm<<shell;
     getline(cin,rep,'\n');
@@ -31,23 +31,9 @@ do{
     //cut rep into words[0], words[1], ...
     while (ss >> buf) words.push_back(buf);
     if(words.size()==0)break;//quit
-    else if (words[0]=="w") diary.exec(words);
     else if (words[0]=="p") diary.print();
-    //else if (words[0]=="help") diary.help(); now  into SQL
     else if (words[0]=="status") diary.status();
-
     else if (words[0]=="con") diary.printvar();
-    else if ((words[0]=="alias")&&(words.size()>1)) {
-        if (words[1]=="add") {
-            string cmd="";
-            for (int a=3; a<words.size()-1; a++){
-                cmd=cmd+words[a]+" ";
-            }
-            cmd=cmd+words[words.size()-1];
-            diary.exec("insert into alias (nom, command) values ( '"+words[2]+"', '"+cmd+"' );");
-        }
-        else if (words[1]=="list") {diary.exec("select * from alias;");diary.print();}
-    }
     else if (words[0]=="!") {
         string a=rep.substr(2);
         diary.exec(a);
@@ -57,7 +43,8 @@ do{
     else {
         /*vector<string>::iterator it;
         it = words.begin();
-        it = words.insert ( it , "default");
+        it = words.insert (it, "now");
+        it = words.insert (it, "default");
         diary.alias(words);*/
         diary.insert(words);
     }
index 327f0aac58e1e95571485f873c21044871a87b8e..6aeb730d1595678cd36dfd815ab1a16e4745727c 100644 (file)
--- a/sqldb.cpp
+++ b/sqldb.cpp
@@ -285,14 +285,9 @@ bool sqlpg::alias(vector<string> a){
         binary[inf-inf]=0;
     }
     clog<<"if(inf!=0) finish\n";
-    for(int k=0; k<(argc+inf); k++){
+    for(int k=0; k<(argc); k++){
         clog<<"value["<<k<<"]="<<value[k]<<" length="<<length[k]<<"\n";
     }
-
-
-
-
-
     clog<<"cmd2="<<cmd2<<" argc="<<argc<<endl;
     res=PQprepare(conn, "execalias",cmd2.c_str(), argc, NULL);
     clog<<"PQprepart done(cmd2="<<cmd2<<" argc="<<argc<<"\n";
@@ -349,7 +344,7 @@ void sqlpg::getvar(){
         value.insert(pair<string, string> (a, b) );
 
     };
-    clog<<"value.size="<<value.size();
+    clog<<"value.size="<<value.size()<<endl;
 };
 
 #endif