]> git.nothing2do.fr Git - diary-shell/commitdiff
lot of error, I give up
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Tue, 23 Jul 2013 11:36:23 +0000 (13:36 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Tue, 23 Jul 2013 11:36:23 +0000 (13:36 +0200)
main.cpp
sqldb.cpp
tables1.sql

index b2bd31eb46e166a199ba1b30017568e60a3312ee..e80db5519fc87a50c57c0c18374b8da3dd771459 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -55,11 +55,11 @@ do{
     }
     else if (diary.alias(words));
     else {
-        std::vector<int> myvector (3,100);
-        vector<string>::iterator it;
+        /*vector<string>::iterator it;
         it = words.begin();
         it = words.insert ( it , "default");
-        diary.alias(words);
+        diary.alias(words);*/
+        diary.insert(words);
     }
     words.clear();
 }while(1);
index 2953cd9ca4b854d63e143ad278a53ba04fc7af80..327f0aac58e1e95571485f873c21044871a87b8e 100644 (file)
--- a/sqldb.cpp
+++ b/sqldb.cpp
@@ -17,12 +17,11 @@ sqlpg::sqlpg() {
     //conn =  PQconnectStart(var.c_str());
     conn =  PQconnectdb(connect.c_str());
     clog<<"prepare SQL statement\n";
-    string cmd="select cmd,argc,inf from alias where ((nom = $1) and (argc = $2)) OR ((nom = $1) and (inf='1') and (argc < $2));";
+    string cmd="select cmd,argc,inf from alias where ((nom = $1) and (argc = $2)) OR ((nom = $1) and (inf<>0) and (argc < $2));";
     clog<<"SQL statement="<<cmd<<endl;
     res=PQprepare(conn, "selectalias", cmd.c_str(), 2, NULL);
     testSQL(res);
 }
-
 int sqlpg::status(){
     string err=toString(PQstatus(conn));
     switch(PQstatus(conn)) {
@@ -111,19 +110,19 @@ int sqlpg::insert(vector<string> text) {
     else {
         clog<<"text.size()<2\n";
         tmp=text[0];
-        string a="now";
+        a="now";
         value[0]=a.c_str();
         length[0]=a.size();
         binary[0]=0;
-        for (int a=0;a<text.size(); a++){
-            tmp=tmp+" "+text[a];
+        for (int i=1;i<text.size(); i++){
+            tmp=tmp+" "+text[i];
         }
         value[1]=tmp.c_str();
         length[1]=tmp.size();
         binary[1]=0;
-        value[1]=a.c_str();
+        /*value[1]=a.c_str();
         length[1]=a.size();
-        binary[1]=0;
+        binary[1]=0;*/
         clog<<"text.size()<2 finish\n";
     };
     res=PQexecPrepared(conn, "insert", argc, value, length, binary, 0);
@@ -131,7 +130,6 @@ int sqlpg::insert(vector<string> text) {
     clog<<"insert(vector<string>) end\n";
     return 0;
 }
-
 string sqlpg::now(int day){//day=0 return only HH:MM:SS, day=1 return YYYY-MM-DD HH:MM:SS, day=2 YYYY-MM-DD
 // current date/time based on current system
    time_t now = time(0);
@@ -241,7 +239,8 @@ inline int sqlpg::testSQL(PGresult* a){
 bool sqlpg::alias(vector<string> a){
     clog<<"alias start here\n";
     string nom=a[0], as=toString(a.size()-1), i;
-    int argca=2, inf=0;
+    int argca=2;
+    bool inf=0;
     const char *valuea[2]={nom.c_str(), as.c_str()};
     int lengtha[2]={nom.size(), as.size()};
     int binarya[2]={0, 0};
@@ -253,7 +252,7 @@ bool sqlpg::alias(vector<string> a){
     }
     string cmd2;
     cmd2=PQgetvalue(res, 0, 0);
-    clog<<"commande : "<<cmd2<<endl;
+    clog<<"alias()->commande : "<<cmd2<<endl;
     i=PQgetvalue(res, 0, 2);
     int argc=atoi(PQgetvalue(res, 0, 1));
     if (i!="0")inf=1;
@@ -283,9 +282,9 @@ bool sqlpg::alias(vector<string> a){
         clog<<"for infinite finish t="<<t<<endl;
         value[argc-inf]=t.c_str();
         length[argc-inf]=t.size();
-        binary[argc-inf]=0;
+        binary[inf-inf]=0;
     }
-    clog<<"if(inf=1) finish\n";
+    clog<<"if(inf!=0) finish\n";
     for(int k=0; k<(argc+inf); k++){
         clog<<"value["<<k<<"]="<<value[k]<<" length="<<length[k]<<"\n";
     }
index fc2a63e7a50420a1da7906a2317adad59f09e359..cc378c5281560ae492543a31619c841c6bc30b4c 100755 (executable)
@@ -12,7 +12,7 @@ cmd text,
 help text,
 argc integer,
 nom text,
-inf bit DEFAULT '0',
+inf integer DEFAULT 0,
 CONSTRAINT uc_aliasID UNIQUE (nom, argc)
 );