@@ -816,7 +816,7 @@ bool SQLite::import_from_json(String import_path) {
816
816
/* Open the json-file and stream its content into a stringstream */
817
817
std::ifstream ifs (char_path);
818
818
if (ifs.fail ()) {
819
- UtilityFunctions::printerr (" GDSQLite Error: Failed to open specified json-file (" + import_path + " )" );
819
+ UtilityFunctions::printerr (" GDSQLite Error: " + String ( std::strerror (errno)) + " (" + import_path + " )" );
820
820
return false ;
821
821
}
822
822
std::stringstream buffer;
@@ -849,19 +849,32 @@ bool SQLite::import_from_json(String import_path) {
849
849
}
850
850
}
851
851
852
+ /* Find all views that are present in this database */
853
+ query (String (" SELECT name FROM sqlite_master WHERE type = 'view';" ));
854
+ TypedArray<Dictionary> old_view_array = query_result.duplicate (true );
855
+ int64_t old_number_of_views = old_view_array.size ();
856
+ /* Drop all old views present in the database */
857
+ for (int64_t i = 0 ; i <= old_number_of_views - 1 ; i++) {
858
+ Dictionary view_dict = old_view_array[i];
859
+ String view_name = view_dict[" name" ];
860
+ String query_string = " DROP VIEW " + view_name + " ;" ;
861
+
862
+ query (query_string);
863
+ }
864
+
852
865
/* Find all tables that are present in this database */
853
866
/* We don't care about indexes or triggers here since they get dropped automatically when their table is dropped */
854
867
query (String (" SELECT name FROM sqlite_master WHERE type = 'table';" ));
855
- TypedArray<Dictionary> old_database_array = query_result.duplicate (true );
868
+ TypedArray<Dictionary> old_table_array = query_result.duplicate (true );
856
869
#ifdef SQLITE_ENABLE_FTS5
857
870
/* FTS5 creates a bunch of shadow tables that cannot be dropped manually! */
858
871
/* The virtual table is responsible for dropping these tables itself */
859
- remove_shadow_tables (old_database_array );
872
+ remove_shadow_tables (old_table_array );
860
873
#endif
861
- int64_t old_number_of_tables = old_database_array .size ();
874
+ int64_t old_number_of_tables = old_table_array .size ();
862
875
/* Drop all old tables present in the database */
863
876
for (int64_t i = 0 ; i <= old_number_of_tables - 1 ; i++) {
864
- Dictionary table_dict = old_database_array [i];
877
+ Dictionary table_dict = old_table_array [i];
865
878
String table_name = table_dict[" name" ];
866
879
867
880
drop_table (table_name);
@@ -923,7 +936,7 @@ bool SQLite::import_from_json(String import_path) {
923
936
924
937
bool SQLite::export_to_json (String export_path) {
925
938
/* Get all names and sql templates for all tables present in the database */
926
- query (String (" SELECT name,sql,type FROM sqlite_master WHERE type = 'table' OR type = 'index' OR type = 'trigger' ;" ));
939
+ query (String (" SELECT name,sql,type FROM sqlite_master;" ));
927
940
TypedArray<Dictionary> database_array = query_result.duplicate (true );
928
941
#ifdef SQLITE_ENABLE_FTS5
929
942
/* FTS5 creates a bunch of shadow tables that should NOT be exported! */
@@ -989,7 +1002,7 @@ bool SQLite::export_to_json(String export_path) {
989
1002
990
1003
std::ofstream ofs (char_path, std::ios::trunc );
991
1004
if (ofs.fail ()) {
992
- UtilityFunctions::printerr (" GDSQLite Error: Can't open specified json-file, file does not exist or is locked " );
1005
+ UtilityFunctions::printerr (" GDSQLite Error: " + String ( std::strerror (errno)) + " ( " + export_path + " ) " );
993
1006
return false ;
994
1007
}
995
1008
Ref<JSON> json;
@@ -1049,11 +1062,13 @@ bool SQLite::validate_json(const Array &database_array, std::vector<object_struc
1049
1062
new_object.row_array = temp_dict[" row_array" ];
1050
1063
} else if (temp_dict[" type" ] == String (" index" )) {
1051
1064
new_object.type = INDEX;
1065
+ } else if (temp_dict[" type" ] == String (" view" )) {
1066
+ new_object.type = TRIGGER;
1052
1067
} else if (temp_dict[" type" ] == String (" trigger" )) {
1053
1068
new_object.type = TRIGGER;
1054
1069
} else {
1055
1070
/* Did not find the necessary key! */
1056
- UtilityFunctions::printerr (" GDSQlite Error: The value of key \" type\" is restricted to \" table\" , \" index\" or \" trigger\" " );
1071
+ UtilityFunctions::printerr (" GDSQlite Error: The value of key \" type\" is restricted to \" table\" , \" index\" , \" view \" or \" trigger\" " );
1057
1072
return false ;
1058
1073
}
1059
1074
0 commit comments