]> SAFE projects GIT repository - jmp/mailleur/commitdiff
ready to check database record insert command
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 29 Jun 2025 02:16:31 +0000 (22:16 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 29 Jun 2025 02:16:31 +0000 (22:16 -0400)
lib/devsql.c
lib/devsql.h
lib/lvleml.c
lib/unimar.c
lib/unimar.h
lib/unipos.c
lib/unipos.h

index 9bf939b6db1401e53034d5efdcba3648b1522c33..be443413392a9a904cb540d40f8dfd5ba5e626a9 100644 (file)
@@ -32,9 +32,10 @@ typedef struct  {
         }SQLTYP;
 
 //SQL database request
-#define EMAILS  "emails"        //emails tables
+#define EMAILS          "emails"        //emails tables
+#define SESSIONS        "sessions"      //session tabbles
 
-//field available in table "EMAILS"
+//field available in table "emails"
 const char *usrfield[]={
           "email",
           "password",
@@ -44,6 +45,15 @@ const char *usrfield[]={
           (char *)0
           };
 
+//field available in table "sessions"
+const char *sesfield[]={
+          "sessid",
+          "sessfrom",
+          "emailfrom",
+          "taille",
+          (char *)0
+          };
+
 /*
 \f
 */
@@ -184,8 +194,8 @@ return numrow;
 */
 /********************************************************/
 /*                                                      */
-/*      Procedure to create a data request and submit it*/
-/*      to the proper database daemon.                  */
+/*      Procedure to create a data search request and   */
+/*      submit it to the to the proper database daemon. */
 /*                                                      */
 /********************************************************/
 static SQLRES *gettupple(SQLTYP *sql,const char *fmt,...)
@@ -217,6 +227,46 @@ if ((rou_vasprintf(&cmd,fmt,args))>0) {
 va_end(args);
 return rs;
 
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to do some action to change database  */
+/*      contents.                                       */
+/*                                                      */
+/********************************************************/
+static int sqlrequest(SQLTYP *sql,const char *fmt,...)
+
+{
+#define OPEP    "devsql.c:sqlrequest,"
+
+int number;
+va_list args;
+char *cmd;
+
+number=-1;
+va_start(args,fmt);
+if ((rou_vasprintf(&cmd,fmt,args))>0) {
+  switch(sql->sqldb) {
+    case db_postgres    :
+      number=pos_request(sql->db.psql,cmd);
+      break;
+    case db_maria       :
+      number=mar_request(sql->db.msql,cmd);
+      break;
+    default             :
+      (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
+                          OPEP,(int)sql->sqldb);
+      break;
+    }
+  (void) free(cmd);
+  }
+va_end(args);
+return number;
+
 #undef  OPEP
 }
 /*
@@ -336,6 +386,29 @@ while (proceed==true) {
 return usr;
 
 #undef  SELUSR
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to create a new session contents      */
+/*                                                      */
+/********************************************************/
+static _Bool insert_ses(SQLTYP *sql,char *seskey,SESTYP **ses)
+
+{
+#define OPEP    "devseql.c:insert_ses,"
+#define INSSES  "INSERT INTO "SESSIONS" (sessid) VALUES(%s)"
+
+_Bool isok;
+
+isok=true;
+(void) rou_alert(0,"%s JMPDBG Insertin session <%s>",OPEP,seskey);
+isok=(sqlrequest(sql,INSSES,seskey)==1);
+return isok;
+
 #undef  OPEP
 }
 /*
@@ -580,7 +653,7 @@ while (proceed==true) {
         phase=999;
         }
       if ((gooddata=sql_gooddata(sql,email))==(char *)0) {
-        (void) rou_alert(0,"%s %s table, key <%s> not acceptable!",
+        (void) rou_alert(0,"%s %s table, key <%s> is empty (Bug?!)",
                             OPEP,EMAILS,email);
         phase=999;
         }
@@ -606,3 +679,61 @@ return isok;
 
 #undef  OPEP
 }
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to manage  information about email    */
+/*      exchange session.                               */
+/*                                                      */
+/********************************************************/
+PUBLIC _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,char *seskey,SESTYP **ses)
+
+{
+#define OPEP    "devsql.c:sql_mngses,"
+
+_Bool isok;
+char *gooddata;
+SQLTYP *sql;
+int phase;
+_Bool proceed;
+
+isok=false;
+gooddata=(char *)0;
+sql=(SQLTYP *)sqlptr;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //checking SQL
+      if (sql==(SQLTYP *)0) {
+        (void) rou_alert(0,"%s SQL pointer is NUll (Bug?)",OPEP);
+        phase=999;
+        }
+      if ((gooddata=sql_gooddata(sql,seskey))==(char *)0) {
+        (void) rou_alert(0,"%s %s table, key <%s> is empty (Bug?!)",
+                            OPEP,SESSIONS,seskey);
+        phase=999;
+        }
+      break;
+    case 1      :       //getting user information
+      switch (action) {
+        case sql_insert :
+          isok=insert_ses(sql,gooddata,ses);
+          break;
+        default :
+          (void) rou_alert(0,"%s action='%d' not yet implemented!",OPEP,action);
+        }
+      gooddata=rou_freestr(gooddata);
+      break;
+    default     :
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return isok;
+
+#undef  OPEP
+}
index 785e7e50bbb792d52c1cbe1b118b53a7f3e3353a..65b7b84c40fbfaba1c070ffd61955de62fd3e628 100644 (file)
@@ -23,7 +23,10 @@ extern SQLPTR *sql_closesql(SQLPTR *sqlptr);
 //as key search by database
 extern char *sql_gooddata(SQLPTR *sqlptr,char *key);
 
-//procedure to get information on exiting user
+//procedure to manage information on exiting user
 extern _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *email,USRTYP **usr);
 
+//procedure to manage information on email exchange session
+extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,char *seskey,SESTYP **ses);
+
 #endif
