v1.6.16:修复issue I5Y567,kingbase中TINYINT类型转换错误

This commit is contained in:
inrgihc
2022-11-05 23:02:26 +08:00
parent c6ec7ef22e
commit 5c3a8c2003
11 changed files with 38 additions and 41 deletions

Binary file not shown.

View File

@@ -99,7 +99,7 @@
<artifactId>kingbase-jdbc</artifactId> <artifactId>kingbase-jdbc</artifactId>
<version>8.2.0</version> <version>8.2.0</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/kingbase8-8.2.0.jar</systemPath> <systemPath>${project.basedir}/lib/kingbase8-8.6.0.jar</systemPath>
</dependency> </dependency>
<dependency> <dependency>

View File

@@ -300,7 +300,7 @@ public abstract class AbstractDatabase implements IDatabaseInterface {
// nothing more we can do here by catch the exception. // nothing more we can do here by catch the exception.
} }
cd.setSigned(signed); cd.setSigned(signed);
cd.setDbType(getDatabaseType()); cd.setProductType(getDatabaseType());
ret.add(cd); ret.add(cd);
} }

View File

@@ -115,7 +115,7 @@ public class DatabaseHiveImpl extends AbstractDatabase implements IDatabaseInter
// nothing more we can do here by catch the exception. // nothing more we can do here by catch the exception.
} }
cd.setSigned(signed); cd.setSigned(signed);
cd.setDbType(ProductTypeEnum.HIVE); cd.setProductType(ProductTypeEnum.HIVE);
ret.add(cd); ret.add(cd);
} }

View File

