cleanDefaultExpression cleans up Oracle default expressions to make them more portable and fix common syntax issues like schema-qualified sequence NEXTVAL calls
(defaultExpr, currentSchema string)
| 1319 | // cleanDefaultExpression cleans up Oracle default expressions to make them more portable |
| 1320 | // and fix common syntax issues like schema-qualified sequence NEXTVAL calls |
| 1321 | func cleanDefaultExpression(defaultExpr, currentSchema string) string { |
| 1322 | if defaultExpr == "" { |
| 1323 | return defaultExpr |
| 1324 | } |
| 1325 | |
| 1326 | // Remove leading/trailing whitespace |
| 1327 | cleaned := strings.TrimSpace(defaultExpr) |
| 1328 | |
| 1329 | // Fix schema-qualified sequence NEXTVAL calls |
| 1330 | // Pattern: "SCHEMA"."SEQUENCE_NAME"."NEXTVAL" -> "SEQUENCE_NAME".NEXTVAL |
| 1331 | // Keep sequence name quoted for compatibility |
| 1332 | if strings.Contains(cleaned, ".\"NEXTVAL\"") { |
| 1333 | // Use regex to match quoted schema and sequence names followed by quoted NEXTVAL |
| 1334 | re := regexp.MustCompile(`"` + regexp.QuoteMeta(currentSchema) + `"\."([^"]+)"\."NEXTVAL"`) |
| 1335 | cleaned = re.ReplaceAllString(cleaned, `"$1".NEXTVAL`) |
| 1336 | } |
| 1337 | |
| 1338 | // Also handle unquoted NEXTVAL (less common) |
| 1339 | if strings.Contains(cleaned, ".NEXTVAL") { |
| 1340 | re := regexp.MustCompile(`"` + regexp.QuoteMeta(currentSchema) + `"\."([^"]+)"\.NEXTVAL`) |
| 1341 | cleaned = re.ReplaceAllString(cleaned, `"$1".NEXTVAL`) |
| 1342 | } |
| 1343 | |
| 1344 | return cleaned |
| 1345 | } |
| 1346 | |
| 1347 | // getViewComments gets comments for views from Oracle system views |
| 1348 | func getViewComments(txn *sql.Tx, schemaName string) (map[db.TableKey]string, error) { |