MCPcopy Create free account
hub / github.com/apache/cloudberry / patternToSQLRegex

Function patternToSQLRegex

src/fe_utils/string_utils.c:1180–1346  ·  view source on GitHub ↗

* 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 *

Source from the content-addressed store, hash-verified

1178 * pattern.
1179 */
1180void
1181patternToSQLRegex(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;

Callers 4

processSQLNamePatternFunction · 0.85
append_database_patternFunction · 0.85
append_schema_patternFunction · 0.85

Calls 6

initPQExpBufferFunction · 0.85
appendPQExpBufferStrFunction · 0.85
appendPQExpBufferCharFunction · 0.85
pg_tolowerFunction · 0.85
PQmblenBoundedFunction · 0.85
termPQExpBufferFunction · 0.85

Tested by

no test coverage detected