|
1 | | -/* |
2 | | - * Copyright (c) 2011-2026 LabKey Corporation |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
7 | | - * |
8 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
15 | | - */ |
16 | | - |
17 | | -package org.labkey.core.dialect; |
18 | | - |
19 | | -import org.apache.commons.lang3.StringUtils; |
20 | | -import org.labkey.api.data.dialect.StandardDialectStringHandler; |
21 | | - |
22 | | -/* |
23 | | -* User: adam |
24 | | -* Date: Aug 13, 2011 |
25 | | -* Time: 4:10:10 PM |
26 | | -*/ |
27 | | - |
28 | | -// Adds support for backslash escaping in string literals |
29 | | -public class PostgreSqlNonConformingStringHandler extends StandardDialectStringHandler |
30 | | -{ |
31 | | - @Override |
32 | | - public String quoteStringLiteral(String str) |
33 | | - { |
34 | | - return "'" + StringUtils.replace(StringUtils.replace(str, "\\", "\\\\"), "'", "''") + "'"; |
35 | | - } |
36 | | - |
37 | | - |
38 | | - @Override |
39 | | - protected int findEndOfStringLiteral(CharSequence sql, int current) |
40 | | - { |
41 | | - boolean skipNext = false; |
42 | | - |
43 | | - while (current < sql.length()) |
44 | | - { |
45 | | - char c = sql.charAt(current++); |
46 | | - |
47 | | - if (skipNext) |
48 | | - { |
49 | | - skipNext = false; |
50 | | - } |
51 | | - else |
52 | | - { |
53 | | - if (c == '\\') |
54 | | - { |
55 | | - skipNext = true; |
56 | | - continue; |
57 | | - } |
58 | | - else if (c == '\'') |
59 | | - { |
60 | | - break; |
61 | | - } |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - return current; |
66 | | - } |
67 | | -} |
| 1 | +/* |
| 2 | + * Copyright (c) 2011-2026 LabKey Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.labkey.api.data.dialect; |
| 18 | + |
| 19 | +import org.apache.commons.lang3.Strings; |
| 20 | + |
| 21 | +// Adds support for backslash escaping in string literals |
| 22 | +public class BackslashEscapingStringHandler extends StandardDialectStringHandler |
| 23 | +{ |
| 24 | + @Override |
| 25 | + public String quoteStringLiteral(String str) |
| 26 | + { |
| 27 | + return "'" + Strings.CS.replace(Strings.CS.replace(str, "\\", "\\\\"), "'", "''") + "'"; |
| 28 | + } |
| 29 | + |
| 30 | + |
| 31 | + @Override |
| 32 | + protected int findEndOfStringLiteral(CharSequence sql, int current) |
| 33 | + { |
| 34 | + boolean skipNext = false; |
| 35 | + |
| 36 | + while (current < sql.length()) |
| 37 | + { |
| 38 | + char c = sql.charAt(current++); |
| 39 | + |
| 40 | + if (skipNext) |
| 41 | + { |
| 42 | + skipNext = false; |
| 43 | + } |
| 44 | + else |
| 45 | + { |
| 46 | + if (c == '\\') |
| 47 | + { |
| 48 | + skipNext = true; |
| 49 | + } |
| 50 | + else if (c == '\'') |
| 51 | + { |
| 52 | + break; |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + return current; |
| 58 | + } |
| 59 | +} |
0 commit comments