]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Better devsql.c
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 11 Jul 2025 10:43:40 +0000 (06:43 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 11 Jul 2025 10:43:40 +0000 (06:43 -0400)
lib/devsql.c
lib/devsql.h

index 1b54805d13e4c45e3f51d3e496c9912f01af3d89..5fcd3befb77ea0d4e86bb8c52fcf27743bccecce 100644 (file)
@@ -36,74 +36,6 @@ typedef struct  {
 #define EMAILS          "emails"        //emails tables
 #define SESSIONS        "sessions"      //session tables
 
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
-/*      Procedure to drop result issued by a successfull*/
-/*      command.                                        */
-/*                                                      */
-/********************************************************/
-static SQLRES *dropresult(SQLTYP *sql,SQLRES *rs)
-
-{
-#define OPEP    "devsql.c:dropresult,"
-
-if (rs!=(SQLRES *)0) {
-  switch(sql->sqldb) {
-    case db_postgres    :
-      rs=(SQLRES *)pos_dropresult((POSRES *)rs);
-      break;
-    case db_maria       :
-      rs=(SQLRES *)pos_dropresult((MARRES *)rs);
-      break;
-    default             :
-      (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
-                          OPEP,(int)sql->sqldb);
-      rs=(SQLRES *)0;
-      break;
-    }
-  }
-return rs;
-#undef  OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
-/*      Procedure to get the ASCII form of field located*/
-/*      in a specific tuple + name in sqlresult.        */
-/*                                                      */
-/********************************************************/
-static char *getvalue(SQLTYP *sql,SQLRES *rs,int tuple,const char *fieldname)
-
-{
-#define OPEP    "devsql.c:getvalue,"
-
-char *value;
-
-value=(char *)0;
-switch(sql->sqldb) {
-  case db_postgres    :
-    value=pos_getvalue((POSRES *)rs,tuple,fieldname);
-    break;
-  case db_maria       :
-    value=mar_getvalue((MARRES *)rs,tuple,fieldname);
-    break;
-  default             :
-    (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
-                        OPEP,(int)sql->sqldb);
-    break;
-  }
-if (value==(char *)0) {
-  (void) rou_alert(0,"%s value is NULL for field=<%s> (BUG!?)",OPEP,fieldname);
-  value="00000";        //force value!
-  }
-return value;
-#undef  OPEP
-}
 #ifdef GETFIELD
 /*
 \f
@@ -143,79 +75,6 @@ return value;
 */
 /********************************************************/
 /*                                                      */
-/*      Procedure to the number of tupple within a      */
-/*      result issued by a successfull command.         */
-/*                                                      */
-/********************************************************/
-static int nbrtupple(SQLTYP *sql,SQLRES *rs)
-
-{
-#define OPEP    "devsql.c:nbrtupple,"
-
-int numrow;
-
-numrow=0;
-switch(sql->sqldb) {
-  case db_postgres    :
-    numrow=pos_nbrtupple((POSRES *)rs);
-    break;
-  case db_maria       :
-    numrow=mar_nbrtupple((MARRES *)rs);
-    break;
-  default             :
-    (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
-                        OPEP,(int)sql->sqldb);
-    break;
-  }
-return numrow;
-
-#undef  OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
-/*      Procedure to create a data search request and   */
-/*      submit it to the to the proper database daemon. */
-/*                                                      */
-/********************************************************/
-static SQLRES *gettupple(SQLTYP *sql,const char *fmt,...)
-
-{
-#define OPEP    "devsql.c:gettupple,"
-
-SQLRES *rs;
-va_list args;
-char *cmd;
-
-rs=(SQLRES *)0;
-va_start(args,fmt);
-if ((rou_vasprintf(&cmd,fmt,args))>0) {
-  switch(sql->sqldb) {
-    case db_postgres    :
-      rs=(SQLRES *)pos_gettupple(sql->db.psql,cmd);
-      break;
-    case db_maria       :
-      rs=(SQLRES *)mar_gettupple(sql->db.msql,cmd);
-      break;
-    default             :
-      (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
-                          OPEP,(int)sql->sqldb);
-      break;
-    }
-  (void) free(cmd);
-  }
-va_end(args);
-return rs;
-
-#undef  OPEP
-}
-/*
-\f
-*/
-/********************************************************/
-/*                                                      */
 /*      Procedure to create an SQL pointer for proper   */
 /*      database type.                                  */
 /*                                                      */
@@ -486,6 +345,156 @@ if ((rou_vasprintf(&cmd,fmt,args))>0) {
 va_end(args);
 return number;
 
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to get the ASCII form of field located*/
+/*      in a specific tuple + name in sqlresult.        */
+/*                                                      */
+/********************************************************/
+PUBLIC char *sql_getvalue(SQLPTR *sqlptr,SQLRES *rs,int row,const char *name)
+
+{
+#define OPEP    "devsql.c:sql_getvalue,"
+
+char *value;
+SQLTYP *sql;
+
+value=(char *)0;
+sql=(SQLTYP *)sqlptr;
+switch(sql->sqldb) {
+  case db_postgres    :
+    value=pos_getvalue((POSRES *)rs,row,name);
+    break;
+  case db_maria       :
+    value=mar_getvalue((MARRES *)rs,row,name);
+    break;
+  default             :
+    (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
+                        OPEP,(int)sql->sqldb);
+    break;
+  }
+if (value==(char *)0) {
+  (void) rou_alert(0,"%s value is NULL for field=<%s> (BUG!?)",OPEP,name);
+  value="00000";        //force value!
+  }
+return value;
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to create a data search request and   */
+/*      submit it to the to the proper database daemon. */
+/*                                                      */
+/********************************************************/
+PUBLIC SQLRES *sql_gettupple(SQLPTR *sqlptr,const char *fmt,...)
+
+{
+#define OPEP    "devsql.c:sql_gettupple,"
+
+SQLRES *rs;
+SQLTYP *sql;
+va_list args;
+char *cmd;
+
+rs=(SQLRES *)0;
+sql=(SQLTYP *)sqlptr;
+va_start(args,fmt);
+if ((rou_vasprintf(&cmd,fmt,args))>0) {
+  switch(sql->sqldb) {
+    case db_postgres    :
+      rs=(SQLRES *)pos_gettupple(sql->db.psql,cmd);
+      break;
+    case db_maria       :
+      rs=(SQLRES *)mar_gettupple(sql->db.msql,cmd);
+      break;
+    default             :
+      (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
+                          OPEP,(int)sql->sqldb);
+      break;
+    }
+  (void) free(cmd);
+  }
+va_end(args);
+return rs;
+
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to the number of tupple within a      */
+/*      result issued by a successfull command.         */
+/*                                                      */
+/********************************************************/
+PUBLIC int sql_getnbrtupple(SQLPTR *sqlptr,SQLRES *rs)
+
+{
+#define OPEP    "devsql.c:sql_getnbrtupple,"
+
+int numrow;
+
+numrow=0;
+SQLTYP *sql;
+sql=(SQLTYP *)sqlptr;
+switch(sql->sqldb) {
+  case db_postgres    :
+    numrow=pos_nbrtupple((POSRES *)rs);
+    break;
+  case db_maria       :
+    numrow=mar_nbrtupple((MARRES *)rs);
+    break;
+  default             :
+    (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
+                        OPEP,(int)sql->sqldb);
+    break;
+  }
+return numrow;
+
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to drop result issued by a successfull*/
+/*      command.                                        */
+/*                                                      */
+/********************************************************/
+PUBLIC SQLRES *dropresult(SQLPTR *sqlptr,SQLRES *rs)
+
+{
+#define OPEP    "devsql.c:sql_dropresult,"
+
+if (rs!=(SQLRES *)0) {
+  SQLTYP *sql;
+
+  sql=(SQLTYP *)sqlptr;
+  switch(sql->sqldb) {
+    case db_postgres    :
+      rs=(SQLRES *)pos_dropresult((POSRES *)rs);
+      break;
+    case db_maria       :
+      rs=(SQLRES *)pos_dropresult((MARRES *)rs);
+      break;
+    default             :
+      (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
+                          OPEP,(int)sql->sqldb);
+      rs=(SQLRES *)0;
+      break;
+    }
+  }
+return rs;
 #undef  OPEP
 }
 /*
index afa5e329d3f418275470e0362b25255ca3ebe636..62d3a042e6c12477426bd729c8d6f73f8278bb5f 100644 (file)
@@ -30,7 +30,7 @@ extern char *sql_gooddata(SQLPTR *sqlptr,char *key);
 extern int sql_request(SQLPTR *sqlptr,const char *fmt,...);
 
 //to extract data from database
-extern char *sql_getvalue(SQLPTR *sqlptr,SQLRES *rs,int row,char *name);
+extern char *sql_getvalue(SQLPTR *sqlptr,SQLRES *rs,int row,const char *name);
 
 //to extract data from database
 extern SQLRES *sql_gettupple(SQLPTR *sqlptr,const char *fmt,...);