From e36d142a6a8173c262ca3f5f7652d7a68ed84472 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Mon, 16 Jun 2025 20:24:26 -0400 Subject: [PATCH] Simplify the shared unisql and unipos code --- lib/Makefile | 6 ++-- lib/unipos.c | 78 ++++++++++++++-------------------------------------- lib/unisql.c | 38 ++----------------------- 3 files changed, 25 insertions(+), 97 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 6742bc2..aa147a7 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -29,6 +29,7 @@ libposql: unipos.o libmysql: unisql.o $(CC) -shared -Wl,-soname,$@.so.1 -o $@.so.1.0 unisql.o +#-------------------------------------------------------------------- unipos.o: unipos.h $(CC) $(CFLAGS) -c -fPIC -o $@ unipos.c @@ -159,14 +160,11 @@ toremake: Makefile #-------------------------------------------------------------------- .PHONY: clean #-------------------------------------------------------------------- -#database USED POSQL->Postgresql, MYSQL->mysql|mariadb -DATABASE= POSQL -#-------------------------------------------------------------------- #definitions #-------------------------------------------------------------------- CC = gcc LD = gcc -CFLAGS = -Wall -D_GNU_SOURCE $(OPTIME) -D$(DATABASE) +CFLAGS = -Wall -D_GNU_SOURCE $(OPTIME) LIBMAIL = libmail.a PAR = -j`/usr/bin/getconf _NPROCESSORS_ONLN` #-------------------------------------------------------------------- diff --git a/lib/unipos.c b/lib/unipos.c index 7903724..820243d 100644 --- a/lib/unipos.c +++ b/lib/unipos.c @@ -10,23 +10,6 @@ #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) fprintf(stderr,"%s\n",cmt); -} -#endif /* */ @@ -41,31 +24,19 @@ PUBLIC POSPTR *pos_opensql(const char *host,const char *sqlport,const char *dbna { #define OPEP "unipos.c:pos_opensql," -POSPTR *posptr; - -posptr=(POSPTR *)0; -#ifdef POSQL - { - PGconn *pf; - char *z; //parameter null +char *z; //parameter null +PGconn *pf; - 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(); +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; } -#endif -return posptr; +return (POSPTR *)pf; #undef OPEP } /* @@ -82,27 +53,18 @@ PUBLIC POSPTR *pos_closesql(POSPTR *posptr) { #define OPEP "unipos.c:pos_closesql," -#ifdef POSQL - { - PGconn *pf; +PGconn *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; +pf=(PGconn *)posptr; +if (pf==(PGconn *)0) { + (void) rou_alert(0,"%s Database link already closedi (Bug?)",OPEP); + (void) PQfinish(pf); } -#else - { - (void) notavail(); +else { + (void) PQfinish((PGconn *)pf); + pf=(PGconn *)0; } -#endif -return posptr; +return (POSPTR *)pf; #undef OPEP } diff --git a/lib/unisql.c b/lib/unisql.c index 80b2cc4..235cdfc 100644 --- a/lib/unisql.c +++ b/lib/unisql.c @@ -10,23 +10,6 @@ #include "subrou.h" #include "unisql.h" -/* - -*/ -/********************************************************/ -/* */ -/* Procedure to report database is not implemented */ -/* */ -/********************************************************/ -#ifndef MYSQL -static void notavail() - -{ -char *cmt="Postgresql Database access is NOT implemented (config?)"; - -(void) fprintf(stderr,"%s\n",cmt); -} -#endif /* */ @@ -44,15 +27,7 @@ PUBLIC SQLPTR *sql_opensql(const char *host,const char *sqlport,const char *dbna SQLPTR *sqlptr; sqlptr=(SQLPTR *)0; -#ifdef MYSQL - { - (void) fprintf(stderr,"%s\n","To be implemented"); - } -#else - { - (void) notavail(); - } -#endif +(void) fprintf(stderr,"%s\n","To be implemented"); return sqlptr; #undef OPEP } @@ -70,16 +45,9 @@ PUBLIC SQLPTR *sql_closesql(SQLPTR *sqlptr) { #define OPEP "sqlpos.c:sql_closesql," -#ifdef MYSQL - { - (void) fprintf(stderr,"%s\n","To be implemented"); - } -#else - { - (void) notavail(); - } -#endif +(void) fprintf(stderr,"%s\n","To be implemented"); return sqlptr; + #undef OPEP } -- 2.47.3