@@ -33,7 +33,7 @@ import org.apache.commons.lang3.StringUtils;
public class DatabaseKingbaseImpl extends AbstractDatabase implements IDatabaseInterface { public class DatabaseKingbaseImpl extends AbstractDatabase implements IDatabaseInterface {
private static final String SHOW_CREATE_VIEW_SQL = private static final String SHOW_CREATE_VIEW_SQL =
"SELECT pg_get_viewdef((select pg_class.relfilenode from pg_catalog.pg_class \n" "SELECT pg_get_viewdef((select pg_class.oid from pg_catalog.pg_class \n"
+ "join pg_catalog.pg_namespace on pg_class.relnamespace = pg_namespace.oid \n" + "join pg_catalog.pg_namespace on pg_class.relnamespace = pg_namespace.oid \n"
+ "where pg_namespace.nspname='%s' and pg_class.relname ='%s'),true) "; + "where pg_namespace.nspname='%s' and pg_class.relname ='%s'),true) ";

View File

@@ -26,11 +26,11 @@ public class ColumnDescription {
private int displaySize; private int displaySize;
private int scaleSize; private int scaleSize;
private int precisionSize; private int precisionSize;
private boolean isAutoIncrement; private boolean autoIncrement;
private boolean isNullable; private boolean nullable;
private String remarks; private String remarks;
private boolean signed = false; private boolean signed = false;
private ProductTypeEnum dbtype; private ProductTypeEnum productType;
public String getFieldName() { public String getFieldName() {
if (null != this.fieldName) { if (null != this.fieldName) {
@@ -52,8 +52,8 @@ public class ColumnDescription {
return this.fieldName; return this.fieldName;
} }
public void setLabelName(String labalName) { public void setLabelName(String labelName) {
this.labelName = labalName; this.labelName = labelName;
} }
public String getFieldTypeName() { public String getFieldTypeName() {
@@ -105,19 +105,19 @@ public class ColumnDescription {
} }
public boolean isAutoIncrement() { public boolean isAutoIncrement() {
return isAutoIncrement; return autoIncrement;
} }
public void setAutoIncrement(boolean isAutoIncrement) { public void setAutoIncrement(boolean autoIncrement) {
this.isAutoIncrement = isAutoIncrement; this.autoIncrement = autoIncrement;
} }
public boolean isNullable() { public boolean isNullable() {
return isNullable; return nullable;
} }
public void setNullable(boolean isNullable) { public void setNullable(boolean isNullable) {
this.isNullable = isNullable; this.nullable = isNullable;
} }
public boolean isSigned() { public boolean isSigned() {
@@ -128,12 +128,12 @@ public class ColumnDescription {
this.signed = signed; this.signed = signed;
} }
public ProductTypeEnum getDbType() { public ProductTypeEnum getProductType() {
return this.dbtype; return this.productType;
} }
public void setDbType(ProductTypeEnum dbtype) { public void setProductType(ProductTypeEnum productType) {
this.dbtype = dbtype; this.productType = productType;
} }
public String getRemarks() { public String getRemarks() {
@@ -154,11 +154,11 @@ public class ColumnDescription {
description.setDisplaySize(displaySize); description.setDisplaySize(displaySize);
description.setScaleSize(scaleSize); description.setScaleSize(scaleSize);
description.setPrecisionSize(precisionSize); description.setPrecisionSize(precisionSize);
description.setAutoIncrement(isAutoIncrement); description.setAutoIncrement(autoIncrement);
description.setNullable(isNullable); description.setNullable(nullable);
description.setRemarks(remarks); description.setRemarks(remarks);
description.setSigned(signed); description.setSigned(signed);
description.setDbType(dbtype); description.setProductType(productType);
return description; return description;
} }

View File

@@ -84,8 +84,7 @@ public class ColumnMetaData {
* The Constant typeCodes. * The Constant typeCodes.
*/ */
public static final String[] TYPE_CODES = new String[]{"-", "Number", "String", "Date", "Boolean", public static final String[] TYPE_CODES = new String[]{"-", "Number", "String", "Date", "Boolean",
"Integer", "Integer", "BigNumber", "Serializable", "Binary", "Timestamp", "Time", "Internet Address",};
"BigNumber", "Serializable", "Binary", "Timestamp", "Time", "Internet Address",};
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@@ -353,7 +352,10 @@ public class ColumnMetaData {
} }
// If we're dealing with PostgreSQL and double precision types // If we're dealing with PostgreSQL and double precision types
if (desc.getDbType() == ProductTypeEnum.POSTGRESQL && type == java.sql.Types.DOUBLE if ((desc.getProductType() == ProductTypeEnum.POSTGRESQL
|| desc.getProductType() == ProductTypeEnum.GREENPLUM
|| desc.getProductType() == ProductTypeEnum.KINGBASE)
&& type == java.sql.Types.DOUBLE
&& precision >= 16 && precision >= 16
&& length >= 16) { && length >= 16) {
precision = -1; precision = -1;
@@ -362,7 +364,8 @@ public class ColumnMetaData {
// MySQL: max resolution is double precision floating point (double) // MySQL: max resolution is double precision floating point (double)
// The (12,31) that is given back is not correct // The (12,31) that is given back is not correct
if (desc.getDbType() == ProductTypeEnum.MYSQL) { if (desc.getProductType() == ProductTypeEnum.MYSQL
|| desc.getProductType() == ProductTypeEnum.MARIADB) {
if (precision >= length) { if (precision >= length) {
precision = -1; precision = -1;
length = -1; length = -1;
@@ -370,7 +373,7 @@ public class ColumnMetaData {
} }
// If we're dealing with Hive and double/float precision types // If we're dealing with Hive and double/float precision types
if (desc.getDbType() == ProductTypeEnum.HIVE) { if (desc.getProductType() == ProductTypeEnum.HIVE) {
if (type == java.sql.Types.DOUBLE if (type == java.sql.Types.DOUBLE
&& precision >= 15 && precision >= 15
&& length >= 15) { && length >= 15) {
@@ -386,14 +389,9 @@ public class ColumnMetaData {
} }
} }
// if the length or precision needs a BIGNUMBER
//if (length > 15 || precision > 15) {
// valtype = ColumnMetaData.TYPE_BIGNUMBER;
//}
} else { } else {
if (precision == 0) { if (precision == 0) {
if (length <= 18 && length > 0) { // Among others Oracle is affected if (length <= 18 && length > 0) { // Among others Oracle is affected here.
// here.
valtype = ColumnMetaData.TYPE_INTEGER; // Long can hold up to 18 valtype = ColumnMetaData.TYPE_INTEGER; // Long can hold up to 18
// significant digits // significant digits
} else if (length > 18) { } else if (length > 18) {
@@ -406,8 +404,9 @@ public class ColumnMetaData {
} }
} }
if (desc.getDbType() == ProductTypeEnum.POSTGRESQL if (desc.getProductType() == ProductTypeEnum.POSTGRESQL
|| desc.getDbType() == ProductTypeEnum.GREENPLUM) { || desc.getProductType() == ProductTypeEnum.KINGBASE
|| desc.getProductType() == ProductTypeEnum.GREENPLUM) {
// undefined size => arbitrary precision // undefined size => arbitrary precision
if (type == java.sql.Types.NUMERIC && length == 0 && precision == 0) { if (type == java.sql.Types.NUMERIC && length == 0 && precision == 0) {
valtype = ColumnMetaData.TYPE_BIGNUMBER; valtype = ColumnMetaData.TYPE_BIGNUMBER;
@@ -416,7 +415,8 @@ public class ColumnMetaData {
} }
} }
if (desc.getDbType() == ProductTypeEnum.ORACLE) { if (desc.getProductType() == ProductTypeEnum.ORACLE ||
desc.getProductType() == ProductTypeEnum.DM) {
if (precision == 0 && length == 38) { if (precision == 0 && length == 38) {
valtype = ColumnMetaData.TYPE_INTEGER; valtype = ColumnMetaData.TYPE_INTEGER;
} }

View File

@@ -30,9 +30,9 @@ public class DatabaseDescription {
protected String username; protected String username;
protected String password; protected String password;
public DatabaseDescription(String dbtype, String host, int port, String mode, String dbname, public DatabaseDescription(String productType, String host, int port, String mode, String dbname,
String charset, String username, String password) { String charset, String username, String password) {
this.type = ProductTypeEnum.valueOf(dbtype.toUpperCase()); this.type = ProductTypeEnum.valueOf(productType.toUpperCase());
this.host = host; this.host = host;
this.port = port; this.port = port;
this.mode = mode; this.mode = mode;

View File

@@ -14,9 +14,7 @@ import java.util.List;
public class SchemaTableMeta extends TableDescription { public class SchemaTableMeta extends TableDescription {
private List<String> primaryKeys; private List<String> primaryKeys;
private String createSql; private String createSql;
private List<ColumnDescription> columns; private List<ColumnDescription> columns;
public List<String> getPrimaryKeys() { public List<String> getPrimaryKeys() {

View File

@@ -35,9 +35,8 @@ public final class GenerateSqlUtils {
String schemaName, String schemaName,
String tableName, String tableName,
boolean autoIncr) { boolean autoIncr) {
AbstractDatabase db = DatabaseFactory.getDatabaseInstance(type);
return getDDLCreateTableSQL( return getDDLCreateTableSQL(
db, DatabaseFactory.getDatabaseInstance(type),
fieldNames, fieldNames,
primaryKeys, primaryKeys,
schemaName, schemaName,