* command_db_stats is the implementation of the internal logic for * dbcommand/dbStats. */
| 79 | * dbcommand/dbStats. |
| 80 | */ |
| 81 | Datum |
| 82 | command_db_stats(PG_FUNCTION_ARGS) |
| 83 | { |
| 84 | if (PG_ARGISNULL(0)) |
| 85 | { |
| 86 | ereport(ERROR, (errmsg("Database name must not be NULL"))); |
| 87 | } |
| 88 | Datum databaseName = PG_GETARG_DATUM(0); |
| 89 | |
| 90 | if (PG_ARGISNULL(1)) |
| 91 | { |
| 92 | /* Scale is optional in the dbStats command but here |
| 93 | * the sql method must provide scale to this C func */ |
| 94 | ereport(ERROR, (errmsg("scale cannot be NULL"))); |
| 95 | } |
| 96 | double scaleDouble = PG_GETARG_FLOAT8(1); |
| 97 | |
| 98 | if (PG_ARGISNULL(2)) |
| 99 | { |
| 100 | /* freeStorage is optional in the dbStats command but here |
| 101 | * the sql method must provide freeStorage to this C func */ |
| 102 | ereport(ERROR, (errmsg("freeStorage cannot be NULL"))); |
| 103 | } |
| 104 | |
| 105 | /* We don't yet support freeStrorage statistics, so skip reading freeStorage value */ |
| 106 | |
| 107 | ReportFeatureUsage(FEATURE_COMMAND_DBSTATS); |
| 108 | |
| 109 | /* Truncate the fractional part of the scale */ |
| 110 | scaleDouble = trunc(scaleDouble); |
| 111 | |
| 112 | /* The 'scale' value is capped to int32 for compatibility with expected behavior */ |
| 113 | int32 scale = scaleDouble > INT32_MAX ? INT32_MAX : |
| 114 | scaleDouble < INT32_MIN ? INT32_MIN : |
| 115 | (int32) scaleDouble; |
| 116 | |
| 117 | pgbson *response = DbStatsCoordinator(databaseName, scale); |
| 118 | PG_RETURN_POINTER(response); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /* |
nothing calls this directly
no test coverage detected