CRM_Core_DAO - Add helper checkTableHasData()
authorTim Otten <totten@civicrm.org>
Wed, 30 Oct 2019 00:20:18 +0000 (17:20 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 30 Oct 2019 00:20:18 +0000 (17:20 -0700)
CRM/Core/DAO.php

index 0a09592556b1a00074e985c4e1f2dc753725946d..b508b64e6c278a76225998eedfe1e70443aadfd8 100644 (file)
@@ -1063,6 +1063,18 @@ LIKE %1
     return $result;
   }
 
+  /**
+   * Check if a given table has data.
+   *
+   * @param string $tableName
+   * @return bool
+   *   TRUE if $tableName has at least one record.
+   */
+  public static function checkTableHasData($tableName) {
+    $c = CRM_Core_DAO::singleValueQuery(sprintf('SELECT count(*) c FROM `%s`', $tableName));
+    return $c > 0;
+  }
+
   /**
    * @param $version
    *