From: Norbert Moutarde Date: Sat, 6 Jul 2013 11:10:23 +0000 (+0200) Subject: now ' character don't make anymore crash X-Git-Url: https://git.nothing2do.fr/?a=commitdiff_plain;h=2914b3fb3836be71aea63fc6f486d07b785f9d60;p=diary-shell.git now ' character don't make anymore crash TODO : table var must be usefully populated --- diff --git a/alias.sql b/alias.sql index 8b426c9..8ca7466 100644 --- a/alias.sql +++ b/alias.sql @@ -1,7 +1,8 @@ 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 ('rm', 'DELETE FROM raw WHERE id =''%1'';', 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 ('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); diff --git a/main.cpp b/main.cpp index 03763b1..d39f3e0 100644 --- a/main.cpp +++ b/main.cpp @@ -15,7 +15,7 @@ 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, date {arg}, help, alias (-/+list/+add),\n"; + cout<<"command : var, now, ls, rm {n°}, rm date1 date2, status, help, alias (-/+list/+add),\n"; cout<<"select SQL command, \"SQL select\"\n"; } @@ -24,6 +24,7 @@ void help() int main(int argc, char *argv[]) { cout << "Début du programme '" << argv[0] << "'. Nombre de paramètres reçus : " << argc << endl; + cerr<<"===start===\n"; sqlpg diary; string tmp, rep, shell="? "; int hm; @@ -42,11 +43,9 @@ do{ else if (words[0]=="help") help(); else if (words[0]=="status") diary.status(); - else if (words[0]=="var") diary.var(); - //else if (words[0]=="now") cout<1)) { + if (words[1]=="add") { string cmd=""; for (int a=3; a string sqlpg::toString( const T & Value ){ return oss.str(); } int sqlpg::insert(vector text) { - cerr<<"insert(vector) begin\n"; - string command="INSERT INTO raw (date, texte) VALUES ($1::timestamp, $2);"; + clog<<"insert(vector) begin\n"; + string command="INSERT INTO raw (date, texte) VALUES ($1::timestamp, $2::text);"; string tmp=""; int argc=2; const char * value[2]; int length[2]; int binary[2]; + PQprepare(conn, "insert", command.c_str(), 2, NULL); if (text.size()>2){ if ((isdate(text[0]))+(isdate(text[1]))==3){ - cerr<<"text[0]+text[1]==3(L55)\n"; + clog<<"text[0]+text[1]==3(L55)\n"; date=text[0]; string a=date+" "+text[1]; value[0]=a.c_str(); @@ -69,7 +76,7 @@ int sqlpg::insert(vector text) { } else if((text[0]=="-")&&(isdate(text[1])==2)){ - cerr<<"date partielle(L72)\n"; + clog<<"date partielle(L72)\n"; tmp=text[2]; string a=date+" "+text[1]; value[0]=a.c_str(); @@ -86,7 +93,7 @@ int sqlpg::insert(vector text) { } else{ - cerr<<"text.size()>2; text[0] & text[1] isn't date. L89"; + clog<<"text.size()>2 && text[0] & text[1] isn't date. L89"; tmp=text[0]; string a="1971-11-11 22:22:22"; value[0]=a.c_str(); @@ -105,11 +112,9 @@ int sqlpg::insert(vector text) { } else { - cerr<<"text.size()<2 L111\n"; + clog<<"text.size()<2 L111\n"; tmp=text[0]; - cerr<<"113\n"; string a="now"; - cerr<<"115\n"; value[0]=a.c_str(); length[0]=a.size(); binary[0]=0; @@ -122,11 +127,12 @@ int sqlpg::insert(vector text) { //value[1]=now().c_str(); length[1]=19; binary[1]=0; - cerr<<"text.size()<2 finish\n"; + clog<<"text.size()<2 finish\n"; }; - res=PQexecParams(conn, command.c_str(), argc, NULL, value, length, binary, 0); + //res=PQexecParams(conn, command.c_str(), argc, NULL, value, length, binary, 0); + res=PQexecPrepared(conn, "insert", argc, value, length, binary, 0); testSQL(res); - cerr<<"insert(vector) end\n"; + clog<<"insert(vector) end\n"; //exec(command); return 0; } @@ -162,6 +168,7 @@ int sqlpg::hmRecord(){ //res=PQexec(conn, command.c_str()); exec(command); a=PQntuples(res); + clog<<"hmRecord()="< a){ - cerr<<"exec(vector: a.size()=="<: a.size()=="< a){ - 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 ! - cerr<<"cmd="<