From: Jean-Marc Pigeon (Delson) Date: Mon, 16 Jun 2025 22:49:07 +0000 (-0400) Subject: Trying to make dependency to postgresql and mysql database X-Git-Tag: tag-0.9~151 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=572df5962283729ba6477e9370a46289b9aaa180;p=jmp%2Fmailleur Trying to make dependency to postgresql and mysql database --- diff --git a/lib/Makefile b/lib/Makefile index fc428fd..edf6072 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,7 +2,11 @@ #Executable generation area #-------------------------------------------------------------------- debug : toremake - @ $(MAKE) $(PAR) OPTIME="-g -DMODEDEBUG" objs + @ $(MAKE) \ + $(PAR) \ + DATABASE=$(DATABASE) \ + OPTIME="-g -DMODEDEBUG" \ + objs @ echo "library compiled in '$@' mode, now ready" prod : toremake @@ -136,11 +140,14 @@ toremake: Makefile #-------------------------------------------------------------------- .PHONY: clean #-------------------------------------------------------------------- +#database USED POSQL->Postgresql, MYSQL->mysql|mariadb +DATABASE= MYSQL +#-------------------------------------------------------------------- #definitions #-------------------------------------------------------------------- CC = gcc LD = gcc -CFLAGS = -Wall -D_GNU_SOURCE $(OPTIME) +CFLAGS = -Wall -D_GNU_SOURCE $(OPTIME) -D$(DATABASE) LIBMAIL = libmail.a PAR = -j`/usr/bin/getconf _NPROCESSORS_ONLN` #-------------------------------------------------------------------- diff --git a/lib/unipos.c b/lib/unipos.c index a6af57b..84dd4aa 100644 --- a/lib/unipos.c +++ b/lib/unipos.c @@ -9,6 +9,23 @@ #include "subrou.h" #include "unipos.h" +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to report database is not implemented */ +/* */ +/********************************************************/ +#ifndef POSQL +static void notavail() + +{ +char *cmt="Postgresql Database access is NOT implemented (config?)"; + +(void) rou_alert(0,"%s",cmt); +} +#endif /* */ @@ -23,19 +40,31 @@ PUBLIC POSPTR *pos_opensql(const char *host,const char *sqlport,const char *dbna { #define OPEP "unipos.c:pos_opensql," -PGconn *pf; -char *z; //parameter null +POSPTR *posptr; + +posptr=(POSPTR *)0; +#ifdef POSQL + { + PGconn *pf; + char *z; //parameter null -z=(char *)0; -pf=PQsetdbLogin(host,sqlport,z,z,dbname,z,z); -// Check if the connection is successful -if (PQstatus(pf)!=CONNECTION_OK) { - (void) rou_alert(0,"%s Connection to database '%s' failed, cause '%s'", - OPEP,dbname,PQerrorMessage(pf)); - (void) PQfinish(pf); - pf=(PGconn *)0; + z=(char *)0; + pf=PQsetdbLogin(host,sqlport,z,z,dbname,z,z); + // Check if the connection is successful + if (PQstatus(pf)!=CONNECTION_OK) { + (void) rou_alert(0,"%s Connection to database '%s' failed, cause '%s'", + OPEP,dbname,PQerrorMessage(pf)); + (void) PQfinish(pf); + pf=(PGconn *)0; + } + posptr=(POSPTR *)pf; + } +#else + { + (void) notavail(); } -return (POSPTR *)pf; +#endif +return posptr; #undef OPEP } /* @@ -52,18 +81,27 @@ PUBLIC POSPTR *pos_closesql(POSPTR *posptr) { #define OPEP "unipos.c:pos_closesql," -PGconn *pf; +#ifdef POSQL + { + PGconn *pf; -pf=(PGconn *)posptr; -if (pf==(PGconn *)0) { - (void) rou_alert(0,"%s Database link already closedi (Bug?)",OPEP); - (void) PQfinish(pf); + pf=(PGconn *)posptr; + if (pf==(PGconn *)0) { + (void) rou_alert(0,"%s Database link already closedi (Bug?)",OPEP); + (void) PQfinish(pf); + } + else { + (void) PQfinish((PGconn *)pf); + pf=(PGconn *)0; + } + posptr=(POSPTR *)pf; } -else { - (void) PQfinish((PGconn *)pf); - pf=(PGconn *)0; +#else + { + (void) notavail(); } -return (POSPTR *)pf; +#endif +return posptr; #undef OPEP } diff --git a/lib/unipos.h b/lib/unipos.h index f2436dd..c4a8f2b 100644 --- a/lib/unipos.h +++ b/lib/unipos.h @@ -1,8 +1,8 @@ // vim: smarttab tabstop=8 shiftwidth=2 expandtab /********************************************************/ /* */ -/* base level subroutine declaration */ -/* to handle Postscript SQL request. */ +/* Base level subroutine declaration */ +/* to handle Postgresql SQL request. */ /* */ /********************************************************/ #ifndef UNIPOS