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');
clog<<"SQL statement="<<cmd<<endl;
res=PQprepare(conn, "selectalias", cmd.c_str(), 2, NULL);
testSQL(res);
-
}
int sqlpg::status(){
}
int sqlpg::insert(vector<string> text) {
clog<<"insert(vector<string>) begin\n";
+
+
string command="INSERT INTO raw (date, texte) VALUES ($1::timestamp, $2::text);";
string tmp="";
int argc=2;
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";
};
clog<<"hmRecord()="<<a<<endl;
return a;
}
-void sqlpg::var(){
- cout<<"date="<<date<<", chaîne de connection: " + connect << endl;;
+void sqlpg::printvar(){
+ cout<<"date="<<date<<", chaîne de connection: " + connect << endl;
+ for(map<string, string>::iterator i=value.begin(); i!=value.end(); ++i){
+ cout<<"value["<<i->first<<"]="<<i->second<<endl;
+ }
}
sqlpg::~sqlpg() {
PQclear(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, j)<<value.find("hs")->second;
};
cout<<PQgetvalue(res, i, lim-1);
- if(i<l-1)cout<<"|";
+ if(i<l-1)cout<<value.find("vs")->second;
};
-cout<<endl;
+ cout<<endl;
}
void sqlpg::exec(string a){
clog<<"exec(string["<<a<<"])\n";
//ex ec(y.str()); it don't works and i don't know why
}
};
+void sqlpg::getvar(){
+ clog<<"getvar\n";
+ exec("select nom,value from var;");
+ int l=PQntuples(res);
+ for (int i=0; i<l; i++){
+ string a, b;
+ a=PQgetvalue(res, i, 0);
+ b=PQgetvalue(res, i, 1);
+ value.insert(pair<string, string> (a, b) );
+ };
+ clog<<"value.size="<<value.size();
+};
#endif