]> git.nbdom.net Git - nb.git/commitdiff
Delete SQL_CALC_FOUND_ROWS
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 6 Jan 2016 02:32:47 +0000 (02:32 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 6 Jan 2016 02:32:47 +0000 (02:32 +0000)
lib/php/db/table.php

index af388ecff0ca5649e90e7133ac0f27335c5b892a..c0113f2d54514192b39da7f0186ffb5823a92076 100644 (file)
@@ -17,6 +17,7 @@ if (false and empty($_SERVER['DOCUMENT_ROOT'])) {
 if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit');
 if (!defined('DB_HTML_DELETE')) define('DB_HTML_DELETE','Delete');
 if (!defined('DB_HTML_NAV_TOP')) define('DB_HTML_NAV_TOP','<div class="nav" id="nav_top"></div>'.PHP_EOL);
+if (!defined('DB_TABLE_QUERY_NAME')) define('DB_TABLE_QUERY_NAME','_query_');
 
 class table extends nb {
 
@@ -44,7 +45,7 @@ class table extends nb {
     // Name, could be a select
     if (stripos($name,'SELECT ')===0) {
       #$temp = '_'.substr(md5($name),0,6);
-      $temp = '_query_';
+      $temp = DB_TABLE_QUERY_NAME;
       $this->db->conn->query("CREATE TEMPORARY TABLE $temp AS $name");
       $name = $temp;
     } elseif (preg_match('/\b(\.import|LOAD DATA|COPY|INSERT|REPLACE|DELETE|TRUNCATE|CREATE|DROP|ALERT)\b/',$name)) {
@@ -579,12 +580,14 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
   ******************************************************************/
   function rows($opt=array()) {
     
+    $select_count = ( (false and $this->db->type =='mysql') ? " SQL_CALC_FOUND_ROWS" : "");
     //
     // Select
     //
-    $sql = "SELECT".($this->db->type =='mysql' ? " SQL_CALC_FOUND_ROWS" : "")." *" . $this->select_extras();
-    $sql .= " FROM ".$this->sql_name().$this->where_criterias($this->p(),$this->p('op'));
-    $this->sql = $sql;
+    $sql = "SELECT$select_count *" . $this->select_extras();
+    $sql .= " FROM ".$this->sql_name();
+    $where = $this->where_criterias($this->p(),$this->p('op'));
+    $this->sql = $sql = $sql . $where;
     $this->debug($sql,1);
 
     if ($this->p('sort')) $sql .= ' ORDER BY '.$this->p('sort');
@@ -626,13 +629,18 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     //
     // Tot
     //
-    if ($this->db->type =='mysql') {
+    if ($select_count) {
       $query = $this->db->conn->query('SELECT FOUND_ROWS()');
+
+# NB 06.01.16     } elseif ($where) {
+# NB 06.01.16       $sql_count = $sql;
+# NB 06.01.16       $sql_count = preg_replace('/ (ORDER|LIMIT) .*?$/s','',$sql_count);
+# NB 06.01.16       $sql_count = preg_replace('/^SELECT .*FROM/s','SELECT count(*) FROM ',$sql_count);
+# NB 06.01.16       $query = $this->db->conn->query($sql_count);
+
     } else {
-      $sql_count = $sql;
-      $sql_count = preg_replace('/ (ORDER|LIMIT) .*?$/s','',$sql_count);
-      $sql_count = preg_replace('/^SELECT .*FROM/s','SELECT count(*) FROM (',$sql_count).') count';
-      $query = $this->db->conn->query($sql_count);
+      $query = $this->db->conn->query('SELECT count(*) FROM '.$this->sql_name());
+
     }
 
     if (!$query) {