]> git.nothing2do.fr Git - diary-shell.git/commitdiff
I've added some help into alias.sql, tweaked the output (the last "|") and some other...
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Mon, 15 Jul 2013 17:28:16 +0000 (19:28 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Mon, 15 Jul 2013 17:28:16 +0000 (19:28 +0200)
alias.sql
sqldb.cpp
tables1.sql

index 6702bab5244f06100ced7da3c62e825ce340821b..81c7d62bc16271b104131494344c15ba1886717a 100644 (file)
--- a/alias.sql
+++ b/alias.sql
@@ -1,14 +1,15 @@
-INSERT INTO alias (nom, command, argc, help) VALUES ('ls', 'select id,texte from raw order by date asc;', 0, 'liste les enregistrement (select by ID, between 2 date, everyone)');
-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, help) VALUES ('search', 'select id,texte from raw where texte ~ $1 order by date asc;', 1, 'search record who contains your arg (only one');
-INSERT INTO alias (nom, command, argc, help) VALUES ('rm', 'DELETE FROM raw WHERE id =$1;', 1, 'delete record by ID');
-INSERT INTO alias (nom, command, argc, help) VALUES ('alias', 'select nom from alias;', 0, 'print every alias''s name');
-insert into alias (nom, command, argc, help) values ('var', 'select nom from var', 0, 'print avery var/named var content');
-insert into alias (nom, command, argc) values ('var', 'select nom,value from var where nom=$1 order by id', 1);
-insert into alias (nom, command, argc, inf, help) values ('memo', 'insert into memo (word, rem) values ($1, $2);', 1, '1', 'list memo''s name');
-insert into alias (nom, command, argc) values ('memo', 'select distinct word from memo', 0);
-insert into alias (nom, command, argc, help) values ('memo', 'select id,rem from memo where word=$1 order by id', 1, 'print memo content');
-insert into alias (nom, command, argc, help) values ('help', 'select distinct nom from alias', 0, 'help itself (add "command to get specific help")');
-insert into alias (nom, command, argc) values ('help', 'select distinct id,nom,command from alias where nom=$1', 1);
-insert into alias (nom, command, argc) values ('help', 'select id,nom,command from alias where nom=$1 and argc=$2', 1);
+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');
+INSERT INTO alias (nom, cmd, argc, help) VALUES ('search', 'select id,texte from raw where texte ~ $1 order by date asc;', 1, 'search record who contains your arg (only one');
+INSERT INTO alias (nom, cmd, argc, help) VALUES ('rm', 'DELETE FROM raw WHERE id =$1;', 1, 'delete record by ID');
+INSERT INTO alias (nom, cmd, argc, help) VALUES ('alias', 'select nom from alias;', 0, 'print every alias''s name');
+insert into alias (nom, cmd, argc, help) values ('var', 'select nom from var', 0, 'print avery var');
+insert into alias (nom, cmd, argc, help) values ('var', 'select nom,value from var where nom=$1 order by id', 1, 'print named var content');
+insert into alias (nom, cmd, argc, inf, help) values ('memo', 'insert into memo (word, rem) values ($1, $2);', 2, '1', 'list memo''s name');
+insert into alias (nom, cmd, argc, help) values ('memo', 'select distinct word from memo', 0, 'list all word with memo attached');
+insert into alias (nom, cmd, argc, help) values ('memo', 'select id,rem from memo where word=$1 order by id', 1, 'print memo content');
+insert into alias (nom, cmd, argc, help) values ('help', 'select distinct nom from alias', 0, 'help itself (add "cmd" to get specific help)');
+insert into alias (nom, cmd, argc, help) values ('help', 'select argc from alias where nom=$1 order by argc', 1, 'print id,argc of named 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 (...)');
index c1573ac8d4152b241b79cf8d06cb64729d3f575e..c1b7363f4c42db053f21b02ae2242d1222f6bcd5 100644 (file)
--- a/sqldb.cpp
+++ b/sqldb.cpp
@@ -17,7 +17,7 @@ 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 (inf='1') and (argc < $2));";
+    string cmd="select cmd,argc,inf from alias where ((nom = $1) and (argc = $2)) OR ((nom = $1) and (inf='1') and (argc < $2));";
     clog<<"SQL statement="<<cmd<<endl;
     res=PQprepare(conn, "selectalias", cmd.c_str(), 2, NULL);
     testSQL(res);
@@ -180,12 +180,14 @@ sqlpg::~sqlpg() {
     PQfinish(conn);
 }
 void sqlpg::print(){
-for (int i=0; i<PQntuples(res); i++){
+int l=PQntuples(res);
+for (int i=0; i<l; i++){
     int lim=PQnfields(res);
     for (int j=0; j<lim-1; j++){
             cout<<PQgetvalue(res, i, j)<<"+";
         };
-        cout<<PQgetvalue(res, i, lim-1)<<"|";
+        cout<<PQgetvalue(res, i, lim-1);
+        if(i<l-1)cout<<"|";
     };
 
 cout<<endl;
index b3d2affc6346511b4b1ef3db8ac589b8cc17f14e..a0b16dd741858ed44c5e69e7c9e56c62140cdf57 100755 (executable)
@@ -12,8 +12,8 @@ cmd text,
 help text,
 argc integer,
 nom text,
-inf bit DEFAULT 0,
-CONSTRAINT uc_aliasID UNIQUE (nom, argc, inf)
+inf bit DEFAULT '0',
+CONSTRAINT uc_aliasID UNIQUE (nom, argc)
 );
 
 create table IF NOT EXISTS raw (