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

Function getTriggerComments

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

getTriggerComments gets comments for triggers from Oracle system views

(txn *sql.Tx, schemaName string)

Source from the content-addressed store, hash-verified

1554
1555// getTriggerComments gets comments for triggers from Oracle system views
1556func getTriggerComments(txn *sql.Tx, schemaName string) (map[db.TableKey]string, error) {
1557 triggerCommentMap := make(map[db.TableKey]string)
1558
1559 // Oracle doesn't have a standard trigger comments view
1560 // Trigger comments might be stored in ALL_TAB_COMMENTS with TABLE_TYPE = 'TRIGGER'
1561 // or in some Oracle versions, they might not be available at all
1562 query := ""
1563 if schemaName == "" {
1564 query = fmt.Sprintf(`
1565 SELECT OWNER, TABLE_NAME, COMMENTS
1566 FROM all_tab_comments
1567 WHERE OWNER NOT IN (%s) AND OWNER NOT LIKE 'APEX_%%' AND COMMENTS IS NOT NULL
1568 AND TABLE_TYPE = 'TRIGGER'
1569 ORDER BY OWNER, TABLE_NAME`, systemSchema)
1570 } else {
1571 query = fmt.Sprintf(`
1572 SELECT OWNER, TABLE_NAME, COMMENTS
1573 FROM all_tab_comments
1574 WHERE OWNER = '%s' AND COMMENTS IS NOT NULL
1575 AND TABLE_TYPE = 'TRIGGER'
1576 ORDER BY TABLE_NAME`, schemaName)
1577 }
1578
1579 slog.Debug("running get trigger comments query")
1580 rows, err := txn.Query(query)
1581 if err != nil {
1582 // If the query fails (e.g., TABLE_TYPE = 'TRIGGER' not supported), return empty map
1583 slog.Debug("trigger comments query failed, returning empty map", slog.String("error", err.Error()))
1584 return triggerCommentMap, nil
1585 }
1586 defer rows.Close()
1587
1588 for rows.Next() {
1589 var schemaName, triggerName, comment string
1590 if err := rows.Scan(&schemaName, &triggerName, &comment); err != nil {
1591 return nil, err
1592 }
1593 key := db.TableKey{Schema: schemaName, Table: triggerName}
1594 triggerCommentMap[key] = common.SanitizeUTF8String(comment)
1595 }
1596 if err := rows.Err(); err != nil {
1597 return nil, util.FormatErrorWithQuery(err, query)
1598 }
1599 if err := rows.Close(); err != nil {
1600 return nil, errors.Wrapf(err, "failed to close rows")
1601 }
1602
1603 return triggerCommentMap, nil
1604}

Callers 1

getTriggersFunction · 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