Skip to content

Commit 3098181

Browse files
committed
Modeled the sys.configurations catalog view.
1 parent f4f9c14 commit 3098181

3 files changed

Lines changed: 256 additions & 0 deletions

File tree

SqlServerSimulator.Tests/CatalogViewTests.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,83 @@ public void DmOsHostInfo_HostSkuNullOffWindows()
358358
else
359359
IsTrue(reader.IsDBNull(0));
360360
}
361+
362+
[TestMethod]
363+
public void SysConfigurations_AgentXps_ValueInUseIsBigintZero()
364+
{
365+
// The exact query SSMS's SMO issues during its Object-Explorer
366+
// database-node preamble. Msg 208 here aborts the request before the
367+
// database enumeration, so the row must resolve and surface bigint.
368+
using var reader = new Simulation().ExecuteReader(
369+
"select value_in_use from sys.configurations where configuration_id = 16384");
370+
IsTrue(reader.Read());
371+
AreEqual(typeof(long), reader.GetFieldType(0));
372+
AreEqual(0L, reader.GetInt64(0));
373+
IsFalse(reader.Read());
374+
}
375+
376+
[TestMethod]
377+
public void SysConfigurations_HasHundredSixRows()
378+
=> AreEqual(106, new Simulation().ExecuteScalar("select count(*) from sys.configurations"));
379+
380+
[TestMethod]
381+
public void SysConfigurations_ColumnShape()
382+
{
383+
using var reader = new Simulation().ExecuteReader("""
384+
select configuration_id, name, value, minimum, maximum,
385+
value_in_use, description, is_dynamic, is_advanced
386+
from sys.configurations where configuration_id = 16384
387+
""");
388+
AreEqual(9, reader.FieldCount);
389+
IsTrue(reader.Read());
390+
AreEqual(typeof(int), reader.GetFieldType(0));
391+
AreEqual(typeof(string), reader.GetFieldType(1));
392+
AreEqual(typeof(long), reader.GetFieldType(2));
393+
AreEqual(typeof(long), reader.GetFieldType(3));
394+
AreEqual(typeof(long), reader.GetFieldType(4));
395+
AreEqual(typeof(long), reader.GetFieldType(5));
396+
AreEqual(typeof(string), reader.GetFieldType(6));
397+
AreEqual(typeof(bool), reader.GetFieldType(7));
398+
AreEqual(typeof(bool), reader.GetFieldType(8));
399+
}
400+
401+
[TestMethod]
402+
public void SysConfigurations_AgentXpsRow_MatchesReference()
403+
{
404+
using var reader = new Simulation().ExecuteReader("""
405+
select configuration_id, name, value, minimum, maximum,
406+
value_in_use, description, is_dynamic, is_advanced
407+
from sys.configurations where configuration_id = 16384
408+
""");
409+
IsTrue(reader.Read());
410+
AreEqual(16384, reader.GetInt32(0));
411+
AreEqual("Agent XPs", reader.GetString(1));
412+
AreEqual(0L, reader.GetInt64(2));
413+
AreEqual(0L, reader.GetInt64(3));
414+
AreEqual(1L, reader.GetInt64(4));
415+
AreEqual(0L, reader.GetInt64(5));
416+
AreEqual("Enable or disable Agent XPs", reader.GetString(6));
417+
IsTrue(reader.GetBoolean(7));
418+
IsTrue(reader.GetBoolean(8));
419+
}
420+
421+
[TestMethod]
422+
public void SysConfigurations_ClrEnabled_ByName()
423+
=> AreEqual(1562, new Simulation().ExecuteScalar(
424+
"select configuration_id from sys.configurations where name = 'clr enabled'"));
425+
426+
[TestMethod]
427+
public void SysConfigurations_XpCmdshell_ByName()
428+
=> AreEqual(16390, new Simulation().ExecuteScalar(
429+
"select configuration_id from sys.configurations where name = 'xp_cmdshell'"));
430+
431+
[TestMethod]
432+
public void SysConfigurations_AgentXps_CountByNameIsOne()
433+
=> AreEqual(1, new Simulation().ExecuteScalar(
434+
"select count(*) from sys.configurations where name = 'Agent XPs'"));
435+
436+
[TestMethod]
437+
public void SysConfigurations_ReadableViaThreePartMasterName()
438+
=> AreEqual(106, new Simulation().ExecuteScalar(
439+
"select count(*) from master.sys.configurations"));
361440
}

