GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: binary decoding of bool values (#2640) · pgjdbc/pgjdbc@56a487c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pgjdbc/src
    • main/java/org/postgresql/jdbc
      • PgResultSet.java
    • test/java/org/postgresql/test/jdbc2
      • BaseTest4.java
      • PreparedStatementTest.java
      • ResultSetTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java‎

Copy file name to clipboardExpand all lines: pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,7 @@ public boolean getBoolean(@Positive int columnIndex) throws SQLException {
22972297
int col = columnIndex - 1;
22982298
if (Oid.BOOL == fields[col].getOID()) {
22992299
final byte[] v = value;
2300-
return (1 == v.length) && (116 == v[0]); // 116 = 't'
2300+
return (1 == v.length) && ((116 == v[0] && !isBinary(columnIndex)) || (1 == v[0] && isBinary(columnIndex))); // 116 = 't'
23012301
}
23022302

23032303
if (isBinary(columnIndex)) {
Collapse file

‎pgjdbc/src/test/java/org/postgresql/test/jdbc2/BaseTest4.java‎

Copy file name to clipboardExpand all lines: pgjdbc/src/test/java/org/postgresql/test/jdbc2/BaseTest4.java
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.postgresql.PGConnection;
99
import org.postgresql.PGProperty;
10+
import org.postgresql.core.Oid;
1011
import org.postgresql.core.Version;
1112
import org.postgresql.jdbc.PreferQueryMode;
1213
import org.postgresql.test.TestUtil;
@@ -39,7 +40,7 @@ public enum StringType {
3940
}
4041

4142
protected Connection con;
42-
private BinaryMode binaryMode;
43+
protected BinaryMode binaryMode;
4344
private ReWriteBatchedInserts reWriteBatchedInserts;
4445
protected PreferQueryMode preferQueryMode;
4546
private StringType stringType;
@@ -58,6 +59,7 @@ protected void updateProperties(Properties props) {
5859

5960
protected void forceBinary(Properties props) {
6061
PGProperty.PREPARE_THRESHOLD.set(props, -1);
62+
PGProperty.BINARY_TRANSFER_ENABLE.set(props, Oid.BOOL);
6163
}
6264

6365
public final void setBinaryMode(BinaryMode binaryMode) {
Collapse file

‎pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java‎

Copy file name to clipboardExpand all lines: pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,17 @@ public void testDoubleQuestionMark() throws SQLException {
505505
st = con.prepareStatement("select ??- lseg '((-1,0),(1,0))';");
506506
rs = st.executeQuery();
507507
assertTrue(rs.next());
508-
assertEquals("t", rs.getString(1));
508+
// Bool values in binary mode are first converted to their Java type (Boolean), and then
509+
// converted to String, which means that we receive 'true'. Bool values in text mode are
510+
// returned as the same text value that was returned by the server, i.e. 't'.
511+
assertEquals(binaryMode == BinaryMode.FORCE && preferQueryMode != PreferQueryMode.SIMPLE ? "true" : "t", rs.getString(1));
509512
assertFalse(rs.next());
510513
st.close();
511514

512515
st = con.prepareStatement("select lseg '((-1,0),(1,0))' ??# box '((-2,-2),(2,2))';");
513516
rs = st.executeQuery();
514517
assertTrue(rs.next());
515-
assertEquals("t", rs.getString(1));
518+
assertEquals(binaryMode == BinaryMode.FORCE && preferQueryMode != PreferQueryMode.SIMPLE ? "true" : "t", rs.getString(1));
516519
assertFalse(rs.next());
517520
st.close();
518521
}
Collapse file

‎pgjdbc/src/test/java/org/postgresql/test/jdbc2/ResultSetTest.java‎

Copy file name to clipboardExpand all lines: pgjdbc/src/test/java/org/postgresql/test/jdbc2/ResultSetTest.java
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public void setUp() throws Exception {
7272
stmt.executeUpdate("INSERT INTO testint VALUES (12345)");
7373

7474
// Boolean Tests
75+
TestUtil.createTable(con, "testbool", "a boolean, b int");
76+
stmt.executeUpdate("INSERT INTO testbool VALUES(true, 1)");
77+
stmt.executeUpdate("INSERT INTO testbool VALUES(false, 0)");
78+
7579
TestUtil.createTable(con, "testboolstring", "a varchar(30), b boolean");
7680
stmt.executeUpdate("INSERT INTO testboolstring VALUES('1 ', true)");
7781
stmt.executeUpdate("INSERT INTO testboolstring VALUES('0', false)");
@@ -284,6 +288,14 @@ public void testMaxFieldSize() throws SQLException {
284288
assertEquals("12", new String(rs.getBytes(1)));
285289
}
286290

291+
@Test
292+
public void testBooleanBool() throws SQLException {
293+
testBoolean("testbool", 0);
294+
testBoolean("testbool", 1);
295+
testBoolean("testbool", 5);
296+
testBoolean("testbool", -1);
297+
}
298+
287299
@Test
288300
public void testBooleanString() throws SQLException {
289301
testBoolean("testboolstring", 0);
@@ -332,7 +344,7 @@ public void testBoolean(String table, int prepareThreshold) throws SQLException
332344
}
333345

334346
@Test
335-
public void testgetBooleanJDBCCompliance() throws SQLException {
347+
public void testGetBooleanJDBCCompliance() throws SQLException {
336348
// The JDBC specification in Table B-6 "Use of ResultSet getter Methods to Retrieve JDBC Data Types"
337349
// the getBoolean have this Supported JDBC Type: TINYINT, SMALLINT, INTEGER, BIGINT, REAL, FLOAT,
338350
// DOUBLE, DECIMAL, NUMERIC, BIT, BOOLEAN, CHAR, VARCHAR, LONGVARCHAR

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.