getFunctionComments gets comments for functions and procedures from Oracle system views
(txn *sql.Tx, schemaName string)
| 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) { |
| 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 |
| 1498 | func getIndexComments(_ *sql.Tx, schemaName string) (map[db.IndexKey]string, error) { |
no test coverage detected