From 41fb389220a48bd4d2bfb1c49e0fd411cdf17da8 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Fri, 11 Jul 2025 15:41:28 -0400 Subject: [PATCH] pos_lock and pos_unlock seems to be working --- lib/devsql.c | 28 ++++++++++++++++++++++++++-- lib/devsql.h | 2 +- lib/unimar.c | 26 ++++++++++++++++++++++++++ lib/unimar.h | 3 +++ lib/unipos.c | 37 +++++++++++++++++++++++++++++++++++-- lib/unipos.h | 5 ++++- 6 files changed, 95 insertions(+), 6 deletions(-) diff --git a/lib/devsql.c b/lib/devsql.c index 89c016a..1a627e5 100644 --- a/lib/devsql.c +++ b/lib/devsql.c @@ -287,10 +287,34 @@ return locked; /* specific database table. */ /* */ /********************************************************/ -PUBLIC int sql_unlock(SQLPTR *sqlptr,_Bool commit) +PUBLIC _Bool sql_unlock(SQLPTR *sqlptr,_Bool commit) { -return 1; +#define OPEP "devsql.c:sql_unlock," + +_Bool unlocked; + +unlocked=false; +if (sqlptr!=(SQLPTR *)0) { + SQLTYP *sql; + + sql=(SQLTYP *)sqlptr; + switch(sql->sqldb) { + case db_postgres : + unlocked=pos_unlock(sql->db.psql,commit); + break; + case db_maria : + unlocked=mar_unlock(sql->db.psql,commit); + break; + default : + (void) rou_alert(0,"%s Unexpected db type='%d' (BUG!?)", + OPEP,(int)sql->sqldb); + break; + } + } +return unlocked; + +#undef OPEP } /* diff --git a/lib/devsql.h b/lib/devsql.h index 3fd3635..6ec49d2 100644 --- a/lib/devsql.h +++ b/lib/devsql.h @@ -26,7 +26,7 @@ extern SQLPTR *sql_closesql(SQLPTR *sqlptr); extern _Bool sql_lock(SQLPTR *sqlptr,char *tablename); //procedure to UNLOCK access to a database table -extern int sql_unlock(SQLPTR *sqlptr,_Bool commit); +extern _Bool sql_unlock(SQLPTR *sqlptr,_Bool commit); //procedure to make sure a string is acceptable //as key search by database diff --git a/lib/unimar.c b/lib/unimar.c index 3db99ca..487543d 100644 --- a/lib/unimar.c +++ b/lib/unimar.c @@ -172,6 +172,32 @@ locked=false; #endif return locked; +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* procedure to unlock access to a previously */ +/* locked table within database. */ +/* */ +/********************************************************/ +PUBLIC _Bool mar_unlock(MARPTR *marptr,_Bool commit) + +{ +#define OPEP "unimar.c:mar_unlock," + +_Bool unlocked; + +unlocked=false; +#ifdef DB_MYSQL + { + (void) rou_alert(0,"%s not implemented yet",OPEP); + } +#endif +return unlocked; + #undef OPEP } /* diff --git a/lib/unimar.h b/lib/unimar.h index 5c7a695..ca6b61f 100644 --- a/lib/unimar.h +++ b/lib/unimar.h @@ -26,6 +26,9 @@ extern char *mar_cleanquote(char *sequence); //locking database one table access extern _Bool mar_lock(MARPTR *marptr,char *tablename); +//unlocking the current database table lock access +extern _Bool mar_unlock(MARPTR *marptr,_Bool commit); + //procedure to drop/free all result information extern MARRES *mar_dropresult(MARRES *rs); diff --git a/lib/unipos.c b/lib/unipos.c index cfdd389..ec7fccf 100644 --- a/lib/unipos.c +++ b/lib/unipos.c @@ -217,12 +217,10 @@ locked=false; { static const char *cmd="LOCK TABLE %s IN SHARE ROW EXCLUSIVE MODE"; - PGconn *pf; char fullcmd[300]; int phase; _Bool proceed; - pf=(PGconn *)posptr; (void) snprintf(fullcmd,sizeof(fullcmd),cmd,tablename); phase=0; proceed=true; @@ -256,6 +254,41 @@ locked=false; #endif return locked; +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* procedure to unlock access to a previously */ +/* locked table within database. */ +/* */ +/********************************************************/ +PUBLIC _Bool pos_unlock(POSPTR *posptr,_Bool commit) + +{ +#define OPEP "unipos.c:pos_unlock," + +_Bool unlocked; + +unlocked=false; +#ifdef DB_POSTGRESQL + { + char *cmd; + + unlocked=true; + cmd="ROLLBACK"; + if (commit==true); + cmd="COMMIT"; + if (pos_request(posptr,cmd)<0) { + unlocked=false; + (void) rou_alert(0,"%s Unable to unlock table (Bug?) ",OPEP); + } + } +#endif +return unlocked; + #undef OPEP } /* diff --git a/lib/unipos.h b/lib/unipos.h index a661645..f695869 100644 --- a/lib/unipos.h +++ b/lib/unipos.h @@ -24,7 +24,10 @@ extern POSPTR *pos_closesql(POSPTR *posptr); extern char *pos_cleanquote(char *sequence); //locking database one table access -extern _Bool pos_lock(POSPTR *marptr,char *tablename); +extern _Bool pos_lock(POSPTR *posptr,char *tablename); + +//unlocking the current database table lock access +extern _Bool pos_unlock(POSPTR *posptr,_Bool commit); //procedure to drop/free all result information extern POSRES *pos_dropresult(POSRES *rs); -- 2.47.3