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

Function getTableComments

backend/plugin/db/oracle/sync.go:359–399  ·  view source on GitHub ↗
(txn *sql.Tx, schemaName string)

Source from the content-addressed store, hash-verified

357}
358
359func getTableComments(txn *sql.Tx, schemaName string) (map[db.TableKey]string, error) {
360 tableCommentMap := make(map[db.TableKey]string)
361
362 query := ""
363 if schemaName == "" {
364 query = fmt.Sprintf(`
365 SELECT OWNER, TABLE_NAME, COMMENTS
366 FROM all_tab_comments
367 WHERE OWNER NOT IN (%s) AND OWNER NOT LIKE 'APEX_%%' AND COMMENTS IS NOT NULL
368 ORDER BY OWNER, TABLE_NAME`, systemSchema)
369 } else {
370 query = fmt.Sprintf(`
371 SELECT OWNER, TABLE_NAME, COMMENTS
372 FROM all_tab_comments
373 WHERE OWNER = '%s' AND COMMENTS IS NOT NULL
374 ORDER BY TABLE_NAME`, schemaName)
375 }
376 slog.Debug("running get table comments query")
377 rows, err := txn.Query(query)
378 if err != nil {
379 return nil, util.FormatErrorWithQuery(err, query)
380 }
381 defer rows.Close()
382
383 for rows.Next() {
384 var schemaName, tableName, comment string
385 if err := rows.Scan(&schemaName, &tableName, &comment); err != nil {
386 return nil, err
387 }
388 key := db.TableKey{Schema: schemaName, Table: tableName}
389 tableCommentMap[key] = common.SanitizeUTF8String(comment)
390 }
391 if err := rows.Err(); err != nil {
392 return nil, util.FormatErrorWithQuery(err, query)
393 }
394 if err := rows.Close(); err != nil {
395 return nil, errors.Wrapf(err, "failed to close rows")
396 }
397
398 return tableCommentMap, nil
399}
400
401func getTableColumnComments(txn *sql.Tx, schemaName string) (map[db.ColumnKey]string, error) {
402 columnCommentsMap := make(map[db.ColumnKey]string)

Callers 1

getTablesFunction · 0.85

Calls 7

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

Tested by

no test coverage detected