提交 65a49e34 编写于 作者: S serge-rider

#2656 Statement execute fix - limit apply check (workaround for SQL Server)

上级 18823797
......@@ -19,6 +19,7 @@ package org.jkiss.dbeaver.ext.mssql.model;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.generic.model.GenericDataSource;
import org.jkiss.dbeaver.ext.mssql.SQLServerConstants;
import org.jkiss.dbeaver.model.DBConstants;
import org.jkiss.dbeaver.model.DBPDataSourceContainer;
import org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -41,6 +42,14 @@ public class SQLServerDataSource extends GenericDataSource {
super(monitor, container, metaModel, new SQLServerDialect());
}
@Override
public Object getDataSourceFeature(String featureId) {
if (DBConstants.FEATURE_LIMIT_AFFECTS_DML.equals(featureId)) {
return true;
}
return super.getDataSourceFeature(featureId);
}
//////////////////////////////////////////////////////////
// Databases
......
......@@ -28,6 +28,8 @@ import java.util.Locale;
*/
public class DBConstants {
public static final String FEATURE_LIMIT_AFFECTS_DML = "datasource.limit-affects-dml";
public static final int METADATA_FETCH_SIZE = 1000;
public static final String DATA_SOURCE_PROPERTY_USER = "user"; //NON-NLS-1
......
......@@ -930,7 +930,10 @@ public final class DBUtils {
// or some DML. For DML statements we mustn't set limits
// because it sets update rows limit [SQL Server]
boolean selectQuery = sqlQuery.getType() == SQLQueryType.SELECT && sqlQuery.isPlainSelect();
final boolean hasLimits = selectQuery && offset >= 0 && maxRows > 0;
final boolean hasLimits = offset > 0 || (selectQuery && maxRows > 0);
// This is a flag for any potential SELECT query
boolean possiblySelect = sqlQuery.getType() == SQLQueryType.SELECT || sqlQuery.getType() == SQLQueryType.UNKNOWN;
boolean limitAffectsDML = Boolean.TRUE.equals(session.getDataSource().getDataSourceFeature(DBConstants.FEATURE_LIMIT_AFFECTS_DML));
DBCQueryTransformer limitTransformer = null, fetchAllTransformer = null;
if (selectQuery) {
......@@ -940,7 +943,7 @@ public final class DBUtils {
if (session.getDataSource().getContainer().getPreferenceStore().getBoolean(ModelPreferences.RESULT_SET_MAX_ROWS_USE_SQL)) {
limitTransformer = transformProvider.createQueryTransformer(DBCQueryTransformType.RESULT_SET_LIMIT);
}
} else if (offset <= 0 && maxRows <= 0) {
} else if (maxRows <= 0) {
fetchAllTransformer = transformProvider.createQueryTransformer(DBCQueryTransformType.FETCH_ALL_TABLE);
}
}
......@@ -961,7 +964,7 @@ public final class DBUtils {
makeStatement(session, queryText, hasLimits);
dbStat.setStatementSource(executionSource);
if (hasLimits || offset > 0) {
if (offset > 0 || hasLimits || (possiblySelect && maxRows > 0 && !limitAffectsDML)) {
if (limitTransformer == null) {
// Set explicit limit - it is safe because we pretty sure that this is a plain SELECT query
dbStat.setLimit(offset, maxRows);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册