* Transform a possibly qualified shell-style object name pattern into up to * three SQL-style regular expressions, converting quotes, lower-casing * unquoted letters, and adjusting shell-style wildcard characters into regexp * notation. * * If the dbnamebuf and schemabuf arguments are non-NULL, and the pattern * contains two or more dbname/schema/name separators, we parse the portions of *
| 1178 | * pattern. |
| 1179 | */ |
| 1180 | void |
| 1181 | patternToSQLRegex(int encoding, PQExpBuffer dbnamebuf, PQExpBuffer schemabuf, |
| 1182 | PQExpBuffer namebuf, const char *pattern, bool force_escape, |
| 1183 | bool want_literal_dbname, int *dotcnt) |
| 1184 | { |
| 1185 | PQExpBufferData buf[3]; |
| 1186 | PQExpBufferData left_literal; |
| 1187 | PQExpBuffer curbuf; |
| 1188 | PQExpBuffer maxbuf; |
| 1189 | int i; |
| 1190 | bool inquotes; |
| 1191 | bool left; |
| 1192 | const char *cp; |
| 1193 | |
| 1194 | Assert(pattern != NULL); |
| 1195 | Assert(namebuf != NULL); |
| 1196 | |
| 1197 | /* callers should never expect "dbname.relname" format */ |
| 1198 | Assert(dbnamebuf == NULL || schemabuf != NULL); |
| 1199 | Assert(dotcnt != NULL); |
| 1200 | |
| 1201 | *dotcnt = 0; |
| 1202 | inquotes = false; |
| 1203 | cp = pattern; |
| 1204 | |
| 1205 | if (dbnamebuf != NULL) |
| 1206 | maxbuf = &buf[2]; |
| 1207 | else if (schemabuf != NULL) |
| 1208 | maxbuf = &buf[1]; |
| 1209 | else |
| 1210 | maxbuf = &buf[0]; |
| 1211 | |
| 1212 | curbuf = &buf[0]; |
| 1213 | if (want_literal_dbname) |
| 1214 | { |
| 1215 | left = true; |
| 1216 | initPQExpBuffer(&left_literal); |
| 1217 | } |
| 1218 | else |
| 1219 | left = false; |
| 1220 | initPQExpBuffer(curbuf); |
| 1221 | appendPQExpBufferStr(curbuf, "^("); |
| 1222 | while (*cp) |
| 1223 | { |
| 1224 | char ch = *cp; |
| 1225 | |
| 1226 | if (ch == '"') |
| 1227 | { |
| 1228 | if (inquotes && cp[1] == '"') |
| 1229 | { |
| 1230 | /* emit one quote, stay in inquotes mode */ |
| 1231 | appendPQExpBufferChar(curbuf, '"'); |
| 1232 | if (left) |
| 1233 | appendPQExpBufferChar(&left_literal, '"'); |
| 1234 | cp++; |
| 1235 | } |
| 1236 | else |
| 1237 | inquotes = !inquotes; |
no test coverage detected