]> SAFE projects GIT repository - jmp/mailleur/commitdiff
lock and unlock are working on mysql/mariadb database
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 11 Jul 2025 20:29:35 +0000 (16:29 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 11 Jul 2025 20:29:35 +0000 (16:29 -0400)
Makefile
conf/mailleur.conf.dvl
lib/gessql.c
lib/unimar.c

index 1d59772a9cbe9bba0675db64bdbf5e19a91f8108..8193573fbf245786139cf606f33acd23b469f001 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -17,9 +17,12 @@ debug                                                        \
               do                                       \
               $(MAKE) DB=$(DB) -s -C $$i $@ ;          \
               done
-          @ ln -nsf rcvrpsql bin/receiver
-          @ ln -nsf sndrpsql bin/sender
-          @ ln -nsf srtrpsql bin/sorter
+          @ #ln -nsf rcvrpsql bin/receiver
+          @ #ln -nsf sndrpsql bin/sender
+          @ #ln -nsf srtrpsql bin/sorter
+          @ ln -nsf rcvrmsql bin/receiver
+          @ ln -nsf sndrmsql bin/sender
+          @ ln -nsf srtrmsql bin/sorter
        
        
 
index 80a6902b44f6f6239c7da02b31df3c493c7b81b1..81240f3dc25530ab1f2f44438c669d9dd600f6d0 100644 (file)
@@ -41,10 +41,14 @@ CA_VERIFY_CLT=0     #to check PEER/server remote certificate
 #------------------------------------------------
 #Configured for Postgresql database
 #DB_TYPE can be either POSTGRESQL,MYSQL, default POSTGRESQL
-DB_TYPE=POSTGRESQL
 DB_NAME=mailleur
 DB_HOST=localhost
-DB_PORT=5432
+DB_LANG="UTF-8"
+#DB_TYPE=POSTGRESQL
+#DB_PORT=5432
+DB_TYPE=MYSQL
+DB_PORT=3306
+
 #------------------------------------------------
 #Dovecot storage directory
 DOV_MAILDIR="/var/spool/mailleur/mails"
index 465cb3f4120bf58e4452f654879cad9e39ae4854..12ea3341461855db39a57d91f6ffe9b279e80a5d 100644 (file)
@@ -602,7 +602,7 @@ while (proceed==true) {
     case 1      :       //record does not exist
       done=false;
       if (sql_lock(sqlptr,RMTTBL)==false) {
-        (void) rou_alert(0,"%s Unable to dbd_lockhard %s table",OPEP,RMTTBL);
+        (void) rou_alert(0,"%s Unable to lock %s table",OPEP,RMTTBL);
         phase=999;      //Unable to lock table
         }      
       break; 
index 487543d3d8eec67ff714d4479f679d852ae55aaa..af502f317629afb3713c6731366f543e9752ff51 100644 (file)
@@ -157,7 +157,7 @@ return cleanstr;
 /*      within database.                                */
 /*                                                     */
 /********************************************************/
-PUBLIC _Bool mar_lock(MARPTR *maerptr,char *tablename)
+PUBLIC _Bool mar_lock(MARPTR *marptr,char *tablename)
 
 {
 #define OPEP    "unimar.c:mar_lock,"
@@ -167,7 +167,41 @@ _Bool locked;
 locked=false;
 #ifdef  DB_MYSQL
   {
-  (void) rou_alert(0,"%s not implemented yet",OPEP);
+  static const char *cmd="LOCK TABLE %s WRITE";
+
+  char fullcmd[300];
+  int phase;
+  _Bool proceed;
+
+  (void) snprintf(fullcmd,sizeof(fullcmd),cmd,tablename);
+  phase=0;
+  proceed=true;
+  while (proceed==true) {
+    (void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase);
+    switch (phase) {
+      case 0    :       //Starting lock
+        if (mar_request(marptr,"BEGIN")<0) {
+          (void) rou_alert(0,"%s Unable to BEGIN to lock table <%s>",
+                              OPEP,tablename);
+          phase=999;    //no need to go further
+          }
+        break;
+      case 1    :       //lock table itself
+        if (mar_request(marptr,fullcmd)<0) {
+          (void) rou_alert(0,"%s Unable to lock table <%s>",
+                              OPEP,tablename);
+          phase=999;    //no need to go further
+          }
+        break;
+      case 2    :       //lock done
+        locked=true;
+        break;
+      default   :       //SAFE Guard
+        proceed=false;
+        break;
+      }
+    phase++;    
+    }
   }
 #endif
 return locked;
@@ -193,7 +227,20 @@ _Bool unlocked;
 unlocked=false;
 #ifdef  DB_MYSQL
   {
-  (void) rou_alert(0,"%s not implemented yet",OPEP);
+  char *cmd;
+
+  unlocked=true;
+  cmd="ROLLBACK";
+  if (commit==true);
+    cmd="COMMIT";
+  if (mar_request(marptr,cmd)<0) {
+    unlocked=false;
+    (void) rou_alert(0,"%s Unable to commit/rollback table (Bug?) ",OPEP);
+    }
+  if (mar_request(marptr,"UNLOCK TABLE")<0) {
+    unlocked=false;
+    (void) rou_alert(0,"%s Unable to unlock table (Bug?) ",OPEP);
+    }
   }
 #endif
 return unlocked;