From: Norbert Moutarde Date: Fri, 5 Jul 2013 17:22:02 +0000 (+0200) Subject: added some function X-Git-Url: https://git.nothing2do.fr/?a=commitdiff_plain;h=78c73caaab0d864fa7ba28b51232b72d8af66c52;p=diary-shell added some function --- diff --git a/alias.sql b/alias.sql index 3f54496..8b426c9 100644 --- a/alias.sql +++ b/alias.sql @@ -1,5 +1,7 @@ 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 ('search', 'select id,texte from raw where texte ~ $1 order by date asc;', 1); -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;"', 1); +insert into alias (nom, command, argc) values ('rdv', diff --git a/main.cpp b/main.cpp index a560114..03763b1 100644 --- a/main.cpp +++ b/main.cpp @@ -43,7 +43,7 @@ do{ else if (words[0]=="status") diary.status(); else if (words[0]=="var") diary.var(); - else if (words[0]=="now") cout< string sqlpg::toString( const T & Value ){ return oss.str(); } int sqlpg::insert(vector text) { - string command; + cerr<<"insert(vector) begin\n"; + string command="INSERT INTO raw (date, texte) VALUES ($1::timestamp, $2);"; string tmp=""; + int argc=2; + const char * value[2]; + int length[2]; + int binary[2]; if (text.size()>2){ if ((isdate(text[0]))+(isdate(text[1]))==3){ - cout<<"date detecte\n"; + cerr<<"text[0]+text[1]==3(L55)\n"; date=text[0]; + string a=date+" "+text[1]; + value[0]=a.c_str(); + length[0]=a.size(); + binary[0]=0; tmp=text[2]; for (int a=3;a2; text[0] & text[1] isn't date. L89"; tmp=text[0]; + string a="1971-11-11 22:22:22"; + value[0]=a.c_str(); + length[0]=a.size(); + binary[0]=0; + //tmp=text[2]; + value[1]=tmp.c_str(); + length[1]=tmp.size(); + binary[1]=0; for (int a=1;a) end\n"; + //exec(command); return 0; } -void sqlpg::deletetuple(string tmp){ - string command; - command="DELETE FROM raw WHERE id ='" + tmp + "'"; - /*res=PQexec(conn, command.c_str()); - testSQL();*/ - exec(command); - //cout<tm_year, 1+ltm->tm_mon, ltm->tm_mday, 1+ltm->tm_hour, 1+ltm->tm_min, 1+ltm->tm_sec); + if (day==0)sprintf(date,"%d:%d:%d", 1+ltm->tm_hour, 1+ltm->tm_min, 1+ltm->tm_sec); + else if (day==1)sprintf(date,"%d-%d-%d %d:%d:%d", 1900+ltm->tm_year, 1+ltm->tm_mon, ltm->tm_mday, 1+ltm->tm_hour, 1+ltm->tm_min, 1+ltm->tm_sec); + else if (day==2)sprintf(date,"%d-%d-%d", 1900+ltm->tm_year, 1+ltm->tm_mon, ltm->tm_mday); + else { + cout<<"error in date"; + date="0000-00-00 00;00;00"; + } + string d(date); return d; } @@ -134,7 +165,7 @@ int sqlpg::hmRecord(){ return a; } void sqlpg::var(){ - cout<<"date="< a){ - cout<<"a.size()=="<: a.size()=="< a){ - //cout<<"alias start here\n"; + cerr<<"alias start here\n"; string cmd; cmd="select command,argc from alias where nom='"+a[0]+"' and argc = '"+toString(a.size()-1)+"';";// I need to select a function with argc too ! - //cout<<"cmd="< #include -std::string now(); + int isdate(std::string);//return 1 for YYYY-MM-DD and 2 for HH:MM:SS class sqlpg { @@ -14,16 +14,12 @@ public: sqlpg (); ~sqlpg(); template static std::string toString( const T & Value ); + 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 - std::vector < std::vector > list(std::string);// to list the content of table "string" - std::vector < std::vector > listdate(std::string, std::string=now());// to list the content of table "raw" between 2 date (date and now, by défault) - //std::vector > size(std::string="");//size of each tuple - void deletetuple(std::string); - void deletedate(std::string, std::string);// delete tuple between two date + void print();// print result of exec(string) call int hmRecord();// How Many records in "raw" table - //std::vector search(std::string);//return id of record containing string, useless (SQL deo the same) void var(); 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... @@ -34,7 +30,7 @@ private: PGconn *conn; PGresult *res, *res2, *res3; std::vector < std::vector > ret;//useless ? - std::string b, date; + std::string b, date, connect; int a; }; diff --git a/tables1.sql b/tables1.sql index 370ccfa..91c2c61 100755 --- a/tables1.sql +++ b/tables1.sql @@ -21,3 +21,14 @@ analyzed bit(1), texte text ); +create table memo ( +id serial primary key, +word text, +rem text +); + +create table var ( +id serial primary key, +nom text, +value text +);