tursodatabase/turso · error · ArgumentException

Too many restrictions specified for collection {collectionNa

Error message

Too many restrictions specified for collection {collectionName}.

What it means

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.

Source

Thrown at bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs:921

        }
    }

    private void CleanupFailedOpen(string? sharedMemoryPath)
    {
        _database?.Dispose();
        _database = null;
        FreeNativeFunctionContexts();
        _dataSource = null;
        _readOnly = false;
        _sharedMemoryPath = null;
        if (sharedMemoryPath is not null)
            ReleaseSharedMemoryFile(sharedMemoryPath);
    }

    private static void ValidateRestrictions(string collectionName, string?[]? restrictionValues, int maxRestrictions)
    {
        if (restrictionValues is not null && restrictionValues.Length > maxRestrictions)
            throw new ArgumentException(Properties.Resources.TooManyRestrictions(collectionName));
    }

    private static string? GetRestriction(string?[]? restrictionValues, int index)
        => restrictionValues is not null && restrictionValues.Length > index && !string.IsNullOrEmpty(restrictionValues[index])
            ? restrictionValues[index]
            : null;

    private static string GetDeclaredSchemaObjectName(string storedName, string type, string? createSql)
    {
        if (string.IsNullOrWhiteSpace(createSql))
            return storedName;

        var index = 0;
        if (!TryReadKeyword(createSql, ref index, "CREATE"))
            return storedName;

        _ = TryReadKeyword(createSql, ref index, "TEMP")
            || TryReadKeyword(createSql, ref index, "TEMPORARY");

View on GitHub (pinned to 6c72522679)

Solutions

  1. Trim restrictionValues to the collection's limit: at most 4 for Tables/Columns, none for MetaDataCollections/ReservedWords.
  2. Read the limit programmatically from GetSchema()'s MetaDataCollections table (NumberOfRestrictions column) before building the array.
  3. Pass only meaningful leading restrictions and use nulls for the rest instead of extra entries.

Example fix

// before
var t = conn.GetSchema("Columns", new[] { "main", null, "users", "id", "extra" }); // 5 > 4 -> throws

// after
var t = conn.GetSchema("Columns", new[] { "main", null, "users", "id" }); // 4 restrictions, within limit
Defensive patterns

Strategy: validation

Validate before calling

static int MaxRestrictions(string collection) => collection.ToLowerInvariant() switch
{
    "tables" or "columns" => 4,
    _ => 0 // MetaDataCollections, ReservedWords
};

static DataTable GetSchemaSafe(SqliteConnection conn, string collection, string?[]? restrictions)
{
    var max = MaxRestrictions(collection);
    if (restrictions is { Length: > 0 } r && r.Length > max)
        restrictions = r.Length > max && max == 0 ? null : r[..max];
    return conn.GetSchema(collection, restrictions);
}

Try / catch

null

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-08-20). Data as JSON: /api/errors/e4d1d5fdb6609d9e. Report an issue: GitHub.