From 8c4b4f0fd3330bce5eebbe40ea1486a0f1202f8e Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Fri, 11 Jul 2025 16:29:35 -0400 Subject: [PATCH] lock and unlock are working on mysql/mariadb database --- Makefile | 9 ++++--- conf/mailleur.conf.dvl | 8 +++++-- lib/gessql.c | 2 +- lib/unimar.c | 53 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 1d59772..8193573 100644 --- 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 diff --git a/conf/mailleur.conf.dvl b/conf/mailleur.conf.dvl index 80a6902..81240f3 100644 --- a/conf/mailleur.conf.dvl +++ b/conf/mailleur.conf.dvl @@ -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" diff --git a/lib/gessql.c b/lib/gessql.c index 465cb3f..12ea334 100644 --- a/lib/gessql.c +++ b/lib/gessql.c @@ -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; diff --git a/lib/unimar.c b/lib/unimar.c index 487543d..af502f3 100644 --- a/lib/unimar.c +++ b/lib/unimar.c @@ -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; -- 2.47.3