]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to implement maysql/mariadb code
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 17 Jun 2025 23:52:10 +0000 (19:52 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Tue, 17 Jun 2025 23:52:10 +0000 (19:52 -0400)
lib/subrou.h
lib/unimar.c

index 9eb2f2988812894b4363976476d66d97c41f9db4..f4cf8fb63dd326c9e0752322368722cd6d27f21f 100644 (file)
@@ -20,8 +20,8 @@
 #define ITSOK   0               //to check errno against no error
 
 //defining database #define
-#define POSTGRESQL      1
-#define MYSQL           2
+//#define USE_POSTGRESQL  1
+//#define USE_MYSQL       2
 
 typedef void (*genfree_t)(void *);
 
index 102949d6ca768101999ef79c694e8cd7b757e15f..0db31c02ac0f863950821e17f139c0fe0cf8fafc 100644 (file)
@@ -5,8 +5,12 @@
 /*     to handle POSTGRES SQL request                  */
 /*                                                     */
 /********************************************************/
+#include        <pwd.h>
 #include        <stdio.h>
-
+#include        <stdlib.h>
+#include        <unistd.h>
+#include        <mysql/mysql.h>
+#include        <sys/types.h>
 
 #include        "subrou.h"
 #include        "unimar.h"
@@ -34,7 +38,29 @@ MARPTR *marptr;
 
 marptr=(MARPTR *)0;
 #ifdef  DB_MYSQL
-  (void) fprintf(stderr,"%s not yet implemented\n",OPEP);
+  {
+  struct passwd *pw;
+  MYSQL *mysql;
+  int port;
+
+  if ((pw=getpwuid(geteuid()))==(struct passwd *)0) {
+    (void) rou_core_dump("%s is unable to find name for uid '%s'",
+                          OPEP,geteuid());
+    //never ever REACHED
+    }
+  mysql=mysql_init((MYSQL *)0);
+  port=0;
+  if (sqlport!=(char *)0)
+    port=atoi(sqlport);
+  if (mysql_real_connect(mysql,host,pw->pw_name,(char *)0,dbname,port,
+                         (char *)0,CLIENT_FOUND_ROWS)==(MYSQL *)0) {
+    (void) rou_alert(0,"%s Connection to database '%s' failed, cause '%s'",
+                       OPEP,dbname,mysql_error(mysql));
+    (void) free(mysql);
+    mysql=(MYSQL *)0; 
+    }
+  marptr=(MARPTR *)mysql;
+  }
 #else
   (void) fprintf(stderr,"%s not compiled to be used with mysql\n",OPEP);
 #endif
@@ -56,10 +82,11 @@ MARPTR *mar_closesql(MARPTR *marptr)
 #define OPEP    "sqlmar.c:mar_closesql,"
 
 #ifdef  DB_MYSQL
-  (void) fprintf(stderr,"%s not yet implemented\n",OPEP);
+  (void) mysql_close(MYSQL *marptr);
 #else
   (void) fprintf(stderr,"%s not compiled to be used with mysql\n",OPEP);
 #endif
+marptr=(MARPTR *)0;
 return marptr;
 
 #undef  OPEP