From 59eb3bb6cd61e4261bf81b57c4a4ffbb14ba4b35 Mon Sep 17 00:00:00 2001
From: Martin Nilsson <mani@lysator.liu.se>
Date: Fri, 25 Nov 2005 00:15:57 +0100
Subject: [PATCH] No more .column when there are no table names.

Rev: lib/modules/Sql.pmod/Sql.pike:1.84
---
 lib/modules/Sql.pmod/Sql.pike | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/lib/modules/Sql.pmod/Sql.pike b/lib/modules/Sql.pmod/Sql.pike
index 351951a408..618f0a2a25 100644
--- a/lib/modules/Sql.pmod/Sql.pike
+++ b/lib/modules/Sql.pmod/Sql.pike
@@ -1,5 +1,5 @@
 /*
- * $Id: Sql.pike,v 1.83 2005/10/05 07:51:32 nilsson Exp $
+ * $Id: Sql.pike,v 1.84 2005/11/24 23:15:57 nilsson Exp $
  *
  * Implements the generic parts of the SQL-interface
  *
@@ -300,20 +300,30 @@ static private array(mapping(string:mixed)) res_obj_to_array(object res_obj)
     array(mapping(string:mixed)) res = ({});
     array(string) fieldnames;
     array(mixed) row;
+
     array(mapping) fields = res_obj->fetch_fields();
+    if(!sizeof(fields)) return ({});
+
+    int has_table = fields[0]->table && fields[0]->table!="";
 
-    fieldnames = (map(fields,
-		      lambda (mapping(string:mixed) m) {
-			return (m->table||"") + "." + m->name;
-		      }) +
-                  fields->name);
+    if(has_table)
+      fieldnames = (map(fields,
+			lambda (mapping(string:mixed) m) {
+			  return (m->table||"") + "." + m->name;
+			}) +
+		    fields->name);
+    else
+      fieldnames = fields->name;
 
     if (case_convert)
       fieldnames = map(fieldnames, lower_case);
 
-
-    while (row = res_obj->fetch_row())
-      res += ({ mkmapping(fieldnames, row + row) });
+    if(has_table)
+      while (row = res_obj->fetch_row())
+	res += ({ mkmapping(fieldnames, row + row) });
+    else
+      while (row = res_obj->fetch_row())
+	res += ({ mkmapping(fieldnames, row) });
 
     return res;
   }
-- 
GitLab