MCPcopy Index your code
hub / github.com/bytebase/bytebase / getSequenceComments

Function getSequenceComments

backend/plugin/db/oracle/sync.go:1397–1444  ·  view source on GitHub ↗

getSequenceComments gets comments for sequences from Oracle system views

(txn *sql.Tx, schemaName string)

Source from the content-addressed store, hash-verified

1395
1396// getSequenceComments gets comments for sequences from Oracle system views
1397func 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
1447func getFunctionComments(txn *sql.Tx, schemaName string) (map[db.TableKey]string, error) {

Callers 1

getSequencesFunction · 0.85

Calls 9

SanitizeUTF8StringFunction · 0.92
FormatErrorWithQueryFunction · 0.92
DebugMethod · 0.80
ScanMethod · 0.80
QueryMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected