From: Norbert Moutarde Date: Wed, 10 Jul 2013 07:22:01 +0000 (+0200) Subject: translate '$$' into all word enter by user X-Git-Url: https://git.nothing2do.fr/?a=commitdiff_plain;h=7f3b1cb4cbcf63a0277d90792aff40ee0b8800bc;p=diary-shell translate '$$' into all word enter by user --- diff --git a/alias.sql b/alias.sql index 8ca7466..085ca83 100644 --- a/alias.sql +++ b/alias.sql @@ -1,8 +1,13 @@ INSERT INTO alias (nom, command, argc) VALUES ('ls', 'select id,texte from raw order by date asc;', 0); +insert into alias (nom, command, argc) values ('ls', 'select * from raw where id=$1 order by date asc;', 1); +insert into alias (nom, command, argc) values ('ls', 'select * from raw where date between $1 and $2 order by date asc;', 2); 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 where nom=$1 from memo;', 1); -insert into alias (nom, command, argc) values ('rdv', -insert into alias (nom, command, argc) values ('var', 'select id, nom, value from var', 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 rem from memo where word=$1', 1); diff --git a/main.cpp b/main.cpp index d39f3e0..cdf1f22 100644 --- a/main.cpp +++ b/main.cpp @@ -15,8 +15,8 @@ string date(string a)//transform any date format (in help) to "YYYY-MM-DD HH:MM: void help() { - cout<<"command : var, now, ls, rm {n°}, rm date1 date2, status, help, alias (-/+list/+add),\n"; - cout<<"select SQL command, \"SQL select\"\n"; + cout<<"command in c++ : value, print, status, help, alias (-/+list/+add), ! SQL...\n"; + cout<<"command in SQL : \n"; } diff --git a/sqldb.cpp b/sqldb.cpp index 30f7c19..4a5c5e7 100644 --- a/sqldb.cpp +++ b/sqldb.cpp @@ -15,9 +15,9 @@ sqlpg::sqlpg() { connect = "dbname=bob user=bob password=pass connect_timeout=10"; //conn = PQconnectStart(var.c_str()); conn = PQconnectdb(connect.c_str()); - clog<<"prepare SQL statement"; - string cmd="select command,argc from alias where nom=$1 and argc = $2;"; - clog<<"cmd="< text) { } else { - clog<<"text.size()<2 L111\n"; + clog<<"text.size()<2\n"; tmp=text[0]; string a="now"; value[0]=a.c_str(); @@ -184,7 +184,7 @@ for (int i=0; i) finish\n"; } inline int sqlpg::testSQL(PGresult* a){ if (!((PQresultStatus(a) == PGRES_COMMAND_OK)||(PQresultStatus(a) == PGRES_TUPLES_OK))) @@ -241,7 +241,7 @@ 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; + int argc=2, inf; const char *value[2]={nom.c_str(), as.c_str()}; int length[2]={nom.size(), as.size()}; int binary[2]={0, 0}; @@ -253,13 +253,25 @@ bool sqlpg::alias(vector a){ } string cmd2; cmd2=PQgetvalue(res, 0, 0); - clog<<"cmd2="<> buf) {//exec for each words in tuples + while (ss >> buf) {//exec for each words in tuple string a="select time,txt from words where txt='"+buf+"';", command; res2=PQexec(conn, a.c_str()); testSQL(res2); diff --git a/tables1.sql b/tables1.sql index a29dfcf..bd8583b 100755 --- a/tables1.sql +++ b/tables1.sql @@ -11,6 +11,7 @@ id serial primary key, cmd text, argc integer, nom text, +inf bit, CONSTRAINT uc_aliasID UNIQUE (nom, argc) );