Compare commits
13 Commits
209b55d310
...
3095542f1d
Author | SHA1 | Date | |
---|---|---|---|
3095542f1d | |||
d80fa4c0a4 | |||
9895893028 | |||
e2fe619c98 | |||
572a7a498d | |||
0e04f5729b | |||
ba28c04195 | |||
e86fb4760b | |||
6dc658d33b | |||
48da005ade | |||
b7ff2380af | |||
d760e172eb | |||
18eac11b99 |
3
build.sh
3
build.sh
@ -28,6 +28,7 @@ bit=$(getconf LONG_BIT)
|
||||
if [ "$bit" -eq 64 ]; then
|
||||
PLATFORM=64
|
||||
fi
|
||||
PKG_VERSION=6.0.0
|
||||
#get OS distributed version.
|
||||
kernel=""
|
||||
version=""
|
||||
@ -113,7 +114,7 @@ function install_jdbc()
|
||||
export COMMIT=$(git rev-parse --short HEAD)
|
||||
export OPENGAUSS_PACKAGE_NAME="org.opengauss";
|
||||
|
||||
export GS_VERSION="compiled at $(date +%Y-%m-%d-%H:%M:%S) build ${COMMIT}"
|
||||
export GS_VERSION="openGauss-JDBC ${PKG_VERSION} build ${COMMIT} compiled at $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
export OUTPUT_DIR="${JDBC_DIR}/output"
|
||||
echo "Begin make jdbc..."
|
||||
export CLASSPATH=".:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar"
|
||||
|
@ -4,7 +4,7 @@
|
||||
<groupId>org.opengauss</groupId>
|
||||
<artifactId>opengauss-jdbc</artifactId>
|
||||
<name>openGauss JDBC Driver</name>
|
||||
<version>6.0.0-RC1</version>
|
||||
<version>6.0.0</version>
|
||||
<description>Java JDBC driver for openGauss</description>
|
||||
<url>https://gitee.com/opengauss/openGauss-connector-jdbc</url>
|
||||
|
||||
|
@ -27,6 +27,14 @@ public class Oid {
|
||||
public static final int INT4 = 23;
|
||||
public static final int INT4_ARRAY = 1007;
|
||||
public static final int INT8 = 20;
|
||||
public static int UINT1 = 4401;
|
||||
public static int UINT1_ARRAY = 3001;
|
||||
public static int UINT2 = 4403;
|
||||
public static int UINT2_ARRAY = 3002;
|
||||
public static int UINT4 = 4405;
|
||||
public static int UINT4_ARRAY = 3003;
|
||||
public static int UINT8 = 4407;
|
||||
public static int UINT8_ARRAY = 3004;
|
||||
public static final int INT8_ARRAY = 1016;
|
||||
public static final int TEXT = 25;
|
||||
public static final int TEXT_ARRAY = 1009;
|
||||
|
@ -42,6 +42,13 @@ public interface TypeInfo {
|
||||
*/
|
||||
void setPGTypes() throws SQLException;
|
||||
|
||||
/**
|
||||
* cache db type, A/B/C/PG
|
||||
* cache b_compatibility_mode, on or off
|
||||
* @return
|
||||
*/
|
||||
void setDBType() throws SQLException;
|
||||
|
||||
/**
|
||||
* Look up the oid for a given postgresql type name. This is the inverse of
|
||||
* {@link #getPGType(int)}.
|
||||
|
@ -332,6 +332,7 @@ public class PgConnection implements BaseConnection {
|
||||
// Initialize object handling
|
||||
_typeCache = createTypeInfo(this, unknownLength);
|
||||
_typeCache.setPGTypes();
|
||||
_typeCache.setDBType();
|
||||
initObjectTypes(info);
|
||||
|
||||
if (PGProperty.LOG_UNCLOSED_CONNECTIONS.getBoolean(info)) {
|
||||
|
@ -270,6 +270,8 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS
|
||||
return getInt(columnIndex);
|
||||
case Types.BIGINT:
|
||||
return getLong(columnIndex);
|
||||
case TypeInfoCache.bIntegerType:
|
||||
return getBigInteger(columnIndex);
|
||||
case Types.NUMERIC:
|
||||
case Types.DECIMAL:
|
||||
return getBigDecimal(columnIndex,
|
||||
@ -2089,9 +2091,9 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS
|
||||
} else if (blobSet.contains(typeName)) {
|
||||
return new String(toBytes(result));
|
||||
} else if ("time".equals(typeName)) {
|
||||
java.util.Calendar cal = getDefaultCalendar();
|
||||
Time time = connection.getTimestampUtils().toTime(cal, result);
|
||||
return String.valueOf(time);
|
||||
char[] cs = result.toCharArray();
|
||||
int start = TimestampUtils.firstDigit(cs, 0);
|
||||
result = result.substring(start);
|
||||
}
|
||||
return result;
|
||||
} catch (IOException ioe) {
|
||||
@ -2337,6 +2339,19 @@ public class PgResultSet implements ResultSet, org.postgresql.PGRefCursorResultS
|
||||
return toLong(getFixedString(columnIndex));
|
||||
}
|
||||
|
||||
public BigInteger getBigInteger(int columnIndex) throws SQLException {
|
||||
String stringVal = getString(columnIndex);
|
||||
if (stringVal == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new BigInteger(stringVal);
|
||||
} catch (NumberFormatException ex) {
|
||||
connection.getLogger().trace("[" + connection.getSocketAddress() + "] " + "format BigInteger failed.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A dummy exception thrown when fast byte[] to number parsing fails and no value can be returned.
|
||||
* The exact stack trace does not matter because the exception is always caught and is not visible
|
||||
|
@ -954,7 +954,13 @@ public class TimestampUtils {
|
||||
return slen;
|
||||
}
|
||||
|
||||
private static int firstDigit(char[] s, int start) {
|
||||
/**
|
||||
* format timestamp
|
||||
* @param s
|
||||
* @param start
|
||||
* @return
|
||||
*/
|
||||
public static int firstDigit(char[] s, int start) {
|
||||
int slen = s.length;
|
||||
for (int i = start; i < slen; i++) {
|
||||
if (Character.isDigit(s[i])) {
|
||||
|
@ -68,6 +68,12 @@ public class TypeInfoCache implements TypeInfo {
|
||||
|
||||
private static ConcurrentHashMap<Integer, String> pgTypes = new ConcurrentHashMap<>();
|
||||
|
||||
public static final int bIntegerType = 1324;
|
||||
|
||||
public static String sqlCompatibility = "A";
|
||||
|
||||
public static String dolphinMode = "off";
|
||||
|
||||
// basic pg types info:
|
||||
// 0 - type name
|
||||
// 1 - type oid
|
||||
@ -80,6 +86,10 @@ public class TypeInfoCache implements TypeInfo {
|
||||
{"int4", Oid.INT4, Types.INTEGER, "java.lang.Integer", Oid.INT4_ARRAY},
|
||||
{"oid", Oid.OID, Types.BIGINT, "java.lang.Long", Oid.OID_ARRAY},
|
||||
{"int8", Oid.INT8, Types.BIGINT, "java.lang.Long", Oid.INT8_ARRAY},
|
||||
{"uint1", Oid.UINT1, Types.SMALLINT, "java.lang.Integer", Oid.UINT1_ARRAY},
|
||||
{"uint2", Oid.UINT2, Types.INTEGER, "java.lang.Integer", Oid.UINT2_ARRAY},
|
||||
{"uint4", Oid.UINT4, Types.BIGINT, "java.lang.Long", Oid.UINT4_ARRAY},
|
||||
{"uint8", Oid.UINT8, bIntegerType, "java.math.BigInteger", Oid.UINT8_ARRAY},
|
||||
{"money", Oid.MONEY, Types.DOUBLE, "java.lang.Double", Oid.MONEY_ARRAY},
|
||||
{"numeric", Oid.NUMERIC, Types.NUMERIC, "java.math.BigDecimal", Oid.NUMERIC_ARRAY},
|
||||
{"float4", Oid.FLOAT4, Types.REAL, "java.lang.Float", Oid.FLOAT4_ARRAY},
|
||||
@ -380,7 +390,17 @@ public class TypeInfoCache implements TypeInfo {
|
||||
}
|
||||
|
||||
public synchronized void setPGTypes() throws SQLException {
|
||||
String sql = "SELECT t.oid, t.typname FROM pg_catalog.pg_type t where t.typname = 'year';";
|
||||
String sql = "SELECT t.oid, t.typname FROM pg_catalog.pg_type t "
|
||||
+ " where t.typname = 'year'"
|
||||
+ " or t.typname = 'uint1'"
|
||||
+ " or t.typname = 'uint2'"
|
||||
+ " or t.typname = 'uint4'"
|
||||
+ " or t.typname = 'uint8'"
|
||||
+ " or t.typname = '_uint1'"
|
||||
+ " or t.typname = '_uint2'"
|
||||
+ " or t.typname = '_uint4'"
|
||||
+ " or t.typname = '_uint8';";
|
||||
|
||||
PreparedStatement pgTypeStatement = _conn.prepareStatement(sql);
|
||||
// Go through BaseStatement to avoid transaction start.
|
||||
if (!((BaseStatement) pgTypeStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN)) {
|
||||
@ -394,13 +414,61 @@ public class TypeInfoCache implements TypeInfo {
|
||||
Integer oid = (int) rs.getLong(1);
|
||||
String typeName = rs.getString(2);
|
||||
pgTypes.put(oid, typeName);
|
||||
_pgNameToOid.put(typeName, oid);
|
||||
_oidToPgName.put(oid, typeName);
|
||||
if (typeName.startsWith("_")) {
|
||||
String arrType = typeName.substring(1) + "[]";
|
||||
_pgNameToOid.put(arrType, oid);
|
||||
}
|
||||
|
||||
Character delim = ',';
|
||||
_arrayOidToDelimiter.put(oid, delim);
|
||||
}
|
||||
_pgArrayToPgType.put(_pgNameToOid.get("_uint1"), _pgNameToOid.get("uint1"));
|
||||
_pgArrayToPgType.put(_pgNameToOid.get("_uint2"), _pgNameToOid.get("uint2"));
|
||||
_pgArrayToPgType.put(_pgNameToOid.get("_uint4"), _pgNameToOid.get("uint4"));
|
||||
_pgArrayToPgType.put(_pgNameToOid.get("_uint8"), _pgNameToOid.get("uint8"));
|
||||
}
|
||||
|
||||
public static Map<Integer, String> getPGTypes() {
|
||||
return pgTypes;
|
||||
}
|
||||
|
||||
|
||||
public void setDBType() throws SQLException {
|
||||
String compatibilitySql = "show sql_compatibility;";
|
||||
String compatibility = getDBParam(compatibilitySql);
|
||||
if (compatibility != null) {
|
||||
sqlCompatibility = compatibility;
|
||||
if ("B".equals(compatibility)) {
|
||||
String dolphinSql = "show dolphin.b_compatibility_mode;";
|
||||
String dolphin = getDBParam(dolphinSql);
|
||||
if (dolphin != null) {
|
||||
dolphinMode = dolphin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getDBParam(String sql) throws SQLException {
|
||||
PreparedStatement dbStatement = _conn.prepareStatement(sql);
|
||||
if (!((BaseStatement) dbStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN)) {
|
||||
throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA);
|
||||
}
|
||||
ResultSet rs = dbStatement.getResultSet();
|
||||
if (rs != null && rs.next()) {
|
||||
return rs.getString(1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDolphinMode(){
|
||||
return dolphinMode;
|
||||
}
|
||||
|
||||
public static String getSqlCompatibility(){
|
||||
return sqlCompatibility;
|
||||
}
|
||||
|
||||
public synchronized int getPGType(String pgTypeName) throws SQLException {
|
||||
Integer oid = _pgNameToOid.get(pgTypeName);
|
||||
if (oid != null) {
|
||||
|
@ -0,0 +1,34 @@
|
||||
package org.postgresql.test.dolphintest;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.postgresql.test.TestUtil;
|
||||
import org.postgresql.test.jdbc2.BaseTest4B;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DolphinTest extends BaseTest4B {
|
||||
|
||||
/**
|
||||
* test db type and dolphin mode
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testUint1() throws SQLException {
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rsDBType = stmt.executeQuery("show sql_compatibility;");
|
||||
|
||||
assertTrue(rsDBType.next());
|
||||
String r1 = rsDBType.getString(1);
|
||||
assertNotNull(r1);
|
||||
assertEquals("B", r1);
|
||||
|
||||
ResultSet rsMode = stmt.executeQuery("show dolphin.b_compatibility_mode;");
|
||||
|
||||
assertTrue(rsMode.next());
|
||||
String r2 = rsMode.getString(1);
|
||||
assertNotNull(r2);
|
||||
assertEquals("on", r2);
|
||||
}
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package org.postgresql.test.dolphintest;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.postgresql.test.TestUtil;
|
||||
import org.postgresql.test.jdbc2.BaseTest4B;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class UnsignedTest extends BaseTest4B {
|
||||
/**
|
||||
* test uint1 type
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testUint1() throws SQLException {
|
||||
TestUtil.createTable(con, "test_unit1", "id uint1");
|
||||
|
||||
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test_unit1 VALUES (?)");
|
||||
pstmt.setObject(1, 234, Types.SMALLINT);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id FROM test_unit1");
|
||||
|
||||
assertTrue(rs.next());
|
||||
Object r1 = rs.getObject(1);
|
||||
assertNotNull(r1);
|
||||
assertEquals(234, r1);
|
||||
|
||||
TestUtil.dropTable(con, "test_unit1");
|
||||
}
|
||||
|
||||
/**
|
||||
* test uint2 type
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testUint2() throws SQLException {
|
||||
TestUtil.createTable(con, "test_unit2", "id uint2");
|
||||
|
||||
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test_unit2 VALUES (?)");
|
||||
pstmt.setObject(1, 65518, Types.INTEGER);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id FROM test_unit2");
|
||||
|
||||
assertTrue(rs.next());
|
||||
Object r1 = rs.getObject(1);
|
||||
assertNotNull(r1);
|
||||
assertEquals(65518, r1);
|
||||
|
||||
TestUtil.dropTable(con, "test_unit2");
|
||||
}
|
||||
|
||||
/**
|
||||
* test uint4 type
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testUint4() throws SQLException {
|
||||
TestUtil.createTable(con, "test_unit4", "id uint4");
|
||||
|
||||
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test_unit4 VALUES (?)");
|
||||
long l = 4294967282L;
|
||||
pstmt.setObject(1, l, Types.BIGINT);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id FROM test_unit4");
|
||||
|
||||
assertTrue(rs.next());
|
||||
Object r1 = rs.getObject(1);
|
||||
assertNotNull(r1);
|
||||
assertEquals(l, r1);
|
||||
|
||||
TestUtil.dropTable(con, "test_unit4");
|
||||
}
|
||||
|
||||
/**
|
||||
* test uint8 type
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testUint8() throws SQLException {
|
||||
TestUtil.createTable(con, "test_unit8", "id uint8");
|
||||
|
||||
PreparedStatement pstmt = con.prepareStatement("INSERT INTO test_unit8 VALUES (?)");
|
||||
BigInteger b = new BigInteger("9223372036859999999");
|
||||
pstmt.setObject(1, b, Types.NUMERIC);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
BigInteger b2 = new BigInteger("15223372036859999999");
|
||||
pstmt.setObject(1, b2, Types.NUMERIC);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
Statement stmt = con.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT id FROM test_unit8");
|
||||
|
||||
assertTrue(rs.next());
|
||||
Object r1 = rs.getObject(1);
|
||||
assertNotNull(r1);
|
||||
assertEquals(b, r1);
|
||||
|
||||
assertTrue(rs.next());
|
||||
Object r2 = rs.getObject(1);
|
||||
assertNotNull(r2);
|
||||
assertEquals(b2, r2);
|
||||
|
||||
TestUtil.dropTable(con, "test_unit8");
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package org.postgresql.test.jdbc2;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.postgresql.test.TestUtil;
|
||||
|
||||
@ -19,6 +20,7 @@ import static org.junit.Assert.fail;
|
||||
/**
|
||||
* Adaptation overload function use case set.
|
||||
*/
|
||||
@Ignore
|
||||
public class ProcOutparamOverrideTest extends BaseTest4 {
|
||||
/**
|
||||
* The sql of the create proc.
|
||||
|
@ -45,6 +45,7 @@ public class EncodingTest extends BaseTest4 {
|
||||
TestUtil.dropTable(con, "test_encode");
|
||||
|
||||
Properties properties2 = new Properties();
|
||||
properties2.put("allowEncodingChanges", "true");
|
||||
properties2.put("characterEncoding", "GBK");
|
||||
con = TestUtil.openDB(properties2);
|
||||
|
||||
@ -57,6 +58,7 @@ public class EncodingTest extends BaseTest4 {
|
||||
assertEquals("GBK", e2);
|
||||
|
||||
Properties properties3 = new Properties();
|
||||
properties3.put("allowEncodingChanges", "true");
|
||||
properties3.put("characterEncoding", "LATIN2");
|
||||
con = TestUtil.openDB(properties3);
|
||||
|
||||
|
@ -100,8 +100,6 @@ public class GetObject310Test extends BaseTest4 {
|
||||
* Test the behavior getObject for time columns.
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO
|
||||
public void testGetLocalTime() throws SQLException {
|
||||
Statement stmt = con.createStatement();
|
||||
stmt.executeUpdate(TestUtil.insertSQL("table1","time_without_time_zone_column","TIME '04:05:06.123456'"));
|
||||
|
@ -291,8 +291,6 @@ public class SetObject310Test extends BaseTest4PG {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO
|
||||
public void testTimeStampRounding() throws SQLException {
|
||||
LocalTime time = LocalTime.parse("23:59:59.999999500");
|
||||
Time actual = insertThenReadWithoutType(time, "time_without_time_zone_column", Time.class);
|
||||
@ -300,8 +298,6 @@ public class SetObject310Test extends BaseTest4PG {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
// TODO
|
||||
public void testTimeStampRoundingWithType() throws SQLException {
|
||||
LocalTime time = LocalTime.parse("23:59:59.999999500");
|
||||
Time actual =
|
||||
|
Reference in New Issue
Block a user