SqlServerSimulator/BuiltInResources.cs

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,33 @@ void Iso(string name, HeapColumn[] columns, Func<Parser.BatchContext, Database,
11621162
new("host_architecture", SqlType.NVarchar, 256, false),
11631163
], (batch, database) => DmOsHostInfoRows);
11641164

1165+
// sys.configurations: server-scoped static server-configuration
1166+
// catalog. Real SQL Server types value / minimum / maximum /
1167+
// value_in_use as sql_variant; the simulator surfaces them as bigint
1168+
// (config values like 'max server memory (MB)' exceed int range),
1169+
// following the same sql_variant-to-concrete-base substitution
1170+
// sys.sequences uses for its sql_variant-typed value columns. The 106
1171+
// rows are a stock instance's defaults (probe-confirmed against SQL
1172+
// Server 2025) — configuration_id and name are stable across
1173+
// instances, and value mirrors value_in_use on a fresh server. This is
1174+
// static catalog data, not a live settings model: SET / sp_configure
1175+
// changes are not reflected. SMO reads value_in_use for
1176+
// configuration_id 16384 (Agent XPs) during SSMS's Object-Explorer
1177+
// database-node preamble, so the row set must resolve for that folder
1178+
// to populate. Row set is independent of the database argument.
1179+
Sys("configurations",
1180+
[
1181+
new("configuration_id", SqlType.Int32, null, false),
1182+
new("name", SqlType.NVarchar, 35, false),
1183+
new("value", SqlType.BigInt, null, true),
1184+
new("minimum", SqlType.BigInt, null, true),
1185+
new("maximum", SqlType.BigInt, null, true),
1186+
new("value_in_use", SqlType.BigInt, null, true),
1187+
new("description", SqlType.NVarchar, 255, false),
1188+
new("is_dynamic", SqlType.Bit, null, false),
1189+
new("is_advanced", SqlType.Bit, null, false),
1190+
], (batch, database) => ConfigurationsRows);
1191+
11651192
return views;
11661193
}
11671194

@@ -1247,6 +1274,155 @@ private static Dictionary<string, string> ReadOsRelease()
12471274
return result;
12481275
}
12491276

