| 118 | |
| 119 | const INVALID_QUERY_REGEX = /[!"#$%&'()*+,\-./:;<>=?@[\\\]^_`{|}~§]/; |
| 120 | function escapeSQLString(str: string): string { |
| 121 | if (str.startsWith('"') && str.endsWith('"')) { |
| 122 | const innerStr = str.slice(1, -1).replace(/"/g, '""'); |
| 123 | return `"${innerStr}"`; |
| 124 | } |
| 125 | |
| 126 | const hasInvalidSymbol = INVALID_QUERY_REGEX.test(str); |
| 127 | const isWildcard = |
| 128 | str.startsWith("*") || |
| 129 | str.endsWith("*") || |
| 130 | str.startsWith("%") || |
| 131 | str.endsWith("%"); |
| 132 | if (hasInvalidSymbol || isWildcard) { |
| 133 | return `"${str}"`; |
| 134 | } |
| 135 | |
| 136 | // if (isWildcard) { |
| 137 | // return str.replace(/(.+?)(\*?$)/gm, (_, text, end) => { |
| 138 | // return `${escapeSQLString(text)}${end}`; |
| 139 | // }); |
| 140 | // } |
| 141 | |
| 142 | // if (str.includes("-")) { |
| 143 | // return `"${str.replace(/"/g, '""')}"`; |
| 144 | // } |
| 145 | |
| 146 | return str.replace(/"/g, '""'); |
| 147 | } |
| 148 | |
| 149 | function tokenizeWithFields( |
| 150 | query: string |