]> git.nbdom.net Git - nb.git/commitdiff
www/dbq/etc/nginx.conf
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 4 Jan 2018 01:07:16 +0000 (01:07 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 4 Jan 2018 01:07:16 +0000 (01:07 +0000)
lib/php/db.php
lib/php/db/table.php
lib/php/page.php
www/dbq/dbq.php
www/dbq/etc/nginx.conf

index fd4fa4bb101d4973a85d5b969c6df18ddbda5310..67846b7532b213627462b21988d458fb998c394d 100644 (file)
@@ -342,8 +342,6 @@ class Db extends nb {
     return $sth->fetchAll($style);
   }
 
-  /*
-  */
   function query2a($sql) {
     $r = $this->conn->query($sql,PDO::FETCH_COLUMN);
     return $r ? $r->fetch() : $r;
index 16276729db48fc9627df12e243fff6e6794123f6..15af5d22b8f7f566613f85a05f33aca670ac7385 100644 (file)
@@ -868,13 +868,16 @@ Class Table extends nb {
     return ','.join(',',$select);
   }
 
-  /******************************************************************
-    Html Output
-  ******************************************************************/
+  public function rows_count() {
+               $opt = [ 'count' => 1 ];
+    return $this->db()->row($this->rows_sql($opt));
+       }
+
   public function rows_sql(&$opt=[]) {
 
     if (isset($this->orderby)) self::pdef('orderby',$this->orderby);
     if (self::p('order')) self::pset('orderby',self::p('orderby').' '.self::p('order')); # from Wordpress
+               $count = empty($opt['count']) ? 0 : 1;
 
     //
     // Select
@@ -882,6 +885,7 @@ Class Table extends nb {
     if (stripos($this->name,' ') !== false) {
       $sql = $this->name;
       $limit = $where = '';
+                       if ($count) $sql = "SELECT count(*) FROM ".$this->sql_name();
 
     } else {
 
@@ -899,12 +903,12 @@ Class Table extends nb {
 
       }
 
-      $sql = "SELECT ".trim( $select_count[0].' '.join(',',$select_fields) ). $this->select_extras();
+      $sql = $count ? "SELECT count(*)" : "SELECT ".trim( $select_count[0].' '.join(',',$select_fields) ). $this->select_extras();
       $sql .= " FROM ".$this->sql_name();
       $sql .= $where;
       #bye($sql);
 
-      if ($this->p('orderby')) $sql .= ' ORDER BY '.$this->p('orderby');
+      if ($this->p('orderby') and !$count) $sql .= ' ORDER BY '.$this->p('orderby');
 
       if ($limit = $this->db()->limit) {
         $sql .= ' LIMIT '.$limit;
@@ -914,6 +918,8 @@ Class Table extends nb {
 
     }
 
+               if ($count) return $sql;
+
     //
     // Get results
     //
index 07754a0c48664303c664e19547eb1ed9ce88ce95..1900cc1f5e05e7031b21b9df0ead48c7467db1d6 100644 (file)
@@ -366,7 +366,6 @@ class Page extends nb {
   public function headers() {
     if (self::php_cli()) return false;
 
-    #header('Content-type: ' . self::$content_type);
                header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : ""));
 
     if (isset($this->expires)) self::headers_cache($this->expires);
@@ -374,7 +373,6 @@ class Page extends nb {
     if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="'
       . $this->title2filename($this->title,self::$content_type)
     .'"');
-    #self::headers_cache();
 
     return true;
   }
@@ -402,8 +400,6 @@ class Page extends nb {
   public function head() {
     $head = '';
 
-    #$head .= '</head>'.NB_EOL; return $head;
-
     if ($this->title) $head .= $this->tag('title',$this->title) . NB_EOL;
 
     if (preg_match('/tml$/',self::$content_type)) {
@@ -466,7 +462,7 @@ class Page extends nb {
       }
 
     }
-    #debug($urls);
+
     return $urls;
   }
 
@@ -485,7 +481,6 @@ class Page extends nb {
   }
 
   public static function nav_parse($array) {
-    #$v = &$sep;
     $title = [];
     $nav = [];
     $hash = [];
index e825383ae35ab34d01db73506671d9dd82478abb..9e0073e69cbbeb78376faf7f4f342cba3f77257c 100644 (file)
@@ -74,6 +74,7 @@ class DbQ extends nb {
                '/default'.(PRODUCTION ? '.min' : '').'.js',
        ];
        public $ext;
+       public $expires;
 
        # Others
        public $expode_args = '&';
@@ -105,7 +106,8 @@ class DbQ extends nb {
                        'title',
                        'css',
                        'js',
-                       'format_html_ua_exp'
+                       'format_html_ua_exp',
+                       'expires',
                ] as $k) {
                        $env = 'DBQ_'.strtoupper($k);
 
@@ -141,6 +143,7 @@ class DbQ extends nb {
                        'sep' => $this->sep_title,
                        #'body_class' => 'fixed',
                ]);
+               if (isset($this->expires)) $this->page->expires = $this->expires;
 
                if ($run) $this->run();
        }
@@ -1176,6 +1179,9 @@ EOF;
                } elseif ($action == 'sql') {
                        $this->page(['sql'=>$this->table->sql()]);
 
+               } elseif ($action == 'count') {
+                       $this->page(['count'=>$this->table->rows_count()]);
+
                } elseif ($action == 'fields') {
                        $this->page($this->table,'fields_rows');
 
index 768253af7666791e002f52a0d6f1e758a9a8b961..7bc19fb7337ffed254a06807e760cf3580ca0e60 100644 (file)
@@ -54,4 +54,7 @@ location ~ /index\.php$ {
 
        if ($DBQ_ENVS = "") { set $DBQ_ENVS ""; }
        fastcgi_param DBQ_ENVS $DBQ_ENVS;
+
+       if ($DBQ_EXPIRES = "") { set $DBQ_EXPIRES ""; }
+       fastcgi_param DBQ_EXPIRES $DBQ_EXPIRES;
 }