Validation
CSDB validation checks file structure, schema metadata, CSV data, relationships, constraints, and row indexes.
File Validation
A file is invalid when:
- The first section is not
--- csdb. - A section name is unknown.
- A table name is invalid.
- A table is missing
schemaordata. - A table appears more than once.
- Table sections are out of required order.
- The database table list does not match table sections.
Schema Validation
A schema is invalid when:
- A column has an unknown type.
- A
customtype is missingtype_name. - A column entry is missing a type.
requiredordefaultsreference an unknown column.- An optional schema field has the wrong shape when present.
- A primary key references an unknown column.
- A unique column list references an unknown column.
- A foreign key references an unknown local or target column.
- A constraint references an unknown column.
- An index references an unknown column.
- A computed field references an unknown column.
Data Validation
Data is invalid when:
- The CSV header does not exactly match schema columns and stored computed fields.
- A row has too few or too many fields.
- A value cannot be parsed as its declared type.
- A required column contains null.
- A declared primary key value is null.
- A stored computed field does not match its expression.
Key Validation
Declared primary keys must be unique.
Each unique column list must be unique across all rows.
Unique indexes must be unique for rows included by their optional where expression.
Relationship Validation
Foreign-key values must reference existing target rows unless any local foreign-key column is null.
Composite foreign keys must match target columns in order.
Constraint Validation
Every constraint expression must evaluate to true for every row.
If a constraint expression evaluates to false or cannot be evaluated, validation fails.
Row Index Validation
A row index is invalid when:
- The section name does not match
row_index:<table>:<primary_key_columns>. - The section title is not padded to
section_title_length. - Records do not match the fixed-width layout.
- A record key does not match the row's actual key.
row_numberdoes not point to the matching row.row_lengthdoes not match the row bytes.- A primary key row is missing from the index.
- The index contains a key not present in data.
Machine Section Validation
A machine section is invalid when:
- Footer key width, value width, or entry count does not match
machine_indexing. - The computed section index length does not match the actual section index bytes.
- A section index record length does not match the actual section bytes.
- Section index records are not in file order.
- The section index does not include
footeras the final record. - Machine section titles are not padded to
section_title_length. - Values are not fixed-width and right-aligned.