index 6812c2eebf9aaa370a06d7a130572cb46eb6dcba..7e9f70d395861f619d3af1211a11f927763b0f64 100644 (file)
@@ -38,9 +38,13 @@ static void getsessid(CONTYP *contact)
 
 {
 if (contact!=(CONTYP *)0) {
+  char *newsid;
+
+  newsid=eml_getcursesid(contact->mainsesid,contact->numreset);
   contact->session=sql_freeses(contact->session);
   contact->session=(SESTYP *)calloc(1,sizeof(SESTYP));
-  contact->session->sessid=eml_getcursesid(contact->mainsesid,contact->numreset);
+  contact->session->sessid=newsid;
+  (void) sql_mngses(contact->sqlptr,sql_insert,newsid,&(contact->session));
   }
 }
 /*
index 8dfa2e595d537404dcb9cd49e2c308d1685084e6..103a7b3d11ad89f08d8650e5c22de2d422f248cc 100644 (file)
@@ -310,4 +310,36 @@ return numrow;
 
 #undef  OPEP
 }
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to request an action (insert,update   */
+/*      delete) to the database.                        */
+/*      return the number of tupple affected by the     */
+/*      command.                                        */
+/*                                                     */
+/********************************************************/
+PUBLIC int mar_request(MARPTR *marptr,char *command)
+
+{
+#define OPEP    "unipos.c:pos_action,"
+
+int number;
 
+number=-1;
+#ifdef  DB_MYSQL
+  {
+  register MYSQL *ms;
+
+  ms=(MYSQL *)marptr;
+  if (mysql_query(ms,command)==0) 
+    number=mysql_affected_rows(ms);
+  else
+    (void) rou_alert(0,"%s pid='%05d' Unable to carry cmd=<%s>, error=<%s>",
+                        OPEP,getpid(),command,mysql_error(ms));
+  }
+#endif
+return number;
+}
index c22ab03ad42522bfc61a5fb85810d61338c1bb13..f46a7f0e0ff416cc9f7f483900b384047a9a5fa4 100644 (file)
@@ -38,4 +38,8 @@ extern MARRES *mar_gettupple(MARPTR *marptr,char *command);
 //procedure to return the number of entry within a result
 extern int mar_nbrtupple(MARRES *marres);
 
+//procedure to submit an action (insert,update,delete)
+//to a MySAL  database
+extern int mar_request(MARPTR *marptr,char *command);
+
 #endif
index f26011110c30670f67efa440e6c159af7d4483e3..640e592deafcfde8d3195876c03238ebeb143693 100644 (file)
@@ -306,7 +306,7 @@ return posres;
 */
 /********************************************************/
 /*                                                     */
-/*     Procedure to retunr the number of tupple related*/
+/*     Procedure to return the number of tupple related*/
 /*      related to a previous search.                   */
 /*                                                     */
 /********************************************************/
@@ -321,3 +321,47 @@ numrow=PQntuples((PGresult *)posres);
 #endif
 return numrow;
 }
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to request an action (insert,update   */
+/*      delete) to the database.                        */
+/*      return the number of tupple affected by the     */
+/*      command.                                        */
+/*                                                     */
+/********************************************************/
+PUBLIC int pos_request(POSPTR *posptr,char *command)
+
+{
+#define OPEP    "unipos.c:pos_action,"
+
+int number;
+
+number=-1;
+#ifdef  DB_POSTGRESQL
+  {
+  register PGconn *pf;
+  PGresult *pgstat;
+
+  pf=(PGconn *)posptr;
+  if ((pgstat=request((PGconn *)pf,command))!=(PGresult *)0) {
+    switch (PQresultStatus(pgstat)) {
+      case PGRES_COMMAND_OK       :
+        number=atoi(PQcmdTuples(pgstat));
+        break;
+      default                     : 
+        (void) rou_alert(0,"%s Command <%s> failed, (error=<%s> pgstatut='%d')",
+                            OPEP,command,PQerrorMessage(pf),
+                            PQresultStatus(pgstat));
+        break;
+      }
+    (void) PQclear(pgstat);
+    }
+  }
+#endif
+return number;
+
+#undef  OPEP
+}
index 8bb29949e1b42db0972ab9a3ee8f5baafb5cda48..e57a18ff0568a7196ab7f149c2860b6987b2abb1 100644 (file)
@@ -32,10 +32,14 @@ extern char *pos_getfield(POSRES *rs,int tuple,int position);
 //procedure to extract specific field value within database
 extern char *pos_getvalue(POSRES *rs,int tuple,const char *fieldname);
 
-//procedure to extract data from database
+//procedure to extract data from postgresql database
 extern POSRES *pos_gettupple(POSPTR *posptr,char *command);
 
 //procedure to return the number of entry within a result
 extern int pos_nbrtupple(POSRES *posres);
 
+//procedure to submit an action (insert,update,delete)
+//to a postgresql database
+extern int pos_request(POSPTR *posptr,char *command);
+
 #endif