@@ -870,6 +870,7 @@ bool DBBrowserDB::dump(const QString& filePath,
870870 const std::vector<std::string>& tablesToDump,
871871 bool insertColNames,
872872 bool insertNewSyntx,
873+ bool keepOriginal,
873874 bool exportSchema,
874875 bool exportData,
875876 bool keepOldSchema) const
@@ -919,11 +920,18 @@ bool DBBrowserDB::dump(const QString& filePath,
919920 if (!keepOldSchema)
920921 stream << QString (" DROP TABLE IF EXISTS %1;\n " ).arg (QString::fromStdString (sqlb::escapeIdentifier (it->name ())));
921922
922- if (it->fullyParsed ())
923- stream << QString::fromStdString (it->sql (" main" , true )) << " \n " ;
924- else
925- stream << QString::fromStdString (it->originalSql ()) << " ;\n " ;
923+ if (it->fullyParsed () && !keepOriginal)
924+ stream << QString::fromStdString (it->sql (" main" , keepOldSchema)) << " \n " ;
925+ else {
926+ QString statement = QString::fromStdString (it->originalSql ());
927+ if (keepOldSchema) {
928+ // The statement is guaranteed by SQLite to start with "CREATE TABLE"
929+ const int createTableLength = 12 ;
930+ statement.replace (0 , createTableLength, " CREATE TABLE IF NOT EXISTS" );
931+ }
932+ stream << statement << " ;\n " ;
926933 }
934+ }
927935 }
928936
929937 // Now export the data as well
@@ -1016,7 +1024,7 @@ bool DBBrowserDB::dump(const QString& filePath,
10161024 // Finally export all objects other than tables
10171025 if (exportSchema)
10181026 {
1019- auto writeSchema = [&stream, &tablesToDump, keepOldSchema](const QString& type, auto objects) {
1027+ auto writeSchema = [&stream, &tablesToDump, keepOldSchema, keepOriginal ](const QString& type, auto objects) {
10201028 for (const auto & obj : objects)
10211029 {
10221030 const auto & it = obj.second ;
@@ -1034,8 +1042,8 @@ bool DBBrowserDB::dump(const QString& filePath,
10341042 type.toUpper (),
10351043 QString::fromStdString (sqlb::escapeIdentifier (it->name ())));
10361044
1037- if (it->fullyParsed ())
1038- stream << QString::fromStdString (it->sql (" main" , true )) << " \n " ;
1045+ if (it->fullyParsed () && !keepOriginal )
1046+ stream << QString::fromStdString (it->sql (" main" , keepOldSchema )) << " \n " ;
10391047 else
10401048 stream << QString::fromStdString (it->originalSql ()) << " ;\n " ;
10411049 }
0 commit comments