]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Able to extract email field from emails table
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 25 Jun 2025 14:26:20 +0000 (10:26 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 25 Jun 2025 14:26:20 +0000 (10:26 -0400)
lib/devsql.c
lib/unimar.c
lib/unimar.h
lib/unipos.c
lib/unipos.h
sql/mailleur.sql

index 34dc284b9afcec45794128d628028f57841853ed..632a1d160e55fc57c9f7c2479a2481b05f1e25e2 100644 (file)
@@ -68,6 +68,70 @@ return rs;
 */
 /********************************************************/
 /*                                                      */
+/*      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;
+  }
+return value;
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to get the ASCII form of field located*/
+/*      in a specific tuple + position in sqlresult.    */
+/*                                                      */
+/********************************************************/
+static char *getfield(SQLTYP *sql,SQLRES *rs,int tuple,int position)
+
+{
+#define OPEP    "devsql.c:getfield,"
+
+char *value;
+
+value=(char *)0;
+switch(sql->sqldb) {
+  case db_postgres    :
+    value=pos_getfield((POSRES *)rs,tuple,position);
+    break;
+  case db_maria       :
+    value=mar_getfield((MARRES *)rs,tuple,position);
+    break;
+  default             :
+    (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
+                        OPEP,(int)sql->sqldb);
+    break;
+  }
+return value;
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
 /*      Procedure to the number of tupple within a      */
 /*      result issued by a successfull command.         */
 /*                                                      */
@@ -416,8 +480,11 @@ while (proceed==true) {
     case 4      :       //getting user information
       int nbr;
 
-      if ((nbr=nbrtupple(sql,rs))>0) {
-        (void) rou_alert(0,"%s jmpdbg NBR='%d'",OPEP,nbr);
+      if ((nbr=nbrtupple(sql,rs))==1) {
+        char *rcpt;
+
+        rcpt=getvalue(sql,rs,0,"email");
+        (void) rou_alert(0,"%s JMPDBG db_rcpt=<%s>",OPEP,rcpt);
         }
       rs=dropresult(sql,rs);
       break;
index cff1460d901ed490f7112e368f1c7a0604e7ffd5..8dfa2e595d537404dcb9cd49e2c308d1685084e6 100644 (file)
@@ -169,6 +169,88 @@ return (MARRES *)0;
 */
 /********************************************************/
 /*                                                     */
+/*      procedure to retrieve specific field value in   */
+/*      tupple under fieldname.                         */
+/*                                                     */
+/********************************************************/
+PUBLIC char *mar_getvalue(MARRES *rs,int tuple,const char *fieldname)
+
+{
+#define OPEP    "unimar.c:pos_getfield,"
+register char *got;
+
+got=(char *)0;
+#ifdef  DB_MYSQL
+  {
+  register int position;
+
+  register uint numfields;
+  MYSQL_FIELD *fields;
+
+  position=-1;
+  numfields=mysql_num_fields((MYSQL_RES *)rs);
+  fields=mysql_fetch_fields((MYSQL_RES *)rs);
+  for (int i=0;i<numfields;i++) {
+    if (strcmp(fields[i].name,fieldname)==0) {
+      position=i;
+      break;
+      }
+    }
+  if (position<0) 
+    (void) rou_alert(0,"%s field '%s' unknown (Bug?)",OPEP,fieldname);
+  else {
+    register MYSQL_ROW row;
+
+    (void) mysql_data_seek((MYSQL_RES *)rs,tuple);
+    if ((row=mysql_fetch_row((MYSQL_RES *)rs))!=(MYSQL_ROW)0) 
+      got=row[position];
+    }
+  }
+#endif
+return got;
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to extract data from the database.    */
+/*      Return POSRES status pointer (can be NULL is not*/
+/*      successfull.                                    */
+/*                                                     */
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*      procedure to retrieve specific field in specific*/
+/*      row, accessed with the column number.           */
+/*                                                     */
+/********************************************************/
+PUBLIC char *mar_getfield(MARRES *rs,int tuple,int position)
+
+{
+register char *got;
+
+got=(char *)0;
+#ifdef  DB_MYSQL
+  {
+  MYSQL_ROW row;
+
+  (void) mysql_data_seek((MYSQL_RES *)rs,tuple);
+  if ((row=mysql_fetch_row((MYSQL_RES *)rs))!=(MYSQL_ROW)0) {
+    got=row[position];
+    }
+  }
+#endif
+return got;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
 /*     Procedure to extract data from the database.    */
 /*      Return POSRES status pointer (can be NULL is not*/
 /*      successfull.                                    */
index ecefce3a0385fc9cd2875c37cf469cc99ca0e932..c22ab03ad42522bfc61a5fb85810d61338c1bb13 100644 (file)
@@ -26,6 +26,12 @@ extern char *mar_cleanquote(char *sequence);
 //procedure to drop/free all result information
 extern MARRES *mar_dropresult(MARRES *rs);
 
+//procedure to extract specific field within database
+extern char *mar_getfield(MARRES *rs,int tuple,int position);
+
+//procedure to extract specific field value within database
+extern char *mar_getvalue(MARRES *rs,int tuple,const char *fieldname);
+
 //procedure to extract data from database
 extern MARRES *mar_gettupple(MARPTR *marptr,char *command);
 
index 8b25de65f1a53c60ff4c0fba2248a6f1d7f55300..f26011110c30670f67efa440e6c159af7d4483e3 100644 (file)
@@ -217,6 +217,57 @@ return (POSRES *)0;
 */
 /********************************************************/
 /*                                                     */
+/*      procedure to retrieve specific field value in   */
+/*      tupple, accessed at position                    */
+/*                                                     */
+/********************************************************/
+PUBLIC char *pos_getfield(POSRES *rs,int tuple,int position)
+
+{
+register char *got;
+
+got=(char *)0;
+#ifdef  DB_POSTGRESQL
+got=PQgetvalue((PGresult *)rs,tuple,position);
+#endif
+return got;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*      procedure to retrieve specific field value in   */
+/*      tupple under fieldname.                         */
+/*                                                     */
+/********************************************************/
+PUBLIC char *pos_getvalue(POSRES *rs,int tuple,const char *fieldname)
+
+{
+#define OPEP    "unipos.c:pos_getfield,"
+register char *got;
+
+got=(char *)0;
+#ifdef  DB_POSTGRESQL
+  {
+  int position;
+
+  if ((position=PQfnumber((PGresult *)rs,fieldname))<0) 
+    (void) rou_alert(0,"%s field '%s' unknown (BUG?)",OPEP,fieldname);
+  else {
+    if (PQgetisnull((PGresult *)rs,tuple,position)==false)
+      got=PQgetvalue((PGresult *)rs,tuple,position);
+    }
+  }
+#endif
+return got;
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
 /*     Procedure to extract data from the database.    */
 /*      Return POSRES status pointer (can be NULL is not*/
 /*      successfull.                                    */
index e0a451270452b358ee7c043a9140b301e699207e..8bb29949e1b42db0972ab9a3ee8f5baafb5cda48 100644 (file)
@@ -26,6 +26,12 @@ extern char *pos_cleanquote(char *sequence);
 //procedure to drop/free all result information
 extern POSRES *pos_dropresult(POSRES *rs);
 
+//procedure to extract specific field within database
+extern char *pos_getfield(POSRES *rs,int tuple,int position);
+
+//procedure to extract specific field value within database
+extern char *pos_getvalue(POSRES *rs,int tuple,const char *fieldname);
+
 //procedure to extract data from database
 extern POSRES *pos_gettupple(POSPTR *posptr,char *command);
 
index efd7d4d39800feaa05448d8c5f1898f001c6d992..7a01ca81de7bb23a851156952f625896c8ca51d7 100644 (file)
@@ -49,7 +49,7 @@
 /*                                                     */
 /********************************************************/
 CREATE TABLE emails    (
-       email   TEXT,           //user email
+       email   TEXTUNIQUE,     //user email
        space   INTEGER         //space used by user email      
                DFLT 0,
        mxspace INTEGER         //Maximun space available