Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binder: primary key should by-default be non-null #649

Merged
merged 2 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/binder/statement/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl Binder {
// // Remove this line and change `columns` above to immut.
for &index in &ordered_pk_ids {
columns[index as usize].set_primary(true);
columns[index as usize].set_nullable(false);
}

Ok(BoundCreateTable {
Expand Down Expand Up @@ -299,7 +300,7 @@ mod tests {
ColumnCatalog::new(
0,
DataTypeKind::Int(None)
.nullable()
.not_null()
.to_column_primary_key("a".into()),
),
ColumnCatalog::new(1, DataTypeKind::Int(None).nullable().to_column("b".into())),
Expand Down
8 changes: 8 additions & 0 deletions src/catalog/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ impl ColumnDesc {
self.is_primary
}

pub fn set_nullable(&mut self, is_nullable: bool) {
self.datatype.nullable = is_nullable;
}

pub fn is_nullable(&self) -> bool {
self.datatype.is_nullable()
}
Expand Down Expand Up @@ -92,6 +96,10 @@ impl ColumnCatalog {
self.desc.is_primary()
}

pub fn set_nullable(&mut self, is_nullable: bool) {
self.desc.set_nullable(is_nullable);
}

pub fn is_nullable(&self) -> bool {
self.desc.is_nullable()
}
Expand Down