@@ -2,6 +2,8 @@ use sqlparser::ast::{ColumnOption, DataType, Statement};
2
2
3
3
use crate :: error:: { Result , SQLRiteError } ;
4
4
5
+ use std:: collections:: HashMap ;
6
+
5
7
// Represents Columns in a table
6
8
#[ derive( PartialEq , Debug ) ]
7
9
pub struct ParsedColumn {
@@ -35,11 +37,15 @@ impl CreateQuery {
35
37
} => {
36
38
let table_name = name;
37
39
let mut parsed_columns: Vec < ParsedColumn > = vec ! [ ] ;
40
+ let mut pushed_columns: HashMap < String , bool > = HashMap :: new ( ) ;
38
41
39
42
// Iterating over the columns returned form the Parser::parse:sql
40
43
// in the mod sql
41
44
for col in columns {
42
45
let name = col. name . to_string ( ) ;
46
+ if pushed_columns. contains_key ( & name) {
47
+ return Err ( SQLRiteError :: Internal ( format ! ( "Duplicate column name: {}" , & name) ) )
48
+ }
43
49
// TODO: Add datetime and timestamp here
44
50
// Parsing each column for it data type
45
51
// For now only accepting basic data types
@@ -81,13 +87,16 @@ impl CreateQuery {
81
87
} ;
82
88
}
83
89
90
+ pushed_columns. insert ( name. clone ( ) , true ) ;
91
+
84
92
parsed_columns. push ( ParsedColumn {
85
93
name,
86
94
datatype : datatype. to_string ( ) ,
87
95
is_pk,
88
96
is_nullable,
89
97
is_unique,
90
98
} ) ;
99
+
91
100
}
92
101
// TODO: Handle constraints,
93
102
// Default value and others.
0 commit comments