From: Norbert Moutarde Date: Wed, 10 Jul 2013 18:22:41 +0000 (+0200) Subject: add alias with "$$", that mean every other words on command line X-Git-Url: https://git.nothing2do.fr/?a=commitdiff_plain;h=b9017eb2d09b7e3c9f7b72f9c9e10e523c4935f8;p=diary-shell.git add alias with "$$", that mean every other words on command line --- diff --git a/alias.sql b/alias.sql index 085ca83..929cdfb 100644 --- a/alias.sql +++ b/alias.sql @@ -4,10 +4,8 @@ insert into alias (nom, command, argc) values ('ls', 'select * from raw where da INSERT INTO alias (nom, command, argc) VALUES ('search', 'select id,texte from raw where texte ~ $1 order by date asc;', 1); INSERT INTO alias (nom, command, argc) VALUES ('rm', 'DELETE FROM raw WHERE id =$1;', 1); INSERT INTO alias (nom, command, argc) VALUES ('alias', 'select nom from alias;', 0); -insert into alias (nom, command, argc) values ('memo', 'select word from memo;', 0); -insert into alias (nom, command, argc) values ('memo', 'select id, word, rem from memo where nom=$1;', 1); insert into alias (nom, command, argc) values ('var', 'select nom from var', 0); insert into alias (nom, command, argc) values ('var', 'select id,nom,value from var where nom=$1', 1); insert into alias (command, argc, nom, inf) values ('insert into memo (word, rem) values ($1, ''$$'');', 1, 'memo', '1'); -insert into alias (nom, command, argc) values ('memo', 'select word from memo', 0); +insert into alias (nom, command, argc) values ('memo', 'select distinct word from memo', 0); insert into alias (nom, command, argc) values ('memo', 'select rem from memo where word=$1', 1); diff --git a/main.cpp b/main.cpp index cdf1f22..0fac236 100644 --- a/main.cpp +++ b/main.cpp @@ -67,6 +67,6 @@ do{ } words.clear(); }while(1); -cout<<"Fin du programme\n"; +clog<<"Fin du programme\n"; return 0; } diff --git a/sqldb.cpp b/sqldb.cpp index 4a5c5e7..a1b9b40 100644 --- a/sqldb.cpp +++ b/sqldb.cpp @@ -7,6 +7,7 @@ #include #include #include + using namespace std; sqlpg::sqlpg() { @@ -16,8 +17,9 @@ sqlpg::sqlpg() { //conn = PQconnectStart(var.c_str()); conn = PQconnectdb(connect.c_str()); clog<<"prepare SQL statement\n"; - string cmd="select command,argc,inf from alias where ((nom=$1) and (argc = $2)) OR ((nom=$1) and (argc<$2) and (inf!='0'));"; - clog<<"SQL statement prepared"<tm_year, 1+ltm->tm_mon, ltm->tm_mday); else { cout<<"error in date"; - date="0000-00-00 00;00;00"; + date="0000-00-00 00:00:00"; } string d(date); @@ -240,45 +242,47 @@ inline int sqlpg::testSQL(PGresult* a){ } bool sqlpg::alias(vector a){ clog<<"alias start here\n"; - string nom=a[0], as=toString(a.size()-1).c_str(); - int argc=2, inf; + string nom=a[0], as=toString(a.size()-1).c_str(), i; + int argc=2; const char *value[2]={nom.c_str(), as.c_str()}; int length[2]={nom.size(), as.size()}; int binary[2]={0, 0}; res=PQexecPrepared(conn, "selectalias", argc, value, length, binary, 0); testSQL(res); - if (PQntuples(res)<1){ + if (PQntuples(res)!=1){ cerr<<"alias end pqntuples(res)="<