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

Function getTableColumnComments

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

Source from the content-addressed store, hash-verified

399}
400
401func getTableColumnComments(txn *sql.Tx, schemaName string) (map[db.ColumnKey]string, error) {
402 columnCommentsMap := make(map[db.ColumnKey]string)
403
404 query := ""
405 if schemaName == "" {
406 query = fmt.Sprintf(`
407 SELECT OWNER, TABLE_NAME, COLUMN_NAME, COMMENTS
408 FROM all_col_comments
409 WHERE OWNER NOT IN (%s) AND OWNER NOT LIKE 'APEX_%%' AND COMMENTS IS NOT NULL
410 ORDER BY OWNER, TABLE_NAME, COLUMN_NAME`, systemSchema)
411 } else {
412 query = fmt.Sprintf(`
413 SELECT OWNER, TABLE_NAME, COLUMN_NAME, COMMENTS
414 FROM all_col_comments
415 WHERE OWNER = '%s' AND COMMENTS IS NOT NULL
416 ORDER BY TABLE_NAME, COLUMN_NAME`, schemaName)
417 }
418 slog.Debug("running get table column comments query")
419 rows, err := txn.Query(query)
420 if err != nil {
421 return nil, util.FormatErrorWithQuery(err, query)
422 }
423 defer rows.Close()
424 for rows.Next() {
425 var schemaName, tableName, columnName, comment string
426 if err := rows.Scan(&schemaName, &tableName, &columnName, &comment); err != nil {
427 return nil, err
428 }
429 key := db.ColumnKey{Schema: schemaName, Table: tableName, Column: columnName}
430 columnCommentsMap[key] = common.SanitizeUTF8String(comment)
431 }
432 if err := rows.Err(); err != nil {
433 return nil, util.FormatErrorWithQuery(err, query)
434 }
435 if err := rows.Close(); err != nil {
436 return nil, errors.Wrapf(err, "failed to close rows")
437 }
438
439 return columnCommentsMap, nil
440}
441
442// getTableColumns gets the columns of a table.
443func getTableColumns(txn *sql.Tx, schemaName string, version *plsql.Version) (map[db.TableKey][]*storepb.ColumnMetadata, error) {

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