]> git.nothing2do.fr Git - diary-shell.git/commitdiff
first release
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Fri, 14 Jun 2013 12:21:06 +0000 (14:21 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Fri, 14 Jun 2013 12:21:06 +0000 (14:21 +0200)
Notes.txt [new file with mode: 0644]
cp-bin.sh [new file with mode: 0755]
diary-shell [new file with mode: 0755]
howto-compile-alwaysdata.com.sh [new file with mode: 0755]
howto-compile-openbsd [new file with mode: 0755]
howto-compile.sh [new file with mode: 0755]
main.cpp [new file with mode: 0644]
tables1.sql [new file with mode: 0755]
test-diary-shell.sh [new file with mode: 0755]

diff --git a/Notes.txt b/Notes.txt
new file mode 100644 (file)
index 0000000..64c892d
--- /dev/null
+++ b/Notes.txt
@@ -0,0 +1,11 @@
+Procédure de compilation en ligne de commande :
+g++ main.cpp sqldb.cpp -o sqlDB -L /opt/PostgreSQL/9.2/lib -lpq
+où -L est l'indicateur du répertoire où se trouve la librairie libpq.so
+et où -lpq indique le nom de la librairie (libpq.so) : -l est l'indicateur de la librairie et pq le nom de la librairie à laquelle on enlève lib et l'extension .so (.a sous d'autres OS)
+Pour exécuter le programme sqlDB il suffit de lancer la commande ./sqlDB sans paramètres (et les paramètres par défaut seront utilisés) ou :
+./sqlDB localhost 5433 base01 bernard mz182001 10 si on indique TOUS les paramètres.
+Ce sont bien sûr mes paramètres et le résultat est :
+Début du programme './sqlDB'. Nombre de paramètres reçus : 7
+Chaîne de connection: host=localhost port=5433 dbname=base01 user=bernard password=mz182001 connect_timeout=10
+La connection à la base est Ok
+Fin du programme
diff --git a/cp-bin.sh b/cp-bin.sh
new file mode 100755 (executable)
index 0000000..a864c2a
--- /dev/null
+++ b/cp-bin.sh
@@ -0,0 +1 @@
+cp diary-shell /usr/local/bin/
diff --git a/diary-shell b/diary-shell
new file mode 100755 (executable)
index 0000000..0b9ecbc
Binary files /dev/null and b/diary-shell differ
diff --git a/howto-compile-alwaysdata.com.sh b/howto-compile-alwaysdata.com.sh
new file mode 100755 (executable)
index 0000000..a796805
--- /dev/null
@@ -0,0 +1,2 @@
+rm ~/diary-shell
+g++ main.cpp ../sqldb.cpp -o ~/diary-shell -I/usr/include/postgresql/ -I.. -lpq
diff --git a/howto-compile-openbsd b/howto-compile-openbsd
new file mode 100755 (executable)
index 0000000..34d4e4c
--- /dev/null
@@ -0,0 +1,2 @@
+#g++ main.cpp -I/usr/local/include/postgresql/
+g++ main.cpp sqldb.cpp -o diary-shell -L /usr/local/lib -I/usr/local/include/postgresql -lpq
diff --git a/howto-compile.sh b/howto-compile.sh
new file mode 100755 (executable)
index 0000000..2b3a7c7
--- /dev/null
@@ -0,0 +1,2 @@
+rm diary-shell
+g++ main.cpp ../sqldb.cpp -o diary-shell -L /usr/lib -I/usr/include/postgresql -I.. -lpq -fpermissive
diff --git a/main.cpp b/main.cpp
new file mode 100644 (file)
index 0000000..c03a134
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,84 @@
+// main.cpp
+#include <iostream>
+#include "sqldb.h"
+#include <sstream>
+#include <cstdlib>
+
+using namespace std;
+string date(string a)//transform any date format (in help) to "YYYY-MM-DD HH:MM:SS.XXXXXX"
+{
+    /*int y[4], m, d, h, m, s, x;
+    stringstream ss(a);
+    ss>>y>>"-">>m>>"-">>d>>" ">>h>>":">>m>>":">>s>>".">>x;
+    return ss.str();*/
+}
+void help()
+{
+
+    cout<<"command : var, now, ls, rm {n°}, rm date1 date2, status, date {arg}, help, alias (-/+list/+add),\n";
+    cout<<"select SQL command, \"SQL select\"\n";
+}
+
+
+
+int main(int argc, char *argv[])
+{
+    cout << "Début du programme '" << argv[0] << "'. Nombre de paramètres reçus : " << argc  << endl;
+    sqlpg diary;
+    string tmp, rep, shell="? ";
+    int hm;
+do{
+    hm=diary.hmRecord();
+    cout<<hm<<shell;
+    getline(cin,rep,'\n');
+    string buf; // Have a buffer string
+    vector<string> words; // Create vector to hold our words
+    stringstream ss(rep); // Insert the string into a stream
+    //cut rep into words[0], words[1], ...
+    while (ss >> buf) words.push_back(buf);
+    if(words.size()==0)break;//quit
+    else if (words[0]=="w") diary.exec(words);
+    else if (words[0]=="p") diary.print();
+    else if (words[0]=="help") help();
+    else if (words[0]=="status") diary.status();
+    else if (words[0]=="rm"){// little useless
+        if (words.size()==2){// cmd : rm "id"
+            diary.deletetuple(words[1]);
+        }
+        else if (words.size()==3){// cmd : rm "date1" "date2"
+            string date1=words[1], date2=words[2];
+            diary.deletedate(date1, date2);
+        }
+    }
+    else if (words[0]=="var") diary.var();
+    else if (words[0]=="now") cout<<now()<<endl;
+    else if (words[0]=="alias") {
+        if (words.size()==1) {diary.exec("select nom from alias;");diary.print();}
+        else if (words[1]=="add") {
+            string cmd="";
+            for (int a=3; a<words.size()-1; a++){
+                cmd=cmd+words[a]+" ";
+            }
+            cmd=cmd+words[words.size()-1];
+            diary.exec("insert into alias (nom, command) values ( '"+words[2]+"', '"+cmd+"' );");
+        }
+        else if (words[1]=="list") {diary.exec("select * from alias;");diary.print();}
+    }
+    else if (words[0]=="ls") {diary.exec("select id,texte from raw order by date asc;");diary.print();}
+
+    else if (words[0]=="!") {
+        string a=rep.substr(2);
+        diary.exec(a);
+        diary.print();
+    }
+    /* alias (select command from alias where 'nom'=string */
+    else if (diary.alias(words));
+    else {
+        diary.insert(words);
+
+    }
+    words.clear();
+}while(1);
+cout<<"Fin du programme\n";
+return 0;
+}
diff --git a/tables1.sql b/tables1.sql
new file mode 100755 (executable)
index 0000000..8a6e5ff
--- /dev/null
@@ -0,0 +1,22 @@
+--drop database if exists bob;
+--CREATE DATABASE bob OWNER bernard;
+drop table if exists words;
+create table words (
+id serial,
+time integer,
+txt text
+); 
+drop table if exists alias;
+create table alias (
+id serial primary key,
+command text,
+nom text
+); 
+drop table if exists raw;
+create table raw (
+id serial primary key,
+date timestamp,
+analyzed bit(1),
+texte text
+);
+
diff --git a/test-diary-shell.sh b/test-diary-shell.sh
new file mode 100755 (executable)
index 0000000..61801e0
--- /dev/null
@@ -0,0 +1 @@
+sudo -u bob ./diary-shell