]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Simplify the shared unisql and unipos code
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 17 Jun 2025 00:24:26 +0000 (20:24 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 17 Jun 2025 00:24:26 +0000 (20:24 -0400)
lib/Makefile
lib/unipos.c
lib/unisql.c

index 6742bc281644919730d6934f00cb454c7e8ed4c9..aa147a71d06bbe9ecac5df676b47251578bf194c 100644 (file)
@@ -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`
 #--------------------------------------------------------------------
index 7903724ad76d22b03a79ef4fae9330e07297ccb3..820243d04788648d217a2636b35c619fd7b356ce 100644 (file)
 #include        "subrou.h"
 #include        "unipos.h"
 
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
-/*      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
 /*
 \f
 */
@@ -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
 }
 
index 80b2cc40372e070622ec53ae543cc43468f15473..235cdfc29a379b741193aa14c186c87b054ab772 100644 (file)
 #include        "subrou.h"
 #include        "unisql.h"
 
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
-/*      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
 /*
 \f
 */
@@ -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
 }