Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix: do not convert ?, ? to $1, $2 when statement.executeQuery(String…
- Loading branch information
Showing
3 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
pgjdbc/src/test/java/org/postgresql/test/jdbc4/JsonbTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*------------------------------------------------------------------------- | ||
* | ||
* Copyright (c) 2004-2016, PostgreSQL Global Development Group | ||
* | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
|
||
package org.postgresql.test.jdbc4; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.postgresql.test.TestUtil; | ||
import org.postgresql.test.jdbc2.BaseTest4; | ||
|
||
import org.junit.Assume; | ||
import org.junit.Test; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
public class JsonbTest extends BaseTest4 { | ||
|
||
public void setUp() throws Exception { | ||
super.setUp(); | ||
Assume.assumeTrue("jsonb requires PostgreSQL 9.4+", TestUtil.haveMinimumServerVersion(con, "9.4")); | ||
TestUtil.createTable(con, "jsonbtest", "detail jsonb"); | ||
Statement stmt = con.createStatement(); | ||
stmt.executeUpdate("INSERT INTO jsonbtest (detail) VALUES ('{\"a\": 1}')"); | ||
stmt.executeUpdate("INSERT INTO jsonbtest (detail) VALUES ('{\"b\": 1}')"); | ||
stmt.executeUpdate("INSERT INTO jsonbtest (detail) VALUES ('{\"c\": 1}')"); | ||
stmt.close(); | ||
} | ||
|
||
public void tearDown() throws SQLException { | ||
TestUtil.dropTable(con, "jsonbtest"); | ||
super.tearDown(); | ||
} | ||
|
||
@Test | ||
public void testJsonbNonPreparedStatement() throws SQLException { | ||
Statement stmt = con.createStatement(); | ||
|
||
ResultSet rs = stmt.executeQuery("SELECT count(1) FROM jsonbtest WHERE detail ? 'a' = false;"); | ||
assertTrue(rs.next()); | ||
assertEquals(2, rs.getInt(1)); | ||
rs.close(); | ||
stmt.close(); | ||
} | ||
|
||
@Test | ||
public void testJsonbPreparedStatement() throws SQLException { | ||
PreparedStatement stmt = con.prepareStatement("SELECT count(1) FROM jsonbtest WHERE detail ?? 'a' = false;"); | ||
ResultSet rs = stmt.executeQuery(); | ||
assertTrue(rs.next()); | ||
assertEquals(2, rs.getInt(1)); | ||
rs.close(); | ||
stmt.close(); | ||
} | ||
} |