4
4
* Copyright (c) 2004, Open Cloud Limited.
7
* $PostgreSQL: pgjdbc/org/postgresql/core/v2/V2Query.java,v 1.5 2005/01/11 08:25:43 jurka Exp $
7
* $PostgreSQL: pgjdbc/org/postgresql/core/v2/V2Query.java,v 1.7 2006/12/01 08:53:45 jurka Exp $
9
9
*-------------------------------------------------------------------------
17
17
* Query implementation for all queries via the V2 protocol.
19
19
class V2Query implements Query {
20
V2Query(String query, boolean withParameters) {
20
V2Query(String query, boolean withParameters, ProtocolConnection pconn) {
22
useEStringSyntax = pconn.getServerVersion() != null
23
&& pconn.getServerVersion().compareTo("8.1") > 0;
24
boolean stdStrings = pconn.getStandardConformingStrings();
21
26
if (!withParameters)
23
28
fragments = new String[] { query };
29
34
Vector v = new Vector();
30
35
int lastParmEnd = 0;
32
boolean inSingleQuotes = false;
33
boolean inDoubleQuotes = false;
37
char []aChars = query.toCharArray();
35
for (int i = 0; i < query.length(); ++i)
39
for (int i = 0; i < aChars.length; ++i)
37
char c = query.charAt(i);
43
++i; // Skip one character.
47
inSingleQuotes = !inDoubleQuotes && !inSingleQuotes;
51
inDoubleQuotes = !inSingleQuotes && !inDoubleQuotes;
43
case '\'': // single-quotes
44
i = Parser.parseSingleQuotes(aChars, i, stdStrings);
47
case '"': // double-quotes
48
i = Parser.parseDoubleQuotes(aChars, i);
51
case '-': // possibly -- style comment
52
i = Parser.parseLineComment(aChars, i);
55
case '/': // possibly /* */ style comment
56
i = Parser.parseBlockComment(aChars, i);
59
case '$': // possibly dollar quote start
60
i = Parser.parseDollarQuotes(aChars, i);
55
if (!inSingleQuotes && !inDoubleQuotes)
57
v.addElement(query.substring (lastParmEnd, i));
64
v.addElement(query.substring (lastParmEnd, i));
75
81
if (fragments.length == 1)
76
82
return NO_PARAMETERS;
78
return new SimpleParameterList(fragments.length - 1);
84
return new SimpleParameterList(fragments.length - 1, useEStringSyntax);
81
87
public String toString(ParameterList parameters) {
101
private static final ParameterList NO_PARAMETERS = new SimpleParameterList(0);
107
private static final ParameterList NO_PARAMETERS = new SimpleParameterList(0, false);
103
109
private final String[] fragments; // Query fragments, length == # of parameters + 1
111
private final boolean useEStringSyntax; // whether escaped string syntax should be used