{"record":{"id":"e4d1d5fdb6609d9e","repo":"tursodatabase/turso","slug":"too-many-restrictions-specified-for-collection-co","errorCode":null,"errorMessage":"Too many restrictions specified for collection {collectionName}.","messagePattern":"Too many restrictions specified for collection (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs","lineNumber":921,"sourceCode":"        }\n    }\n\n    private void CleanupFailedOpen(string? sharedMemoryPath)\n    {\n        _database?.Dispose();\n        _database = null;\n        FreeNativeFunctionContexts();\n        _dataSource = null;\n        _readOnly = false;\n        _sharedMemoryPath = null;\n        if (sharedMemoryPath is not null)\n            ReleaseSharedMemoryFile(sharedMemoryPath);\n    }\n\n    private static void ValidateRestrictions(string collectionName, string?[]? restrictionValues, int maxRestrictions)\n    {\n        if (restrictionValues is not null && restrictionValues.Length > maxRestrictions)\n            throw new ArgumentException(Properties.Resources.TooManyRestrictions(collectionName));\n    }\n\n    private static string? GetRestriction(string?[]? restrictionValues, int index)\n        => restrictionValues is not null && restrictionValues.Length > index && !string.IsNullOrEmpty(restrictionValues[index])\n            ? restrictionValues[index]\n            : null;\n\n    private static string GetDeclaredSchemaObjectName(string storedName, string type, string? createSql)\n    {\n        if (string.IsNullOrWhiteSpace(createSql))\n            return storedName;\n\n        var index = 0;\n        if (!TryReadKeyword(createSql, ref index, \"CREATE\"))\n            return storedName;\n\n        _ = TryReadKeyword(createSql, ref index, \"TEMP\")\n            || TryReadKeyword(createSql, ref index, \"TEMPORARY\");","sourceCodeStart":903,"sourceCodeEnd":939,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs#L903-L939","documentation":"ValidateRestrictions throws ArgumentException when a GetSchema call passes more restriction values than the collection supports. In this provider the limits are: MetaDataCollections, ReservedWords -> 0 restrictions; Tables and Columns -> 4 (catalog, schema, table, column as applicable). Passing an over-long restriction array fails immediately, before any metadata query runs. Null or empty entries within an accepted-length array are simply ignored.","triggerScenarios":"GetSchema(\"Tables\", new[] { \"main\", null, \"users\", \"extra\" }) (5 entries also fails; 4 is the max for Tables); passing restrictions to GetSchema(\"MetaDataCollections\", values) or GetSchema(\"ReservedWords\", values) where any non-null array of length > 0 throws; generic schema tooling that fills a fixed-size restriction array (commonly 4+ slots) for every collection.","commonSituations":"Code written against SqlClient's richer restriction sets (databases/owners/table/column), shared metadata helpers assuming uniform restriction counts, and copy-paste from provider docs with different limits.","solutions":["Trim restrictionValues to the collection's limit: at most 4 for Tables/Columns, none for MetaDataCollections/ReservedWords.","Read the limit programmatically from GetSchema()'s MetaDataCollections table (NumberOfRestrictions column) before building the array.","Pass only meaningful leading restrictions and use nulls for the rest instead of extra entries."],"exampleFix":"// before\nvar t = conn.GetSchema(\"Columns\", new[] { \"main\", null, \"users\", \"id\", \"extra\" }); // 5 > 4 -> throws\n\n// after\nvar t = conn.GetSchema(\"Columns\", new[] { \"main\", null, \"users\", \"id\" }); // 4 restrictions, within limit","handlingStrategy":"validation","validationCode":"static int MaxRestrictions(string collection) => collection.ToLowerInvariant() switch\n{\n    \"tables\" or \"columns\" => 4,\n    _ => 0 // MetaDataCollections, ReservedWords\n};\n\nstatic DataTable GetSchemaSafe(SqliteConnection conn, string collection, string?[]? restrictions)\n{\n    var max = MaxRestrictions(collection);\n    if (restrictions is { Length: > 0 } r && r.Length > max)\n        restrictions = r.Length > max && max == 0 ? null : r[..max];\n    return conn.GetSchema(collection, restrictions);\n}","typeGuard":null,"tryCatchPattern":"null","preventionTips":["Read NumberOfRestrictions from GetSchema()'s MetaDataCollections table instead of hardcoding counts.","Pad with null entries inside the limit rather than appending extra restriction slots.","Wrap provider-agnostic GetSchema calls so oversized arrays are trimmed per provider."],"tags":["ado-net","sqlite","turso","schema","metadata","validation"],"backgroundTag":"invalid-schema-restrictions","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}