~ubuntu-branches/ubuntu/precise/libpgjava/precise

« back to all changes in this revision

Viewing changes to org/postgresql/core/v2/V2Query.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2008-04-26 22:01:11 UTC
  • mfrom: (3.1.4 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080426220111-yasgxtas5smx2qm3
Tags: 8.2-504-2
* Updated description to mention PostgreSQL 8.3 as supported.
  Closes: #398348
* Removed libpgjava transitional package. Closes: #477557
* Moved debhelper and cdbs from Build-Depends-Indep to Build-Depends.
* Added Homepage, Vcs-Svn and Vcs-Browser fields.
* Added watch file.
* Added myself to Uploaders.
* Removed Stafan and Wolfgang from Uploaders.
* Updated Standards-Version to 3.7.3
* Updated debhelper level to 5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
* Copyright (c) 2004, Open Cloud Limited.
5
5
*
6
6
* IDENTIFICATION
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 $
8
8
*
9
9
*-------------------------------------------------------------------------
10
10
*/
17
17
 * Query implementation for all queries via the V2 protocol.
18
18
 */
19
19
class V2Query implements Query {
20
 
    V2Query(String query, boolean withParameters) {
 
20
    V2Query(String query, boolean withParameters, ProtocolConnection pconn) {
 
21
 
 
22
        useEStringSyntax = pconn.getServerVersion() != null
 
23
                && pconn.getServerVersion().compareTo("8.1") > 0;
 
24
        boolean stdStrings = pconn.getStandardConformingStrings();
 
25
 
21
26
        if (!withParameters)
22
27
        {
23
28
            fragments = new String[] { query };
29
34
        Vector v = new Vector();
30
35
        int lastParmEnd = 0;
31
36
 
32
 
        boolean inSingleQuotes = false;
33
 
        boolean inDoubleQuotes = false;
 
37
        char []aChars = query.toCharArray();
34
38
 
35
 
        for (int i = 0; i < query.length(); ++i)
 
39
        for (int i = 0; i < aChars.length; ++i)
36
40
        {
37
 
            char c = query.charAt(i);
38
 
 
39
 
            switch (c)
 
41
            switch (aChars[i])
40
42
            {
41
 
            case '\\':
42
 
                if (inSingleQuotes)
43
 
                    ++i; // Skip one character.
44
 
                break;
45
 
 
46
 
            case '\'':
47
 
                inSingleQuotes = !inDoubleQuotes && !inSingleQuotes;
48
 
                break;
49
 
 
50
 
            case '"':
51
 
                inDoubleQuotes = !inSingleQuotes && !inDoubleQuotes;
 
43
            case '\'': // single-quotes
 
44
                i = Parser.parseSingleQuotes(aChars, i, stdStrings);
 
45
                break;
 
46
 
 
47
            case '"': // double-quotes
 
48
                i = Parser.parseDoubleQuotes(aChars, i);
 
49
                break;
 
50
 
 
51
            case '-': // possibly -- style comment
 
52
                i = Parser.parseLineComment(aChars, i);
 
53
                break;
 
54
 
 
55
            case '/': // possibly /* */ style comment
 
56
                i = Parser.parseBlockComment(aChars, i);
 
57
                break;
 
58
            
 
59
            case '$': // possibly dollar quote start
 
60
                i = Parser.parseDollarQuotes(aChars, i);
52
61
                break;
53
62
 
54
63
            case '?':
55
 
                if (!inSingleQuotes && !inDoubleQuotes)
56
 
                {
57
 
                    v.addElement(query.substring (lastParmEnd, i));
58
 
                    lastParmEnd = i + 1;
59
 
                }
 
64
                v.addElement(query.substring (lastParmEnd, i));
 
65
                lastParmEnd = i + 1;
60
66
                break;
61
67
 
62
68
            default:
75
81
        if (fragments.length == 1)
76
82
            return NO_PARAMETERS;
77
83
 
78
 
        return new SimpleParameterList(fragments.length - 1);
 
84
        return new SimpleParameterList(fragments.length - 1, useEStringSyntax);
79
85
    }
80
86
 
81
87
    public String toString(ParameterList parameters) {
98
104
        return fragments;
99
105
    }
100
106
 
101
 
    private static final ParameterList NO_PARAMETERS = new SimpleParameterList(0);
 
107
    private static final ParameterList NO_PARAMETERS = new SimpleParameterList(0, false);
102
108
 
103
109
    private final String[] fragments;      // Query fragments, length == # of parameters + 1
 
110
    
 
111
    private final boolean useEStringSyntax; // whether escaped string syntax should be used
104
112
}
105
113