From 1541377f7ce577a060cceec8f8031a88ad22c250 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 17 Jun 2025 19:52:10 -0400 Subject: [PATCH] Starting to implement maysql/mariadb code --- lib/subrou.h | 4 ++-- lib/unimar.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/subrou.h b/lib/subrou.h index 9eb2f29..f4cf8fb 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -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 *); diff --git a/lib/unimar.c b/lib/unimar.c index 102949d..0db31c0 100644 --- a/lib/unimar.c +++ b/lib/unimar.c @@ -5,8 +5,12 @@ /* to handle POSTGRES SQL request */ /* */ /********************************************************/ +#include #include - +#include +#include +#include +#include #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 -- 2.47.3