]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Trying to make dependency to postgresql and mysql database
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 16 Jun 2025 22:49:07 +0000 (18:49 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 16 Jun 2025 22:49:07 +0000 (18:49 -0400)
lib/Makefile
lib/unipos.c
lib/unipos.h

index fc428fd732c7459bdf4bb98300e29cf1725354a7..edf6072777dea54df96b7d586113713333f008b0 100644 (file)
@@ -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`
 #--------------------------------------------------------------------
index a6af57baa47744e67d5cfa193815ee01fe195e3a..84dd4aa40bb87d731436155cdde528d11e2e5070 100644 (file)
@@ -9,6 +9,23 @@
 #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) rou_alert(0,"%s",cmt);
+}
+#endif
 /*
 \f
 */
@@ -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
 }
 
index f2436ddfb2e2183d6a8d9ee3547a3ab15bd031dc..c4a8f2bb124e5c4b0702dd3414b757b2859d2d7c 100644 (file)
@@ -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