getViewComments gets comments for views from Oracle system views
(txn *sql.Tx, schemaName string)
| 1346 | |
| 1347 | // getViewComments gets comments for views from Oracle system views |
| 1348 | func getViewComments(txn *sql.Tx, schemaName string) (map[db.TableKey]string, error) { |
| 1349 | viewCommentMap := make(map[db.TableKey]string) |
| 1350 | |
| 1351 | // Oracle stores view comments in ALL_TAB_COMMENTS where TABLE_TYPE = 'VIEW' |
| 1352 | query := "" |
| 1353 | if schemaName == "" { |
| 1354 | query = fmt.Sprintf(` |
| 1355 | SELECT OWNER, TABLE_NAME, COMMENTS |
| 1356 | FROM all_tab_comments |
| 1357 | WHERE OWNER NOT IN (%s) AND OWNER NOT LIKE 'APEX_%%' AND COMMENTS IS NOT NULL |
| 1358 | AND TABLE_TYPE = 'VIEW' |
| 1359 | ORDER BY OWNER, TABLE_NAME`, systemSchema) |
| 1360 | } else { |
| 1361 | query = fmt.Sprintf(` |
| 1362 | SELECT OWNER, TABLE_NAME, COMMENTS |
| 1363 | FROM all_tab_comments |
| 1364 | WHERE OWNER = '%s' AND COMMENTS IS NOT NULL |
| 1365 | AND TABLE_TYPE = 'VIEW' |
| 1366 | ORDER BY TABLE_NAME`, schemaName) |
| 1367 | } |
| 1368 | |
| 1369 | slog.Debug("running get view comments query") |
| 1370 | rows, err := txn.Query(query) |
| 1371 | if err != nil { |
| 1372 | // If the query fails (e.g., TABLE_TYPE = 'VIEW' not supported), return empty map |
| 1373 | slog.Debug("view comments query failed, returning empty map", slog.String("error", err.Error())) |
| 1374 | return viewCommentMap, nil |
| 1375 | } |
| 1376 | defer rows.Close() |
| 1377 | |
| 1378 | for rows.Next() { |
| 1379 | var schemaName, viewName, comment string |
| 1380 | if err := rows.Scan(&schemaName, &viewName, &comment); err != nil { |
| 1381 | return nil, err |
| 1382 | } |
| 1383 | key := db.TableKey{Schema: schemaName, Table: viewName} |
| 1384 | viewCommentMap[key] = common.SanitizeUTF8String(comment) |
| 1385 | } |
| 1386 | if err := rows.Err(); err != nil { |
| 1387 | return nil, util.FormatErrorWithQuery(err, query) |
| 1388 | } |
| 1389 | if err := rows.Close(); err != nil { |
| 1390 | return nil, errors.Wrapf(err, "failed to close rows") |
| 1391 | } |
| 1392 | |
| 1393 | return viewCommentMap, nil |
| 1394 | } |
| 1395 | |
| 1396 | // getSequenceComments gets comments for sequences from Oracle system views |
| 1397 | func getSequenceComments(txn *sql.Tx, schemaName string) (map[db.TableKey]string, error) { |
no test coverage detected