[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kspread/functions
From:       Marijn Kruisselbrink <m.kruisselbrink () student ! tue ! nl>
Date:       2010-06-13 8:52:23
Message-ID: 20100613085223.A2C99AC8CF () svn ! kde ! org
[Download RAW message or body]

SVN commit 1137505 by mkruisselbrink:

enhance the DCOUNT and DCOUNTA function to have an optional middle argument like in excel


 M  +10 -4     database.cpp  


--- trunk/koffice/kspread/functions/database.cpp #1137504:1137505
@@ -287,8 +287,6 @@
     Value database = args[0];
     Value conditions = args[2];
     int fieldIndex = getFieldIndex(calc, args[1], database);
-    if (fieldIndex < 0)
-        return Value::errorVALUE();
 
     DBConditions conds(calc, database, conditions);
 
@@ -296,11 +294,16 @@
     int count = 0;
     for (int r = 0; r < rows; ++r)
         if (conds.matches(r)) {
+            // fieldIndex is optional, if no field is specified count all rows matching the conditions
+            if (fieldIndex < 0)
+                count++;
+            else {
             Value val = database.element(fieldIndex, r + 1);
             // include this value in the result
             if ((!val.isEmpty()) && (!val.isBoolean()) && (!val.isString()))
                 count++;
         }
+        }
 
     return Value(count);
 }
@@ -311,8 +314,6 @@
     Value database = args[0];
     Value conditions = args[2];
     int fieldIndex = getFieldIndex(calc, args[1], database);
-    if (fieldIndex < 0)
-        return Value::errorVALUE();
 
     DBConditions conds(calc, database, conditions);
 
@@ -320,11 +321,16 @@
     int count = 0;
     for (int r = 0; r < rows; ++r)
         if (conds.matches(r)) {
+            // fieldIndex is optional, if no field is specified count all rows matching the conditions
+            if (fieldIndex < 0)
+                count++;
+            else {
             Value val = database.element(fieldIndex, r + 1);
             // include this value in the result
             if (!val.isEmpty())
                 count++;
         }
+        }
 
     return Value(count);
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic