@@ -364,6 +364,10 @@ bool SQLite::query_with_bindings(const String &p_query, Array param_bindings)
364
364
365
365
bool SQLite::create_table (const String &p_name, const Dictionary &p_table_dict)
366
366
{
367
+ if (!validate_table_dict (p_table_dict)) {
368
+ return false ;
369
+ }
370
+
367
371
String query_string, type_string, key_string;
368
372
String integer_datatype = " int" ;
369
373
/* Create SQL statement */
@@ -376,11 +380,6 @@ bool SQLite::create_table(const String &p_name, const Dictionary &p_table_dict)
376
380
for (int64_t i = 0 ; i <= number_of_columns - 1 ; i++)
377
381
{
378
382
column_dict = p_table_dict[columns[i]];
379
- if (!column_dict.has (" data_type" ))
380
- {
381
- UtilityFunctions::printerr (" GDSQLite Error: The field \" data_type\" is a required part of the table dictionary" );
382
- return false ;
383
- }
384
383
query_string += (const String &)columns[i] + String (" " );
385
384
type_string = (const String &)column_dict[" data_type" ];
386
385
if (type_string.to_lower ().begins_with (integer_datatype))
@@ -445,6 +444,36 @@ bool SQLite::create_table(const String &p_name, const Dictionary &p_table_dict)
445
444
return query (query_string);
446
445
}
447
446
447
+ bool SQLite::validate_table_dict (const Dictionary &p_table_dict) {
448
+ Dictionary column_dict;
449
+ Array columns = p_table_dict.keys ();
450
+ int64_t number_of_columns = columns.size ();
451
+ for (int64_t i = 0 ; i <= number_of_columns - 1 ; i++)
452
+ {
453
+ if (p_table_dict[columns[i]].get_type () != Variant::DICTIONARY) {
454
+ UtilityFunctions::printerr (" GDSQLite Error: All values of the table dictionary should be of type Dictionary" );
455
+ return false ;
456
+ }
457
+
458
+ column_dict = p_table_dict[columns[i]];
459
+ if (!column_dict.has (" data_type" ))
460
+ {
461
+ UtilityFunctions::printerr (" GDSQLite Error: The field \" data_type\" is a required part of the table dictionary" );
462
+ return false ;
463
+ }
464
+
465
+ if (column_dict.has (" default" ))
466
+ {
467
+ if (column_dict[" default" ].get_type () != Variant::STRING) {
468
+ UtilityFunctions::printerr (" GDSQLite Error: The field \" default\" should be of type String" );
469
+ return false ;
470
+ }
471
+ }
472
+ }
473
+
474
+ return true ;
475
+ }
476
+
448
477
bool SQLite::drop_table (const String &p_name)
449
478
{
450
479
String query_string;
0 commit comments