Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new "escapeSyntaxCallMode" connection property
The "escapeSyntaxCallMode" connection property allows you to specify how the driver transforms JDBC escape call syntax into underlying SQL, for invoking procedures and functions. The possible values of this property are: select, callIfNoReturn, or call In escapeSyntaxCallMode=select mode (the default), the driver always uses a SELECT statement (allowing function invocation only). In escapeSyntaxCallMode=callIfNoReturn mode, the driver uses a CALL statement (allowing procedure invocation) if there is no return parameter specified, otherwise the driver uses a SELECT statement. In escapeSyntaxCallMode=call mode, the driver always uses a CALL statement (allowing procedure invocation only). Prior to the addition of this connection property, the driver always used a SELECT statement for JDBC escape call syntax, which results in the following error when attempting to invoke a procedure: ERROR: xxxx is a procedure Hint: To call a procedure, use CALL
- Loading branch information
Showing
16 changed files
with
427 additions
and
15 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
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
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
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
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
38 changes: 38 additions & 0 deletions
38
pgjdbc/src/main/java/org/postgresql/jdbc/EscapeSyntaxCallMode.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,38 @@ | ||
/* | ||
* Copyright (c) 2019, PostgreSQL Global Development Group | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
package org.postgresql.jdbc; | ||
|
||
/** | ||
* <p>Specifies whether a SELECT/CALL statement is used for the underlying SQL for JDBC escape call syntax: 'select' means to | ||
* always use SELECT, 'callIfNoReturn' means to use CALL if there is no return parameter (otherwise use SELECT), and 'call' means | ||
* to always use CALL.</p> | ||
* | ||
* @see org.postgresql.PGProperty#ESCAPE_SYNTAX_CALL_MODE | ||
*/ | ||
public enum EscapeSyntaxCallMode { | ||
SELECT("select"), | ||
CALL_IF_NO_RETURN("callIfNoReturn"), | ||
CALL("call"); | ||
|
||
private final String value; | ||
|
||
EscapeSyntaxCallMode(String value) { | ||
this.value = value; | ||
} | ||
|
||
public static EscapeSyntaxCallMode of(String mode) { | ||
for (EscapeSyntaxCallMode escapeSyntaxCallMode : values()) { | ||
if (escapeSyntaxCallMode.value.equals(mode)) { | ||
return escapeSyntaxCallMode; | ||
} | ||
} | ||
return SELECT; | ||
} | ||
|
||
public String value() { | ||
return value; | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
pgjdbc/src/test/java/org/postgresql/test/jdbc3/EscapeSyntaxCallModeBaseTest.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,43 @@ | ||
/* | ||
* Copyright (c) 2019, PostgreSQL Global Development Group | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
package org.postgresql.test.jdbc3; | ||
|
||
import org.postgresql.core.ServerVersion; | ||
import org.postgresql.test.TestUtil; | ||
import org.postgresql.test.jdbc2.BaseTest4; | ||
|
||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
public class EscapeSyntaxCallModeBaseTest extends BaseTest4 { | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
Statement stmt = con.createStatement(); | ||
stmt.execute( | ||
"CREATE OR REPLACE FUNCTION myiofunc(a INOUT int, b OUT int) AS 'BEGIN b := a; a := 1; END;' LANGUAGE plpgsql"); | ||
stmt.execute( | ||
"CREATE OR REPLACE FUNCTION mysumfunc(a int, b int) returns int AS 'BEGIN return a + b; END;' LANGUAGE plpgsql"); | ||
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v11)) { | ||
stmt.execute( | ||
"CREATE OR REPLACE PROCEDURE myioproc(a INOUT int, b INOUT int) AS 'BEGIN b := a; a := 1; END;' LANGUAGE plpgsql"); | ||
} | ||
} | ||
|
||
@Override | ||
public void tearDown() throws SQLException { | ||
Statement stmt = con.createStatement(); | ||
stmt.execute("drop function myiofunc(a INOUT int, b OUT int) "); | ||
stmt.execute("drop function mysumfunc(a int, b int) "); | ||
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v11)) { | ||
stmt.execute("drop procedure myioproc(a INOUT int, b INOUT int) "); | ||
} | ||
stmt.close(); | ||
super.tearDown(); | ||
} | ||
|
||
} |
Oops, something went wrong.