getSequenceComments gets comments for sequences from Oracle system views
(txn *sql.Tx, schemaName string)
| 1395 | |
| 1396 | // getSequenceComments gets comments for sequences from Oracle system views |
| 1397 | func getSequenceComments(txn *sql.Tx, schemaName string) (map[db.TableKey]string, error) { |
| 1398 | sequenceCommentMap := make(map[db.TableKey]string) |
| 1399 | |
| 1400 | // Oracle doesn't have a direct sequence comments view, but we can try user_tab_comments |
| 1401 | // where TABLE_TYPE might be 'SEQUENCE' in some Oracle versions |
| 1402 | query := "" |
| 1403 | if schemaName == "" { |
| 1404 | query = fmt.Sprintf(` |
| 1405 | SELECT OWNER, TABLE_NAME, COMMENTS |
| 1406 | FROM all_tab_comments |
| 1407 | WHERE OWNER NOT IN (%s) AND OWNER NOT LIKE 'APEX_%%' AND COMMENTS IS NOT NULL |
| 1408 | AND TABLE_TYPE = 'SEQUENCE' |
| 1409 | ORDER BY OWNER, TABLE_NAME`, systemSchema) |
| 1410 | } else { |
| 1411 | query = fmt.Sprintf(` |
| 1412 | SELECT OWNER, TABLE_NAME, COMMENTS |
| 1413 | FROM all_tab_comments |
| 1414 | WHERE OWNER = '%s' AND COMMENTS IS NOT NULL |
| 1415 | AND TABLE_TYPE = 'SEQUENCE' |
| 1416 | ORDER BY TABLE_NAME`, schemaName) |
| 1417 | } |
| 1418 | |
| 1419 | slog.Debug("running get sequence comments query") |
| 1420 | rows, err := txn.Query(query) |
| 1421 | if err != nil { |
| 1422 | // If the query fails (e.g., TABLE_TYPE = 'SEQUENCE' not supported), return empty map |
| 1423 | slog.Debug("sequence comments query failed, returning empty map", slog.String("error", err.Error())) |
| 1424 | return sequenceCommentMap, nil |
| 1425 | } |
| 1426 | defer rows.Close() |
| 1427 | |
| 1428 | for rows.Next() { |
| 1429 | var schemaName, sequenceName, comment string |
| 1430 | if err := rows.Scan(&schemaName, &sequenceName, &comment); err != nil { |
| 1431 | return nil, err |
| 1432 | } |
| 1433 | key := db.TableKey{Schema: schemaName, Table: sequenceName} |
| 1434 | sequenceCommentMap[key] = common.SanitizeUTF8String(comment) |
| 1435 | } |
| 1436 | if err := rows.Err(); err != nil { |
| 1437 | return nil, util.FormatErrorWithQuery(err, query) |
| 1438 | } |
| 1439 | if err := rows.Close(); err != nil { |
| 1440 | return nil, errors.Wrapf(err, "failed to close rows") |
| 1441 | } |
| 1442 | |
| 1443 | return sequenceCommentMap, nil |
| 1444 | } |
| 1445 | |
| 1446 | // getFunctionComments gets comments for functions and procedures from Oracle system views |
| 1447 | func getFunctionComments(txn *sql.Tx, schemaName string) (map[db.TableKey]string, error) { |
no test coverage detected