Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/pro#3648 Driver properties #59

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {

@Override
public String getIdentifierQuoteString() throws SQLException {
return null;
return "\"";
}

@Override
Expand Down Expand Up @@ -165,27 +165,27 @@ public String getTimeDateFunctions() throws SQLException {

@Override
public String getSearchStringEscape() throws SQLException {
return null;
return "\\";
}

@Override
public String getExtraNameCharacters() throws SQLException {
return null;
return "";
}

@Override
public boolean supportsAlterTableWithAddColumn() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsAlterTableWithDropColumn() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsColumnAliasing() throws SQLException {
return false;
return true;
}

@Override
Expand All @@ -195,12 +195,12 @@ public boolean nullPlusNonNullIsNull() throws SQLException {

@Override
public boolean supportsConvert() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsConvert(int fromType, int toType) throws SQLException {
return false;
return true;
}

@Override
Expand All @@ -225,7 +225,7 @@ public boolean supportsOrderByUnrelated() throws SQLException {

@Override
public boolean supportsGroupBy() throws SQLException {
return false;
return true;
}

@Override
Expand Down Expand Up @@ -260,12 +260,12 @@ public boolean supportsNonNullableColumns() throws SQLException {

@Override
public boolean supportsMinimumSQLGrammar() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsCoreSQLGrammar() throws SQLException {
return false;
return true;
}

@Override
Expand All @@ -275,17 +275,17 @@ public boolean supportsExtendedSQLGrammar() throws SQLException {

@Override
public boolean supportsANSI92EntryLevelSQL() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsANSI92IntermediateSQL() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsANSI92FullSQL() throws SQLException {
return false;
return true;
}

@Override
Expand All @@ -295,12 +295,12 @@ public boolean supportsIntegrityEnhancementFacility() throws SQLException {

@Override
public boolean supportsOuterJoins() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsFullOuterJoins() throws SQLException {
return false;
return true;
}

@Override
Expand All @@ -325,7 +325,7 @@ public String getCatalogTerm() throws SQLException {

@Override
public boolean isCatalogAtStart() throws SQLException {
return false;
return true;
}

@Override
Expand All @@ -335,52 +335,52 @@ public String getCatalogSeparator() throws SQLException {

@Override
public boolean supportsSchemasInDataManipulation() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsSchemasInProcedureCalls() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsSchemasInTableDefinitions() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsSchemasInIndexDefinitions() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsCatalogsInDataManipulation() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsCatalogsInProcedureCalls() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsCatalogsInTableDefinitions() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
return false;
return true;
}

@Override
public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
*/
package com.dbeaver.jdbc.model;

import org.jkiss.utils.CommonUtils;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Map;

Expand Down Expand Up @@ -92,62 +95,56 @@

@Override
public String getString(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
return CommonUtils.toString(getObject(columnIndex));
}

@Override
public boolean getBoolean(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
return CommonUtils.toBoolean(getObject(columnIndex));
}

@Override
public byte getByte(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
return (byte) CommonUtils.toInt(getObject(columnIndex));
}

@Override
public short getShort(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
return (short) CommonUtils.toInt(getObject(columnIndex));
}

@Override
public int getInt(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
return CommonUtils.toInt(getObject(columnIndex));
}

@Override
public long getLong(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
return CommonUtils.toLong(getObject(columnIndex));
}

@Override
public float getFloat(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
return CommonUtils.toFloat(getObject(columnIndex));
}

@Override
public double getDouble(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
return CommonUtils.toDouble(getObject(columnIndex));
}

@Override
public byte[] getBytes(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
}

@Override
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
throw new SQLFeatureNotSupportedException();
}

@Override
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
throw new SQLFeatureNotSupportedException();
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
Object object = getObject(columnIndex);
return object == null ? null :
object instanceof BigDecimal bd ? bd :
object instanceof Long str ? BigDecimal.valueOf(str) : BigDecimal.valueOf(CommonUtils.toDouble(object));
}

@Override
public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
throw new SQLFeatureNotSupportedException();
public byte[] getBytes(int columnIndex) throws SQLException {
Object object = getObject(columnIndex);
return object == null ? null : object.toString().getBytes();
}

@Override
Expand All @@ -165,11 +162,6 @@
throw new SQLFeatureNotSupportedException();
}

@Override
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
throw new SQLFeatureNotSupportedException();
}

@Override
public InputStream getAsciiStream(int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException();
Expand All @@ -185,7 +177,39 @@
throw new SQLFeatureNotSupportedException();
}

protected <T extends java.util.Date> T parseDate(Class<T> type, String value) throws SQLException {
try {
if (type == Time.class) {
return type.cast(new Time(CommonJdbcConstants.ISO_TIME_FORMAT.parse(value).getTime()));
} else if (type == Date.class) {
return type.cast(new Date(CommonJdbcConstants.ISO_DATE_FORMAT.parse(value).getTime()));
} else {
return type.cast(new Timestamp(CommonJdbcConstants.ISO_TIMESTAMP_FORMAT.parse(value).getTime()));
}
} catch (ParseException e) {
throw new SQLException("Error parsing ISO date format", e);
}
}

@Override
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
Object object = getObject(columnIndex);
return object == null ? null : parseDate(Date.class, object.toString());
}

@Override
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
Object object = getObject(columnIndex);
return object == null ? null : parseDate(Time.class, object.toString());
}

@Override
public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
Object object = getObject(columnIndex);
return object == null ? null : parseDate(Timestamp.class, object.toString());
}

@Override

Check warning on line 212 in modules/com.dbeaver.jdbc.api/src/com/dbeaver/jdbc/model/AbstractJdbcResultSet.java

View workflow job for this annotation

GitHub Actions / Check / Lint

[checkstyle] reported by reviewdog 🐶 All overloaded methods should be placed next to each other. Previous overloaded method located at line '194'. Raw Output: /github/workspace/./modules/com.dbeaver.jdbc.api/src/com/dbeaver/jdbc/model/AbstractJdbcResultSet.java:212:5: warning: All overloaded methods should be placed next to each other. Previous overloaded method located at line '194'. (com.puppycrawl.tools.checkstyle.checks.coding.OverloadMethodsDeclarationOrderCheck)
public Date getDate(int columnIndex) throws SQLException {
return getDate(columnIndex, Calendar.getInstance());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.dbeaver.jdbc.model;

import org.jkiss.utils.StandardConstants;

import java.text.SimpleDateFormat;

public abstract class CommonJdbcConstants {

public static final SimpleDateFormat ISO_TIMESTAMP_FORMAT = new SimpleDateFormat(StandardConstants.ISO_TIMESTAMP_PATTERN);
public static final SimpleDateFormat ISO_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss'Z'");
public static final SimpleDateFormat ISO_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
}
Loading