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);
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="<<cmd<<endl;
+ clog<<"prepare SQL statement\n";
+ string cmd="select command,argc,inf from alias where ((nom=$1) and (argc = $2)) OR ((nom=$1) and (argc<$2) and (inf!='0'));";
+ clog<<"SQL statement prepared"<<endl;
res=PQprepare(conn, "selectalias", cmd.c_str(), 2, NULL);
testSQL(res);
}
else {
- clog<<"text.size()<2 L111\n";
+ clog<<"text.size()<2\n";
tmp=text[0];
string a="now";
value[0]=a.c_str();
for (int j=0; j<lim-1; j++){
cout<<PQgetvalue(res, i, j)<<"+";
};
- cout<<PQgetvalue(res, i, lim-1)<<"\n";
+ cout<<PQgetvalue(res, i, lim-1)<<"|";
};
cout<<endl;
value[i]=a[i+1].c_str();
length[i]=a[i+1].size();
binary[i]=0;
- cerr<<"i="<<i<<" value="<<value[i]<<" length="<<length[i]<<"\n";
+ clog<<"i="<<i<<" value="<<value[i]<<" length="<<length[i]<<"\n";
}
res=PQexecParams(conn, a[0].c_str(), argc, NULL, value, length, binary, 0);
testSQL(res);
print();
- clog<<"exec() finish\n";
+ clog<<"exec(vector<string>) finish\n";
}
inline int sqlpg::testSQL(PGresult* a){
if (!((PQresultStatus(a) == PGRES_COMMAND_OK)||(PQresultStatus(a) == PGRES_TUPLES_OK)))
bool sqlpg::alias(vector<string> 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};
}
string cmd2;
cmd2=PQgetvalue(res, 0, 0);
- clog<<"cmd2="<<cmd2<<endl;
+ inf=PQgetvalue(res, 0, 2);
+ clog<<"cmd2="<<cmd2<<" inf="<<inf<<endl;
int pos=0;
argc=atoi(PQgetvalue(res, 0, 1));
clog<<"argc="<<argc<<endl;
res=PQprepare(conn, "execalias",cmd2.c_str(), argc, NULL);
testSQL(res);
-
+ clog<<"bcl qui tue, inf="<<inf<<"\n";
+ if(1){
+ string b=a[argc+1];
+ int pos=cmd2.find("$$");
+ clog<<"pos="<<pos<<" cmd2="<<cmd2<<"\n";
+ int asize=a.size();
+ for(int i=argc+2;i<asize;i++){
+ b=b+" "+a[i];
+ }
+ clog<<"b="<<b;
+ cmd2.replace(pos, 2, b, 0, string::npos);
+ }
clog<<"for argc="<<argc<<"\n";
for(int i=0; i<argc; i++){
value[i]=a[i+1].c_str();
exec(cmd);
clog<<"exec1("<<cmd<<") PQntuples(res)="<<PQntuples(res)<<endl;
int tuples=PQntuples(res);
- for (int i=0; i<tuples;i++){
+ for (int i=0; i<tuples;i++){// run this for every tuple where analyzed=0
string buf, txt=PQgetvalue(res, i, PQfnumber(res, "texte"));
stringstream ss(txt);
- while (ss >> 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);