Index: dbmysql.c
===================================================================
RCS file: /cvsroot-dbmail/dbmail/mysql/dbmysql.c,v
retrieving revision 1.73.4.10
diff -u -r1.73.4.10 dbmysql.c
--- dbmysql.c	2003/11/14 15:43:03	1.73.4.10
+++ dbmysql.c	2003/11/20 22:50:21
@@ -101,6 +101,8 @@
 	res = NULL;
 }
 
+static unsigned last_row=-1;
+static MYSQL_ROW last_res;
 char *db_get_result(unsigned row, unsigned field)
 {
 	char *result;
@@ -117,13 +119,19 @@
 		      "row = %u, field = %u, bigger than size of result set",				__FILE__, __FUNCTION__,row, field);           
 		return NULL;                                          
 	}                                                         
-	/* get the right row */                                   
-	mysql_data_seek(res, row);                          
-	result = mysql_fetch_row(res)[field];               
+	/* get the right row */
+	if(last_row==row) {
+	} else if((last_row+1)==row) {
+		last_res=mysql_fetch_row(res);
+	} else {
+		mysql_data_seek(res, row);                          
+		last_res=mysql_fetch_row(res);
+	}
+	result = last_res[field];               
 	if (result == NULL)                                       
 		trace(TRACE_WARNING, "%s,%s: result is null\n",
 		      __FILE__, __FUNCTION__);
-
+	last_row=row;
 	return result;                                            
 }                                                             
 
@@ -152,7 +160,8 @@
 
 int db_query(const char *the_query)        
 {                                                             
-	unsigned int querysize = 0;                               
+	unsigned int querysize = 0;
+	last_row=-1;
 	if (db_check_connection() < 0) {
 		trace(TRACE_ERROR, "%s,%s: no database connection",
 				__FILE__, __FUNCTION__);
@@ -240,10 +249,17 @@
 		   "row = %u, field = %u, bigger than size of result set",				__FILE__, __FUNCTION__,row, field);           
 		return -1;                                          
 	}                                                         
-	/* get the right row */                                   
-	mysql_data_seek(res, row);
-	mysql_fetch_row(res);
-
+	/* get the right row */
+	if(last_row==row) {
+		// Don't do anything, we're already there
+	} else if((last_row+1)==row) {
+		// Get the next row
+		last_res=mysql_fetch_row(res);
+	} else {
+		mysql_data_seek(res, row);
+		last_res=mysql_fetch_row(res);
+	}
+	last_row=row;
 	return (u64_t) mysql_fetch_lengths(res)[field];
 }
 