1277+
/// <summary>
1278+
/// Raw stock-instance rows for <c>sys.configurations</c> (probe-confirmed
1279+
/// against SQL Server 2025). <c>configuration_id</c> and <c>name</c> are
1280+
/// stable across instances; <c>value</c> mirrors <c>value_in_use</c> on a
1281+
/// fresh server. The four sql_variant columns hold integers for every
1282+
/// option, surfaced as bigint.
1283+
/// </summary>
1284+
private static readonly (int Id, string Name, long Value, long Minimum, long Maximum, long ValueInUse, string Description, bool IsDynamic, bool IsAdvanced)[] ConfigurationData =
1285+
[
1286+
(101, "recovery interval (min)", 0, 0, 32767, 0, "Maximum recovery interval in minutes", true, true),
1287+
(102, "allow updates", 0, 0, 1, 0, "Allow updates to system tables", true, false),
1288+
(103, "user connections", 0, 0, 32767, 0, "Number of user connections allowed", false, true),
1289+
(106, "locks", 0, 5000, 2147483647, 0, "Number of locks for all users", false, true),
1290+
(107, "open objects", 0, 0, 2147483647, 0, "Number of open database objects", false, true),
1291+
(109, "fill factor (%)", 0, 0, 100, 0, "Default fill factor percentage", false, true),
1292+
(114, "disallow results from triggers", 0, 0, 1, 0, "Disallow returning results from triggers", true, true),
1293+
(115, "nested triggers", 1, 0, 1, 1, "Allow triggers to be invoked within triggers", true, false),
1294+
(116, "server trigger recursion", 1, 0, 1, 1, "Allow recursion for server level triggers", true, false),
1295+
(117, "remote access", 1, 0, 1, 1, "Allow remote access", false, false),
1296+
(124, "default language", 0, 0, 9999, 0, "default language", true, false),
1297+
(400, "cross db ownership chaining", 0, 0, 1, 0, "Allow cross db ownership chaining", true, false),
1298+
(503, "max worker threads", 0, 128, 65535, 0, "Maximum worker threads", true, true),
1299+
(505, "network packet size (B)", 4096, 512, 32767, 4096, "Network packet size", true, true),
1300+
(518, "show advanced options", 0, 0, 1, 0, "show advanced options", true, false),
1301+
(542, "remote proc trans", 0, 0, 1, 0, "Create DTC transaction for remote procedures", true, false),
1302+
(544, "c2 audit mode", 0, 0, 1, 0, "c2 audit mode", false, true),
1303+
(1126, "default full-text language", 1033, 0, 2147483647, 1033, "default full-text language", true, true),
1304+
(1127, "two digit year cutoff", 2049, 1753, 9999, 2049, "two digit year cutoff", true, true),
1305+
(1505, "index create memory (KB)", 0, 704, 2147483647, 0, "Memory for index create sorts (kBytes)", true, true),
1306+
(1517, "priority boost", 0, 0, 1, 0, "Priority boost", false, true),
1307+
(1519, "remote login timeout (s)", 10, 0, 2147483647, 10, "remote login timeout", true, false),
1308+
(1520, "remote query timeout (s)", 600, 0, 2147483647, 600, "remote query timeout", true, false),
1309+
(1531, "cursor threshold", -1, -1, 2147483647, -1, "cursor threshold", true, true),
1310+
(1532, "set working set size", 0, 0, 1, 0, "set working set size", false, true),
1311+
(1534, "user options", 0, 0, 32767, 0, "user options", true, false),
1312+
(1535, "affinity mask", 0, -2147483648, 2147483647, 0, "affinity mask", true, true),
1313+
(1536, "max text repl size (B)", 65536, -1, 2147483647, 65536, "Maximum size of a text field in replication.", true, false),
1314+
(1537, "media retention", 0, 0, 365, 0, "Tape retention period in days", true, true),
1315+
(1538, "cost threshold for parallelism", 5, 0, 32767, 5, "cost threshold for parallelism", true, true),
1316+
(1539, "max degree of parallelism", 8, 0, 32767, 8, "maximum degree of parallelism", true, true),
1317+
(1540, "min memory per query (KB)", 1024, 512, 2147483647, 1024, "minimum memory per query (kBytes)", true, true),
1318+
(1541, "query wait (s)", -1, -1, 2147483647, -1, "maximum time to wait for query memory (s)", true, true),
1319+
(1543, "min server memory (MB)", 0, 0, 2147483647, 16, "Minimum size of server memory (MB)", true, true),
1320+
(1544, "max server memory (MB)", 4096, 128, 2147483647, 4096, "Maximum size of server memory (MB)", true, true),
1321+
(1545, "query governor cost limit", 0, 0, 2147483647, 0, "Maximum estimated cost allowed by query governor", true, true),
1322+
(1546, "lightweight pooling", 0, 0, 1, 0, "User mode scheduler uses lightweight pooling", false, true),
1323+
(1547, "scan for startup procs", 0, 0, 1, 0, "scan for startup stored procedures", false, true),
1324+
(1549, "affinity64 mask", 0, -2147483648, 2147483647, 0, "affinity64 mask", true, true),
1325+
(1550, "affinity I/O mask", 0, -2147483648, 2147483647, 0, "affinity I/O mask", false, true),
1326+
(1551, "affinity64 I/O mask", 0, -2147483648, 2147483647, 0, "affinity64 I/O mask", false, true),
1327+
(1555, "transform noise words", 0, 0, 1, 0, "Transform noise words for full-text query", true, true),
1328+
(1556, "precompute rank", 0, 0, 1, 0, "Use precomputed rank for full-text query", true, true),
1329+
(1557, "PH timeout (s)", 60, 1, 3600, 60, "DB connection timeout for full-text protocol handler (s)", true, true),
1330+
(1562, "clr enabled", 0, 0, 1, 0, "CLR user code execution enabled in the server", true, false),
1331+
(1563, "max full-text crawl range", 4, 0, 256, 4, "Maximum crawl ranges allowed in full-text indexing", true, true),
1332+
(1564, "ft notify bandwidth (min)", 0, 0, 32767, 0, "Number of reserved full-text notifications buffers", true, true),
1333+
(1565, "ft notify bandwidth (max)", 100, 0, 32767, 100, "Max number of full-text notifications buffers", true, true),
1334+
(1566, "ft crawl bandwidth (min)", 0, 0, 32767, 0, "Number of reserved full-text crawl buffers", true, true),
1335+
(1567, "ft crawl bandwidth (max)", 100, 0, 32767, 100, "Max number of full-text crawl buffers", true, true),
1336+
(1568, "default trace enabled", 1, 0, 1, 1, "Enable or disable the default trace", true, true),
1337+
(1569, "blocked process threshold (s)", 0, 0, 86400, 0, "Blocked process reporting threshold", true, true),
1338+
(1570, "in-doubt xact resolution", 0, 0, 2, 0, "Recovery policy for DTC transactions with unknown outcome", true, true),
1339+
(1576, "remote admin connections", 0, 0, 1, 0, "Dedicated Admin Connections are allowed from remote clients", true, false),
1340+
(1577, "common criteria compliance enabled", 0, 0, 1, 0, "Common Criteria compliance mode enabled", false, true),
1341+
(1578, "EKM provider enabled", 0, 0, 1, 0, "Enable or disable EKM provider", true, true),
1342+
(1579, "backup compression default", 0, 0, 1, 0, "Enable compression of backups by default", true, false),
1343+
(1580, "filestream access level", 0, 0, 2, 0, "Sets the FILESTREAM access level", true, false),
1344+
(1581, "optimize for ad hoc workloads", 0, 0, 1, 0, "When this option is set, plan cache size is further reduced for single-use adhoc OLTP workload.", true, true),
1345+
(1582, "access check cache bucket count", 0, 0, 65536, 0, "Default hash bucket count for the access check result security cache", true, true),
1346+
(1583, "access check cache quota", 0, 0, 2147483647, 0, "Default quota for the access check result security cache", true, true),
1347+
(1584, "backup checksum default", 0, 0, 1, 0, "Enable checksum of backups by default", true, false),
1348+
(1585, "automatic soft-NUMA disabled", 0, 0, 1, 0, "Automatic soft-NUMA is enabled by default", false, true),
1349+
(1586, "external scripts enabled", 0, 0, 1, 0, "Allows execution of external scripts", true, false),
1350+
(1587, "clr strict security", 1, 0, 1, 1, "CLR strict security enabled in the server", true, true),
1351+
(1588, "column encryption enclave type", 0, 0, 2, 0, "Type of enclave used for computations on encrypted columns", false, false),
1352+
(1589, "tempdb metadata memory-optimized", 0, 0, 1, 0, "Tempdb metadata memory-optimized is disabled by default.", false, true),
1353+
(1591, "ADR cleaner retry timeout (min)", 15, 0, 32767, 15, "ADR cleaner retry timeout.", true, true),
1354+
(1592, "ADR Preallocation Factor", 4, 0, 32767, 4, "ADR Preallocation Factor.", true, true),
1355+
(1593, "version high part of SQL Server", 1114112, -2147483648, 2147483647, 1114112, "version high part of SQL Server that model database copied for", true, true),
1356+
(1594, "version low part of SQL Server", 73072641, -2147483648, 2147483647, 73072641, "version low part of SQL Server that model database copied for", true, true),
1357+
(1595, "Data processed daily limit in TB", 2147483647, 0, 2147483647, 2147483647, "SQL On-demand data processed daily limit in TB", true, false),
1358+
(1596, "Data processed weekly limit in TB", 2147483647, 0, 2147483647, 2147483647, "SQL On-demand data processed weekly limit in TB", true, false),
1359+
(1597, "Data processed monthly limit in TB", 2147483647, 0, 2147483647, 2147483647, "SQL On-demand data processed monthly limit in TB", true, false),
1360+
(1598, "ADR Cleaner Thread Count", 1, 1, 32767, 1, "Max number of threads ADR cleaner can assign.", true, true),
1361+
(1599, "hardware offload enabled", 0, 0, 1, 0, "Enable hardware offloading on the server", false, true),
1362+
(1600, "hardware offload config", 0, 0, 255, 0, "Configure hardware offload accelerator", false, true),
1363+
(1601, "hardware offload mode", 0, 0, 255, 0, "Configure hardware offload accelerator mode", false, true),
1364+
(1602, "backup compression algorithm", 0, 0, 3, 0, "Configure default backup compression algorithm", true, false),
1365+
(1603, "ADR cleaner lock timeout (s)", 5, 1, 32767, 5, "ADR cleaner lock timeout", true, true),
1366+
(1606, "SLOG memory quota (%)", 75, 1, 100, 75, "SLOG memory quota percentage", true, true),
1367+
(1609, "max RPC request params (KB)", 0, 0, 2147483647, 0, "Maximum memory for RPC request parameters (kBytes)", true, true),
1368+
(1610, "max UCS send boxcars", 256, 256, 2048, 256, "Maximum number of UCS boxcars for sending messages.", false, true),
1369+
(1611, "availability group commit time (ms)", 0, 0, 10, 0, "Configure availability group commit time in milliseconds for SQL Server only.", true, true),
1370+
(1612, "tiered memory enabled", 0, 0, 1, 0, "tiered memory memory-optimized is disabled by default.", false, true),
1371+
(1613, "max server tiered memory (MB)", 2147483647, 0, 2147483647, 2147483647, "Maximum size of server tiered memory (MB)", false, true),
1372+
(16384, "Agent XPs", 0, 0, 1, 0, "Enable or disable Agent XPs", true, true),
1373+
(16386, "Database Mail XPs", 0, 0, 1, 0, "Enable or disable Database Mail XPs", true, true),
1374+
(16387, "SMO and DMO XPs", 1, 0, 1, 1, "Enable or disable SMO and DMO XPs", true, true),
1375+
(16388, "Ole Automation Procedures", 0, 0, 1, 0, "Enable or disable Ole Automation Procedures", true, true),
1376+
(16390, "xp_cmdshell", 0, 0, 1, 0, "Enable or disable command shell", true, true),
1377+
(16391, "Ad Hoc Distributed Queries", 0, 0, 1, 0, "Enable or disable Ad Hoc Distributed Queries", true, true),
1378+
(16392, "Replication XPs", 0, 0, 1, 0, "Enable or disable Replication XPs", true, true),
1379+
(16393, "contained database authentication", 0, 0, 1, 0, "Enables contained databases and contained authentication", true, false),
1380+
(16394, "hadoop connectivity", 0, 0, 8, 0, "Configure SQL Server to connect to external Hadoop or Microsoft Azure storage blob data sources through PolyBase", true, false),
1381+
(16395, "polybase network encryption", 1, 0, 1, 1, "Configure SQL Server to encrypt control and data channels when using PolyBase", true, false),
1382+
(16396, "remote data archive", 0, 0, 1, 0, "Allow the use of the REMOTE_DATA_ARCHIVE data access for databases", true, false),
1383+
(16397, "allow polybase export", 0, 0, 1, 0, "Allows writing into an external table using PolyBase", true, false),
1384+
(16398, "allow filesystem enumeration", 1, 0, 1, 1, "Allow enumeration of filesystem", true, true),
1385+
(16399, "polybase enabled", 0, 0, 1, 0, "Configure SQL Server to connect to external data sources through PolyBase", true, false),
1386+
(16400, "suppress recovery model errors", 0, 0, 1, 0, "Return warning instead of error for unsupported ALTER DATABASE SET RECOVERY command", true, true),
1387+
(16401, "openrowset auto_create_statistics", 1, 0, 1, 1, "Enable or disable auto create statistics for openrowset sources.", true, true),
1388+
(16402, "external rest endpoint enabled", 0, 0, 1, 0, "Enable or disable invocations of external REST endpoints", true, false),
1389+
(16403, "external xtp dll gen util enabled", 0, 0, 1, 0, "Enable or disable using external xtp dll generation via HkDllGen.exe", true, false),
1390+
(16404, "external AI runtimes enabled", 0, 0, 1, 0, "Enable or disable using external AI runtimes", true, false),
1391+
(16405, "allow server scoped db credentials", 0, 0, 1, 0, "Enable or disable use of server managed identity in database scoped credentials", true, false),
1392+
];
1393+
1394+
/// <summary>
1395+
/// The 106 rows projected by <c>sys.configurations</c>, materialized once
1396+
/// from <see cref="ConfigurationData"/> since server-configuration
1397+
/// metadata is fixed static catalog data (matching how the other
1398+
/// constant-row catalog views reuse a shared array). Independent of the
1399+
/// database argument — <c>sys.configurations</c> is server-scoped.
1400+
/// </summary>
1401+
private static readonly SqlValue[][] ConfigurationsRows = BuildConfigurationsRows();
1402+
1403+
private static SqlValue[][] BuildConfigurationsRows()
1404+
{
1405+
var rows = new SqlValue[ConfigurationData.Length][];
1406+
for (var i = 0; i < ConfigurationData.Length; i++)
1407+
{
1408+
var (id, name, value, minimum, maximum, valueInUse, description, isDynamic, isAdvanced) = ConfigurationData[i];
1409+
rows[i] =
1410+
[
1411+
SqlValue.FromInt32(id),
1412+
SqlValue.FromNVarchar(name),
1413+
SqlValue.FromInt64(value),
1414+
SqlValue.FromInt64(minimum),
1415+
SqlValue.FromInt64(maximum),
1416+
SqlValue.FromInt64(valueInUse),
1417+
SqlValue.FromNVarchar(description),
1418+
SqlValue.FromBoolean(isDynamic),
1419+
SqlValue.FromBoolean(isAdvanced),
1420+
];
1421+
}
1422+
1423+
return rows;
1424+
}
1425+
12501426
/// <summary>
12511427
/// Rows for <c>sys.types</c>: every <see cref="SystypesRowData"/> entry
12521428
/// (system types) followed by user-defined table types from each schema's

0 commit comments

Comments
 (0)