Compare commits

...

13 Commits

Author SHA1 Message Date
3095542f1d !246 增加打包构建时间和commitid信息
Merge pull request !246 from zhangxubo/cherry-pick-1716624442
2024-05-25 08:26:08 +00:00
d80fa4c0a4 update build.sh.
Signed-off-by: zhangxubo <2578876417@qq.com>
2024-05-25 08:08:24 +00:00
9895893028 fixed fbefccd from https://gitee.com/zhang_xubo/openGauss-connector-jdbc/pulls/245
增加打包构建时间和commitid信息
2024-05-25 08:07:22 +00:00
e2fe619c98 !242 实现jdbc查询数据库类型以及dolphin参数
Merge pull request !242 from zhangtingtingting/7.2.1
2024-05-25 03:23:40 +00:00
572a7a498d 实现jdbc查询数据库类型以及dolphin参数 2024-05-24 09:51:48 +08:00
0e04f5729b !239 修复B模式下 uint1/uint2/uint4/uint8 的getObject类型为PGobject与M*不一致问题
Merge pull request !239 from zhangtingtingting/7.2.1
2024-05-20 06:20:10 +00:00
ba28c04195 修复B模式下 uint1/uint2/uint4/uint8 的getObject类型为PGobject与M*不一致问题 2024-05-17 18:59:18 +08:00
e86fb4760b !235 更新版本至6.0.0
Merge pull request !235 from 李锦波/master
2024-05-15 07:08:35 +00:00
6dc658d33b !232 处理字符集报错问题
Merge pull request !232 from zhangtingtingting/8.0.2
2024-05-14 08:08:21 +00:00
48da005ade 处理字符集报错问题 2024-05-14 15:55:30 +08:00
b7ff2380af 更新版本至6.0.0
Signed-off-by: 李锦波 <lijinbo22@huawei.com>
2024-05-14 03:41:12 +00:00
d760e172eb !226 处理time类型丢失秒后的精度问题
Merge pull request !226 from zhangtingtingting/7.1.9
2024-05-13 01:07:41 +00:00
18eac11b99 处理time类型丢失秒后的精度问题 2024-05-09 10:22:33 +08:00
14 changed files with 270 additions and 14 deletions

View File

@ -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"

View File

@ -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>

View File

@ -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;

View File

@ -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)}.

View File

@ -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)) {

View File

@ -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

View File

@ -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])) {

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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");
}
}

View File

@ -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.

View File

@ -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);

View File

@ -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'"));

View File

@ -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 =