miemie 5 年之前
父節點
當前提交
8f9924557c

+ 4 - 0
mybatis-plus-annotation/src/main/java/com/baomidou/mybatisplus/annotation/DbType.java

@@ -105,6 +105,10 @@ public enum DbType {
      * Oscar
      */
     OSCAR("oscar", "神通数据库"),
+    /**
+     * Sybase
+     */
+    SYBASE("sybase", "Sybase ASE 数据库"),
     /**
      * UNKONWN DB
      */

+ 1 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/DialectRegistry.java

@@ -56,6 +56,7 @@ public class DialectRegistry {
         dialect_enum_map.put(DbType.DB2, new DB2Dialect());
         dialect_enum_map.put(DbType.SQL_SERVER2005, new SQLServer2005Dialect());
         dialect_enum_map.put(DbType.SQL_SERVER, new SQLServerDialect());
+        dialect_enum_map.put(DbType.SYBASE, new SybaseDialect());
     }
 
     public IDialect getDialect(DbType dbType) {

+ 50 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/pagination/dialects/SybaseDialect.java

@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * https://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.extension.plugins.pagination.dialects;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
+
+/**
+ * sybase 数据库分页方言
+ *
+ * @author sdsyjh
+ * @since 2020-07-30
+ */
+public class SybaseDialect implements IDialect {
+
+    private final boolean hasTop; // sybase12.5.4以前,不支持select top
+
+    public SybaseDialect() {
+        this(true);
+    }
+
+    public SybaseDialect(boolean hasTop) {
+        this.hasTop = hasTop;
+    }
+
+    @Override
+    public DialectModel buildPaginationSql(String originalSql, long offset, long limit) {
+        int index = originalSql.indexOf("FROM");
+        String sql = "select";
+        if (hasTop) {
+            sql += " top " + (offset + limit);
+        }
+        sql += " rownum=identity(12)," + originalSql.substring(6, index) + " into #t " + originalSql.substring(index);
+        sql += " select * from #t where rownum > ? and rownum <= ? ";
+        sql += "drop table #t ";
+        return new DialectModel(sql, offset, offset + limit).setConsumerChain();
+    }
+}

+ 2 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/toolkit/JdbcUtils.java

@@ -96,6 +96,8 @@ public class JdbcUtils {
             return DbType.CLICKHOUSE;
         } else if (jdbcUrl.contains(":oscar:")) {
             return DbType.OSCAR;
+        } else if (jdbcUrl.contains(":sybase:")) {
+            return DbType.SYBASE;
         } else {
             logger.warn("The jdbcUrl is " + jdbcUrl + ", Mybatis Plus Cannot Read Database type or The Database's Not Supported!");
             return DbType.OTHER;