001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.db.dialect;
017
018import com.jfinal.plugin.activerecord.dialect.Sqlite3Dialect;
019import io.jboot.db.model.Column;
020import io.jboot.db.model.SqlBuilder;
021import io.jboot.db.model.Join;
022
023import java.util.List;
024
025
026public class JbootSqlite3Dialect extends Sqlite3Dialect implements JbootDialect {
027
028
029    @Override
030    public String forFindByColumns(String alias, List<Join> joins, String table, String loadColumns, List<Column> columns, String orderBy, Object limit) {
031        StringBuilder sqlBuilder = SqlBuilder.forFindByColumns(alias, joins, table, loadColumns, columns, orderBy, ' ');
032
033        if (limit != null) {
034            sqlBuilder.append(" LIMIT " + limit);
035        }
036
037        return sqlBuilder.toString();
038    }
039
040    @Override
041    public String forFindCountByColumns(String alias, List<Join> joins, String table, String loadColumns, List<Column> columns) {
042        return SqlBuilder.forFindCountByColumns(alias, joins, table, loadColumns, columns, ' ');
043    }
044
045    @Override
046    public String forDeleteByColumns(String alias, List<Join> joins, String table, List<Column> columns) {
047        return SqlBuilder.forDeleteByColumns(alias, joins, table, columns, ' ');
048    }
049
050
051    @Override
052    public String forPaginateSelect(String loadColumns) {
053        return "SELECT " + loadColumns;
054    }
055
056
057    @Override
058    public String forPaginateFrom(String alias, List<Join> joins, String table, List<Column> columns, String orderBy) {
059        return SqlBuilder.forPaginateFrom(alias, joins, table, columns, orderBy, ' ');
060    }
061
062    @Override
063    public String forPaginateTotalRow(String select, String sqlExceptSelect, Object ext) {
064        String distinctSql = SqlBuilder.forPaginateDistinctTotalRow(select, sqlExceptSelect, ext);
065        return distinctSql != null ? distinctSql : super.forPaginateTotalRow(select, sqlExceptSelect, ext);
066    }
067
068}