@@ -142,13 +142,19 @@ public void CheckValidation(IStatement statement)
142
142
//to create a table
143
143
if ( x . CreateType == CreateType . Table )
144
144
{
145
+ // primary key not exists
146
+ if ( x . PrimaryKey == null || x . PrimaryKey == "" )
147
+ throw new KeyNotExistsException ( $ "Table \" { x . TableName } \" does not have a primary key") ;
145
148
//to check whether the table has been created before
146
149
Catalog_table a = new Catalog_table ( _databaseName ) ;
147
150
a . AssertNotExist ( x . TableName ) ;
148
151
}
149
152
//to create an index
150
153
else
151
154
{
155
+ // index key not exists
156
+ if ( x . AttributeName == null || x . AttributeName == "" )
157
+ throw new KeyNotExistsException ( $ "Index \" { x . IndexName } \" does not have a index key") ;
152
158
Catalog_table a = new Catalog_table ( _databaseName ) ;
153
159
Catalog_index b = new Catalog_index ( _databaseName ) ;
154
160
//to check whether the table exists
@@ -158,11 +164,11 @@ public void CheckValidation(IStatement statement)
158
164
//to check whether the attribute is in the attribute list of the table
159
165
bool condition3 = a . return_table ( x . TableName ) . Has_attribute ( x . AttributeName ) ;
160
166
if ( ! condition1 )
161
- throw new TableOrIndexNotExistsException ( $ "Table { x . TableName } not exists") ;
167
+ throw new TableOrIndexNotExistsException ( $ "Table \" \" { x . TableName } \" \" not exists") ;
162
168
if ( ! condition2 )
163
- throw new TableOrIndexAlreadyExistsException ( $ "Index { x . IndexName } not exists") ;
169
+ throw new TableOrIndexAlreadyExistsException ( $ "Index \" \" { x . IndexName } \" \" not exists") ;
164
170
if ( ! condition3 )
165
- throw new AttributeNotExistsException ( $ "Attribute { x . AttributeName } not exists in table { x . TableName } ") ;
171
+ throw new AttributeNotExistsException ( $ "Attribute \" \" { x . AttributeName } \" \" not exists in table \" \" { x . TableName } \" \" ") ;
166
172
}
167
173
}
168
174
//check validation of a drop statement
@@ -184,7 +190,7 @@ public void CheckValidation(IStatement statement)
184
190
b . AssertExist ( x . IndexName ) ;
185
191
186
192
if ( b . Of_table ( x . IndexName ) != x . TableName )
187
- throw new AttributeNotExistsException ( $ "Index { x . IndexName } is not associated with table { x . TableName } ") ;
193
+ throw new AttributeNotExistsException ( $ "Index \" { x . IndexName } \" is not associated with table \" { x . TableName } \" ") ;
188
194
}
189
195
else
190
196
b . AssertExist ( x . IndexName ) ;
@@ -218,7 +224,7 @@ public void CheckValidation(IStatement statement)
218
224
{
219
225
if ( ! a . return_table ( x . FromTable ) . Has_attribute ( expression_piece . Key ) )
220
226
{
221
- throw new AttributeNotExistsException ( $ "Attribute { expression_piece . Key } not exists in table { x . FromTable } ") ;
227
+ throw new AttributeNotExistsException ( $ "Attribute \" { expression_piece . Key } \" not exists in table \" { x . FromTable } \" ") ;
222
228
}
223
229
}
224
230
}
@@ -229,7 +235,7 @@ public void CheckValidation(IStatement statement)
229
235
//check whether the only attribute is one of the table's attributes
230
236
if ( ! a . return_table ( x . FromTable ) . Has_attribute ( x . Condition . AttributeName ) )
231
237
{
232
- throw new AttributeNotExistsException ( $ "Attribute { x . Condition . AttributeName } not exists in table { x . FromTable } ") ;
238
+ throw new AttributeNotExistsException ( $ "Attribute \" { x . Condition . AttributeName } \" not exists in table \" { x . FromTable } \" ") ;
233
239
}
234
240
235
241
}
@@ -263,7 +269,7 @@ public void CheckValidation(IStatement statement)
263
269
{
264
270
if ( ! a . return_table ( x . TableName ) . Has_attribute ( expression_piece . Key ) )
265
271
{
266
- throw new AttributeNotExistsException ( $ "Attribute { expression_piece . Key } not exists in table { x . TableName } ") ;
272
+ throw new AttributeNotExistsException ( $ "Attribute \" { expression_piece . Key } \" not exists in table \" { x . TableName } \" ") ;
267
273
}
268
274
}
269
275
}
@@ -274,7 +280,7 @@ public void CheckValidation(IStatement statement)
274
280
//check whether the only attribute is one of the table's attributes
275
281
if ( ! a . return_table ( x . TableName ) . Has_attribute ( x . Condition . AttributeName ) )
276
282
{
277
- throw new AttributeNotExistsException ( $ "Attribute { x . Condition . AttributeName } not exists in table { x . TableName } ") ;
283
+ throw new AttributeNotExistsException ( $ "Attribute \" { x . Condition . AttributeName } \" not exists in table \" { x . TableName } \" ") ;
278
284
}
279
285
280
286
}
@@ -291,14 +297,14 @@ public void CheckValidation(IStatement statement)
291
297
//check if the number of the attributes perfectly match the number of the values
292
298
if ( x . Values . Count != a . return_table ( x . TableName ) . attribute_list . Count )
293
299
{
294
- throw new NumberOfAttributesNotMatchsException ( $ "Number of attributes { x . Values . Count } not matchs { a . return_table ( x . TableName ) . attribute_list . Count } ") ;
300
+ throw new NumberOfAttributesNotMatchsException ( $ "Number of attributes not matchs. Expected: \" { a . return_table ( x . TableName ) . attribute_list . Count } \" ; actual: \" { x . Values . Count } \" ") ;
295
301
}
296
302
//check whether the type of the inserted data well suits the data definition of each attribute
297
303
for ( int i = 0 ; i < x . Values . Count ; i ++ )
298
304
{
299
305
if ( a . return_table ( x . TableName ) . attribute_list [ i ] . type != x . Values [ i ] . Type )
300
306
{
301
- throw new TypeOfAttributeNotMatchsException ( $ "Type { x . Values [ i ] . Type } of attribute { a . return_table ( x . TableName ) . attribute_list [ i ] . attribute_name } not matches { a . return_table ( x . TableName ) . attribute_list [ i ] . type } ") ;
307
+ throw new TypeOfAttributeNotMatchsException ( $ "Type for attribute \" { a . return_table ( x . TableName ) . attribute_list [ i ] . attribute_name } \" not matches. Expected: \" { a . return_table ( x . TableName ) . attribute_list [ i ] . type } \" ; actual: \" { x . Values [ i ] . Type } \" ") ;
302
308
}
303
309
}
304
310
//if all data type suit, return true
0 commit comments