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

Function getFunctionComments

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

getFunctionComments gets comments for functions and procedures from Oracle system views

(txn *sql.Tx, schemaName string)

Source from the content-addressed store, hash-verified

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) {
1448 functionCommentMap := make(map[db.TableKey]string)
1449
1450 // Oracle stores function/procedure comments in ALL_OBJECTS or USER_OBJECTS
1451 // However, Oracle doesn't have a standard system view for function/procedure comments
1452 // We can try to get them from ALL_TAB_COMMENTS where TABLE_TYPE might be 'FUNCTION' or 'PROCEDURE'
1453 query := ""
1454 if schemaName == "" {
1455 query = fmt.Sprintf(`
1456 SELECT OWNER, TABLE_NAME, COMMENTS
1457 FROM all_tab_comments
1458 WHERE OWNER NOT IN (%s) AND OWNER NOT LIKE 'APEX_%%' AND COMMENTS IS NOT NULL
1459 AND TABLE_TYPE IN ('FUNCTION', 'PROCEDURE')
1460 ORDER BY OWNER, TABLE_NAME`, systemSchema)
1461 } else {
1462 query = fmt.Sprintf(`
1463 SELECT OWNER, TABLE_NAME, COMMENTS
1464 FROM all_tab_comments
1465 WHERE OWNER = '%s' AND COMMENTS IS NOT NULL
1466 AND TABLE_TYPE IN ('FUNCTION', 'PROCEDURE')
1467 ORDER BY TABLE_NAME`, schemaName)
1468 }
1469
1470 slog.Debug("running get function comments query")
1471 rows, err := txn.Query(query)
1472 if err != nil {
1473 // If the query fails (e.g., TABLE_TYPE for functions not supported), return empty map
1474 slog.Debug("function comments query failed, returning empty map", slog.String("error", err.Error()))
1475 return functionCommentMap, nil
1476 }
1477 defer rows.Close()
1478
1479 for rows.Next() {
1480 var schemaName, functionName, comment string
1481 if err := rows.Scan(&schemaName, &functionName, &comment); err != nil {
1482 return nil, err
1483 }
1484 key := db.TableKey{Schema: schemaName, Table: functionName}
1485 functionCommentMap[key] = common.SanitizeUTF8String(comment)
1486 }
1487 if err := rows.Err(); err != nil {
1488 return nil, util.FormatErrorWithQuery(err, query)
1489 }
1490 if err := rows.Close(); err != nil {
1491 return nil, errors.Wrapf(err, "failed to close rows")
1492 }
1493
1494 return functionCommentMap, nil
1495}
1496
1497// getIndexComments gets comments for indexes from Oracle system views
1498func getIndexComments(_ *sql.Tx, schemaName string) (map[db.IndexKey]string, error) {

Callers 1

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