Does the JDBC spec prevent '?' from being used as an operator (outside of quotes)?

前端 未结 3 1050
生来不讨喜
生来不讨喜 2020-11-29 11:01

From Sam Macbeth\'s question:

Is there anything in the JDBC spec which allows a ? to be escaped and be anything other than a parameter placeholder?

3条回答
  •  时光取名叫无心
    2020-11-29 11:51

    I don't see anything in the JDBC specification that would allow ? to be escaped. Pretty much all it says about ? is:

    Parameter markers, represented by “?” in the SQL string, are used to specify input values to the statement that may vary at runtime. [1]

    and later...

    Parameter ordinals, which are integers passed to the approriate setter method, refer to the parameter markers ("?") in the statement, starting at one. [2]

    And it only defines escape syntax for a small set of features, none of which look like they could be applied to ?:

    JDBC defines escape syntax for the following:

    • scalar functions
    • date and time literals
    • outer joins
    • calling stored procedures
    • escape characters for LIKE clauses [3]

    Overall, it doesn't seem like the JDBC specification has very "strict" language (compared to, for example, some W3C specification documents which use must and should a lot), so I don't know whether a driver which allowed ? to be escaped would be technically non-compliant, but it would probably be not-so-compatible.

    It doesn't even look like even the Postgres driver would allow it, as the method in the driver which actually parses SQL statements for ? doesn't check for any escape characters.


    1. JDBC 4.1 Specification, Section 13.2 — The PreparedStatement Interface
    2. JDBC 4.1 Specification, Section 13.3.2 — Setting Parameters
    3. JDBC 4.1 Specification, Section 13.4 — Escape Syntax

提交回复
热议问题