Mercurial > hg > monetdb-java
annotate src/main/java/org/monetdb/mcl/parser/HeaderLineParser.java @ 927:d311affc65f0
Stop referring to monetdb.org/bugzilla, point straight to github.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Mon, 07 Oct 2024 13:18:07 +0200 (6 months ago) |
parents | e890195256ac |
children | d416e9b6b3d0 |
rev | line source |
---|---|
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 /* |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
2 * SPDX-License-Identifier: MPL-2.0 |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
3 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
7 * |
833
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
8 * Copyright 2024 MonetDB Foundation; |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
9 * Copyright August 2008 - 2023 MonetDB B.V.; |
e890195256ac
Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents:
716
diff
changeset
|
10 * Copyright 1997 - July 2008 CWI. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
12 |
391
f523727db392
Moved Java classes from packages starting with nl.cwi.monetdb.* to package org.monetdb.*
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
373
diff
changeset
|
13 package org.monetdb.mcl.parser; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
15 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 * The HeaderLineParser is a generic MCLParser that extracts values from |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
665
diff
changeset
|
18 * a metadata header in the MCL protocol either as string or integer values. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 * |
194
1296dbcc4958
Resolved javadoc many errors and warnings, such as:
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
180
diff
changeset
|
20 * @author Fabian Groffen |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
21 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
22 public final class HeaderLineParser extends MCLParser { |
203
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
23 /* types of meta data supported by MCL protocol */ |
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
24 public final static int NAME = 1; // name of column |
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
25 public final static int LENGTH = 2; |
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
26 public final static int TABLE = 3; // may include the schema name |
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
27 public final static int TYPE = 4; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
28 public final static int TYPESIZES = 5; // precision and scale |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
29 |
203
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
30 /** The int values found while parsing. Public, you may touch it. */ |
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
31 public final int intValues[]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
32 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
34 * Constructs a HeaderLineParser which expects columncount columns. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
35 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
36 * @param columncount the number of columns in the to be parsed string |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
37 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
38 public HeaderLineParser(final int columncount) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
39 super(columncount); |
203
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
40 intValues = new int[columncount]; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
41 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
43 /** |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
44 * Parses the given String source as header line. If source cannot |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
45 * be parsed, an MCLParseException is thrown. The columncount argument |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
46 * given during construction is used for allocation of the backing array. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
47 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
48 * @param source a String which should be parsed |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
49 * @return the type of the parsed header line |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
50 * @throws MCLParseException if an error occurs during parsing |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
51 */ |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
52 @Override |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
53 public int parse(final String source) throws MCLParseException { |
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
54 final char[] chrLine = source.toCharArray(); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
55 int len = chrLine.length; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
56 int pos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
57 boolean foundChar = false; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
58 boolean nameFound = false; |
373
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
59 int i; |
203
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
60 |
180
fdf4c888d5b7
Small code and layout improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
119
diff
changeset
|
61 // find header name searching from the end of the line |
373
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
62 for (i = len - 1; i >= 0; i--) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
63 switch (chrLine[i]) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
64 case ' ': |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
65 case '\n': |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
66 case '\t': |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
67 case '\r': |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
68 if (!foundChar) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
69 len = i - 1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
70 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
71 pos = i + 1; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
72 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
73 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
74 case '#': |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
75 // found! |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
76 nameFound = true; |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
77 if (pos == 0) |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
78 pos = i + 1; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
79 i = 0; // force the loop to terminate |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
80 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
81 default: |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
82 foundChar = true; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
83 pos = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
84 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
85 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
86 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
87 if (!nameFound) |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
88 throw new MCLParseException("invalid header, no header name found", pos); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
89 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
90 // depending on the name of the header, we continue |
203
c6abd650aeb4
Reduce memory consumption in TupleLineParser which is a subclass of MCLParser.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
200
diff
changeset
|
91 int type = 0; |
373
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
92 i = pos; |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
93 switch (len - pos) { |
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
94 case 4: |
373
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
95 // source.regionMatches(pos + 1, "name", 0, 4) |
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
96 if (chrLine[i] == 'n' && chrLine[++i] == 'a' && chrLine[++i] == 'm' && chrLine[++i] == 'e') { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
97 getValues(chrLine, 2, pos - 3); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
98 type = NAME; |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
99 } else |
373
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
100 // source.regionMatches(pos + 1, "type", 0, 4) |
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
101 if (chrLine[i] == 't' && chrLine[++i] == 'y' && chrLine[++i] == 'p' && chrLine[++i] == 'e') { |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
102 getValues(chrLine, 2, pos - 3); |
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
103 type = TYPE; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
104 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
105 break; |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
106 case 6: |
373
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
107 // source.regionMatches(pos + 1, "length", 0, 6) |
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
108 if (chrLine[ i ] == 'l' && chrLine[++i] == 'e' && chrLine[++i] == 'n' && chrLine[++i] == 'g' |
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
109 && chrLine[++i] == 't' && chrLine[++i] == 'h') { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
110 getIntValues(chrLine, 2, pos - 3); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
111 type = LENGTH; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
112 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
113 break; |
665
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
114 case 9: |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
115 // System.out.println("In HeaderLineParser.parse() case 9: source line = " + source); |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
116 // source.regionMatches(pos + 1, "typesizes", 0, 9) |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
117 if (chrLine[ i ] == 't' && chrLine[++i] == 'y' && chrLine[++i] == 'p' && chrLine[++i] == 'e' |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
118 && chrLine[++i] == 's' && chrLine[++i] == 'i' && chrLine[++i] == 'z' && chrLine[++i] == 'e' && chrLine[++i] == 's') { |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
119 getValues(chrLine, 2, pos - 3); /* these contain precision and scale values (separated by a space), so read them as strings */ |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
120 type = TYPESIZES; |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
121 } |
8f7d51c478df
Improved implementation of methods ResultSetMetaData.getPrecision() and ResultSetMetaData.getScale().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
610
diff
changeset
|
122 break; |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
123 case 10: |
373
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
124 // source.regionMatches(pos + 1, "table_name", 0, 10) |
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
125 if (chrLine[ i ] == 't' && chrLine[++i] == 'a' && chrLine[++i] == 'b' && chrLine[++i] == 'l' && chrLine[++i] == 'e' |
f15d2ac35932
Optimize HeaderLineParser.parse() method by replacing regionMatches() calls by direct character array comparisons.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
350
diff
changeset
|
126 && chrLine[++i] == '_' && chrLine[++i] == 'n' && chrLine[++i] == 'a' && chrLine[++i] == 'm' && chrLine[++i] == 'e') { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
127 getValues(chrLine, 2, pos - 3); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
128 type = TABLE; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
129 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
130 break; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
131 default: |
180
fdf4c888d5b7
Small code and layout improvements
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
119
diff
changeset
|
132 throw new MCLParseException("unknown header: " + (new String(chrLine, pos, len - pos))); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
133 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
134 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
135 // adjust colno |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
136 colnr = 0; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
137 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
138 return type; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
139 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
140 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
141 /** |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
142 * Fills an array of Strings containing the values between |
104
839ffec1d36d
Fix for bug 6183.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
143 * ',\t' separators. |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
144 * |
104
839ffec1d36d
Fix for bug 6183.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
145 * As of Oct2014-SP1 release MAPI adds double quotes around names when |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
146 * the name contains a comma or a tab or a space or a # or " or \ escape character. |
927
d311affc65f0
Stop referring to monetdb.org/bugzilla, point straight to github.
Sjoerd Mullender <sjoerd@acm.org>
parents:
833
diff
changeset
|
147 * See issue: https://github.com/MonetDB/MonetDB/issues/3616 |
104
839ffec1d36d
Fix for bug 6183.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
148 * If the parsed name string part has a " as first and last character, |
839ffec1d36d
Fix for bug 6183.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
149 * we remove those added double quotes here. |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
150 * |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
151 * @param chrLine a character array holding the input data |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
152 * @param start where the relevant data starts |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
153 * @param stop where the relevant data stops |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
154 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
155 private final void getValues(final char[] chrLine, int start, final int stop) { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
156 int elem = 0; |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
157 boolean inString = false, escaped = false; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
158 |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
159 for (int i = start; i < stop; i++) { |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
160 switch(chrLine[i]) { |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
161 case '\\': |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
162 escaped = !escaped; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
163 break; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
164 case '"': |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
165 /** |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
166 * If all strings are wrapped between two quotes, a \" can |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
167 * never exist outside a string. Thus if we believe that we |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
168 * are not within a string, we can safely assume we're about |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
169 * to enter a string if we find a quote. |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
170 * If we are in a string we should stop being in a string if |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
171 * we find a quote which is not prefixed by a \, for that |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
172 * would be an escaped quote. However, a nasty situation can |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
173 * occur where the string is like "test \\" as obvious, a |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
174 * test for a \ in front of a " doesn't hold here for all |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
175 * cases. Because "test \\\"" can exist as well, we need to |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
176 * know if a quote is prefixed by an escaping slash or not. |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
177 */ |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
178 if (!inString) { |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
179 inString = true; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
180 } else if (!escaped) { |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
181 inString = false; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
182 } |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
183 // reset escaped flag |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
184 escaped = false; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
185 break; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
186 case ',': |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
187 if (!inString && chrLine[i + 1] == '\t') { |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
188 // we found the field separator |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
189 if (chrLine[start] == '"') |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
190 start++; // skip leading double quote |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
191 if (elem < values.length) { |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
192 // TODO: also deal with escape characters as done in TupleLineParser.parse() |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
193 values[elem++] = new String(chrLine, start, i - (chrLine[i - 1] == '"' ? 1 : 0) - start); |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
194 } |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
195 i++; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
196 start = i + 1; // reset start for the next name, skipping the field separator (a comma and tab) |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
197 } |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
198 // reset escaped flag |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
199 escaped = false; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
200 break; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
201 default: |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
202 escaped = false; |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
203 break; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
204 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
205 } |
104
839ffec1d36d
Fix for bug 6183.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
206 // add the left over part (last column) |
839ffec1d36d
Fix for bug 6183.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
207 if (chrLine[start] == '"') |
839ffec1d36d
Fix for bug 6183.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
90
diff
changeset
|
208 start++; // skip leading double quote |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
209 if (elem < values.length) |
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
210 values[elem] = new String(chrLine, start, stop - (chrLine[stop - 1] == '"' ? 1 : 0) - start); |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
211 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
212 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
213 /** |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
214 * Fills an array of ints containing the values between |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
215 * ',\t' separators. |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
216 * |
116
04c535b05c52
Fixed negative number parsing on the StartOfHeaderParser
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
104
diff
changeset
|
217 * Feb2017 note - This integer parser doesn't have to parse negative |
04c535b05c52
Fixed negative number parsing on the StartOfHeaderParser
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
104
diff
changeset
|
218 * numbers, because it is only used to parse column lengths |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
219 * which are always greater than 0. |
116
04c535b05c52
Fixed negative number parsing on the StartOfHeaderParser
Pedro Ferreira <pedro.ferreira@monetdbsolutions.com>
parents:
104
diff
changeset
|
220 * |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
221 * @param chrLine a character array holding the input data |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
222 * @param start where the relevant data starts |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
223 * @param stop where the relevant data stops |
709
bdeabbd46ec6
Resolve javac and javadoc warnings when compiled with JDK19.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
665
diff
changeset
|
224 * @throws MCLParseException if an error occurs during parsing |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
225 */ |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
226 private final void getIntValues(final char[] chrLine, final int start, final int stop) throws MCLParseException { |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
227 int elem = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
228 int tmp = 0; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
229 |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
230 for (int i = start; i < stop; i++) { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
231 if (chrLine[i] == ',' && chrLine[i + 1] == '\t') { |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
232 if (elem < intValues.length) { |
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
233 intValues[elem++] = tmp; |
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
234 } |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
235 tmp = 0; |
297
bb273e9c7e09
Add "final" keyword to classes, method arguments and local variables where possible.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
261
diff
changeset
|
236 i++; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
237 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
238 // note: don't use Character.isDigit() here, because |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
239 // we only want ISO-LATIN-1 digits |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
240 if (chrLine[i] >= '0' && chrLine[i] <= '9') { |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
241 tmp *= 10; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
242 tmp += (int)chrLine[i] - (int)'0'; |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
243 } else { |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
244 throw new MCLParseException("expected a digit in " + new String(chrLine) + " at " + i); |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
245 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
246 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
247 } |
119
1ea2ee3b946c
Extend HeaderLineParser to also correctly parse result set header lines for table
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
117
diff
changeset
|
248 // add the left over part (last column) |
325
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
249 if (elem < intValues.length) |
0b8eb1df8276
Optimised parsing of Header line data.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
297
diff
changeset
|
250 intValues[elem] = tmp; |
0
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
251 } |
a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
252 } |