Skip to content

Commit 24de18b

Browse files
committed
added support for duplicate column names
1 parent e496f61 commit 24de18b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ FLAGS:
4848
- [x] Generic validation structure for SQL Commands.
4949
- [x] `Create Table` Command Parsing
5050
- [x] Improve error handling with https://github.com/dtolnay/thiserror
51+
- [x] Added support for parsing duplicate columns on CREATE TABLE
5152
- [ ] In memory BTreeMap indexes initially only for PRIMARY KEYS.
5253
- [ ] Simple INSERT queries command parsing.
5354
- [ ] Serialization | Deserialization to and from binary encodings (Investigating).

src/sql/parser/create.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use sqlparser::ast::{ColumnOption, DataType, Statement};
22

33
use crate::error::{Result, SQLRiteError};
44

5+
use std::collections::HashMap;
6+
57
// Represents Columns in a table
68
#[derive(PartialEq, Debug)]
79
pub struct ParsedColumn {
@@ -35,11 +37,15 @@ impl CreateQuery {
3537
} => {
3638
let table_name = name;
3739
let mut parsed_columns: Vec<ParsedColumn> = vec![];
40+
let mut pushed_columns: HashMap<String, bool> = HashMap::new();
3841

3942
// Iterating over the columns returned form the Parser::parse:sql
4043
// in the mod sql
4144
for col in columns {
4245
let name = col.name.to_string();
46+
if pushed_columns.contains_key(&name) {
47+
return Err(SQLRiteError::Internal(format!("Duplicate column name: {}", &name)))
48+
}
4349
// TODO: Add datetime and timestamp here
4450
// Parsing each column for it data type
4551
// For now only accepting basic data types
@@ -81,13 +87,16 @@ impl CreateQuery {
8187
};
8288
}
8389

90+
pushed_columns.insert(name.clone(), true);
91+
8492
parsed_columns.push(ParsedColumn {
8593
name,
8694
datatype: datatype.to_string(),
8795
is_pk,
8896
is_nullable,
8997
is_unique,
9098
});
99+
91100
}
92101
// TODO: Handle constraints,
93102
// Default value and others.

0 commit comments

Comments
 (0)