]> git.joonet.de Git - adminer.git/commitdiff
MS SQL pagination
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 23 Apr 2010 09:04:05 +0000 (09:04 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 23 Apr 2010 09:04:05 +0000 (09:04 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1485 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/drivers/mssql.inc.php
adminer/select.inc.php

index 5e40c268822ec2a5daff6978ae1fe9ec638a6a22..2e9007b4a603dfe74d24a542d197b29968f96857 100644 (file)
@@ -125,6 +125,12 @@ if (isset($_GET["mssql"])) {
                                $return->type = ($field["Type"] == 1 ? 254 : 0);
                                return $return;
                        }
+                       
+                       function seek($offset) {
+                               for ($i=0; $i < $offset; $i++) {
+                                       sqlsrv_fetch($this->_result); // SQLSRV_SCROLL_ABSOLUTE added in sqlsrv 1.1
+                               }
+                       }
 
                        function __destruct() {
                                sqlsrv_free_stmt($this->_result);
@@ -216,6 +222,10 @@ if (isset($_GET["mssql"])) {
                                return $return;
                        }
 
+                       function seek($offset) {
+                               mssql_data_seek($this->_result, $offset);
+                       }
+                       
                        function __destruct() {
                                mssql_free_result($this->_result);
                        }
@@ -242,10 +252,10 @@ if (isset($_GET["mssql"])) {
        }
 
        function limit($query, $limit, $offset = 0) {
-               return (isset($limit) ? " TOP ($limit)" : "") . " $query"; //! offset
+               return (isset($limit) ? " TOP (" . ($limit + $offset) . ")" : "") . " $query"; // seek later
        }
 
-       function limit1($query, $limit, $offset = 0) {
+       function limit1($query) {
                return limit($query, 1);
        }
 
@@ -297,7 +307,11 @@ if (isset($_GET["mssql"])) {
        function fields($table) {
                global $connection;
                $return = array();
-               $result = $connection->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = " . $connection->quote($table));
+               $result = $connection->query("SELECT i.*, c.is_identity
+FROM information_schema.COLUMNS i
+JOIN sys.columns c ON OBJECT_NAME(c.object_id) = i.TABLE_NAME AND c.name = i.COLUMN_NAME
+WHERE i.TABLE_NAME = " . $connection->quote($table)
+               );
                while ($row = $result->fetch_assoc()) {
                        $return[$row["COLUMN_NAME"]] = array(
                                "field" => $row["COLUMN_NAME"],
@@ -306,9 +320,10 @@ if (isset($_GET["mssql"])) {
                                "length" => $row["CHARACTER_MAXIMUM_LENGTH"], //! NUMERIC_, DATETIME_?
                                "default" => $row["COLUMN_DEFAULT"],
                                "null" => ($row["IS_NULLABLE"] == "YES"),
+                               "auto_increment" => $row["is_identity"],
                                "collation" => $row["COLLATION_NAME"],
                                "privileges" => array("insert" => 1, "select" => 1, "update" => 1),
-                               //! primary - is_identity in sys.columns
+                               "primary" => $row["is_identity"], //! or indexes.is_primary_key
                        );
                }
                return $return;
@@ -371,13 +386,18 @@ WHERE OBJECT_NAME(indexes.object_id) = " . $connection2->quote($table)
                if ($collation) {
                        queries("ALTER DATABASE " . idf_escape(DB) . " COLLATE " . idf_escape($collation));
                }
-               return queries("ALTER DATABASE " . idf_escape(DB) . " MODIFY NAME = " . idf_escape($name)); //! false negative "The database name 'test2' has been set."
+               queries("ALTER DATABASE " . idf_escape(DB) . " MODIFY NAME = " . idf_escape($name));
+               return true; //! false negative "The database name 'test2' has been set."
        }
 
        function auto_increment() {
                return " IDENTITY";
        }
        
+       function insert_into($table, $set) {
+               return queries("INSERT INTO " . idf_escape($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
+       }
+       
        function explain($connection, $query) {
                $connection->query("SET SHOWPLAN_ALL ON");
                $return = $connection->query($query);
index 57a18db03badd5fe609a28c18fef76c9e9a16f7a..25e710d3912233ca81b9011a079872eb6d5d4e5d 100644 (file)
@@ -189,6 +189,9 @@ if (!$columns) {
        if (!$result) {
                echo "<p class='error'>" . error() . "\n";
        } else {
+               if ($driver == "mssql") {
+                       $result->seek($limit * $page);
+               }
                $email_fields = array();
                echo "<form action='' method='post' enctype='multipart/form-data'>\n";
                $rows = array();
@@ -196,10 +199,12 @@ if (!$columns) {
                        $rows[] = $row;
                }
                // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
-               $found_rows = (intval($limit) && $group && count($group) < count($select)
-                       ? ($driver == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
-                       : count($rows)
-               );
+               if ($_GET["page"] != "last") {
+                       $found_rows = (intval($limit) && $group && count($group) < count($select)
+                               ? ($driver == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
+                               : count($rows)
+                       );
+               }
                
                if (!$rows) {
                        echo "<p class='message'>" . lang('No rows.') . "\n";
@@ -296,7 +301,7 @@ if (!$columns) {
                
                if ($rows || $page) {
                        $exact_count = true;
-                       if (intval($limit) && count($group) >= count($select) && ($found_rows >= $limit || $page)) {
+                       if ($_GET["page"] != "last" && intval($limit) && count($group) >= count($select) && ($found_rows >= $limit || $page)) {
                                $found_rows = $table_status["Rows"];
                                if (!isset($found_rows) || $where || 2 * $page * $limit > $found_rows || ($table_status["Engine"] == "InnoDB" && $found_rows < 1e4)) {
                                        // slow with big tables