From 793e8ffd159058e2ab3395252a618358f9529f99 Mon Sep 17 00:00:00 2001 From: Norbert Moutarde Date: Tue, 16 Jul 2013 13:59:33 +0200 Subject: [PATCH] added var.sql (and mapvalue) --- alias.sql | 11 ++++++----- main.cpp | 6 +++--- sqldb.cpp | 32 ++++++++++++++++++++++++-------- sqldb.h | 6 ++++-- tables1.sql | 2 +- var.sql | 3 +++ 6 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 var.sql diff --git a/alias.sql b/alias.sql index 81c7d62..e4ed9af 100644 --- a/alias.sql +++ b/alias.sql @@ -1,15 +1,16 @@ 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 ('search', 'select id,texte from raw where texte ~ $1 order by date asc;', 1, 'search record who contains your arg (only one arg)'); 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 ('var', 'select value from var where nom=$1', 1, 'print named var content'); +insert into alias (nom, cmd, argc, inf, help) values ('var', 'insert into var (nom, value) values ($1, $2)', 2, '1', 'add new var and it''s content'); +insert into alias (nom, cmd, argc, inf, help) values ('memo', 'insert into memo (word, rem) values ($1, $2);', 2, '1', 'insert new memo'); 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 argc from alias where nom=$1 order by argc', 1, 'print id,argc of named alias by ID'); 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'); diff --git a/main.cpp b/main.cpp index c66d4a8..d3a05a2 100644 --- a/main.cpp +++ b/main.cpp @@ -19,8 +19,9 @@ int main(int argc, char *argv[]) sqlpg diary; string tmp, rep, shell="? "; int hm; + diary.getvar(); do{ - clog<<"\n"; + clog<<"again\n"; hm=diary.hmRecord(); cout<1)) { if (words[1]=="add") { string cmd=""; @@ -55,7 +56,6 @@ do{ else if (diary.alias(words)); else { diary.insert(words); - } words.clear(); }while(1); diff --git a/sqldb.cpp b/sqldb.cpp index c1b7363..405d976 100644 --- a/sqldb.cpp +++ b/sqldb.cpp @@ -21,7 +21,6 @@ sqlpg::sqlpg() { clog<<"SQL statement="< string sqlpg::toString( const T & Value ){ } int sqlpg::insert(vector text) { clog<<"insert(vector) begin\n"; + + string command="INSERT INTO raw (date, texte) VALUES ($1::timestamp, $2::text);"; string tmp=""; int argc=2; @@ -125,8 +126,8 @@ int sqlpg::insert(vector text) { value[1]=tmp.c_str(); length[1]=tmp.size(); binary[1]=0; - //value[1]=now().c_str(); - length[1]=19; + value[1]=a.c_str(); + length[1]=a.size(); binary[1]=0; clog<<"text.size()<2 finish\n"; }; @@ -172,8 +173,11 @@ int sqlpg::hmRecord(){ clog<<"hmRecord()="<::iterator i=value.begin(); i!=value.end(); ++i){ + cout<<"value["<first<<"]="<second<second; }; cout<second; }; -cout< (a, b) ); + }; + clog<<"value.size="< #include +#include int isdate(std::string);//return 1 for YYYY-MM-DD and 2 for HH:MM:SS @@ -17,10 +18,10 @@ public: std::string now(int=1); int status();// return 0 if success, 1 for error, -1 int insert(std::vector);// format=yyyy-month-day hour:min:sec text - + void getvar(); void print();// print result of exec(string) call int hmRecord();// How Many records in "raw" table - void var(); + void printvar(); inline int testSQL(PGresult*);// test if all gone good void exec(std::vector);// first string is for SQL command, other are to replace %1,%2, etc... void exec(std::string); @@ -32,6 +33,7 @@ private: std::vector < std::vector > ret;//useless ? std::string b, date, connect; int a; + std::mapvalue; }; #endif // SQLDB_H diff --git a/tables1.sql b/tables1.sql index a0b16dd..fc2a63e 100755 --- a/tables1.sql +++ b/tables1.sql @@ -19,7 +19,7 @@ CONSTRAINT uc_aliasID UNIQUE (nom, argc) create table IF NOT EXISTS raw ( id serial primary key, date timestamp, -analyzed bit(1), +analyzed bit(1) default '0', texte text ); diff --git a/var.sql b/var.sql new file mode 100644 index 0000000..2318ed0 --- /dev/null +++ b/var.sql @@ -0,0 +1,3 @@ +insert into var (nom, value) values ('hs', '+'); +insert into var (nom, value) values ('vs', '|'); +-- Vertical and Horizontal Spacing car -- 2.45.1