@@ -93,10 +93,10 @@ RollbackManager::RollbackManager(const std::string & world_path,
93
93
std::string migrating_flag = txt_filename + " .migrating" ;
94
94
database_path = world_path + DIR_DELIM " rollback.sqlite" ;
95
95
96
- initDatabase ();
96
+ bool created = initDatabase ();
97
97
98
- if (fs::PathExists (txt_filename) && (fs::PathExists (migrating_flag) ||
99
- ! fs::PathExists (database_path ))) {
98
+ if (fs::PathExists (txt_filename) && (created ||
99
+ fs::PathExists (migrating_flag ))) {
100
100
std::ofstream of (migrating_flag.c_str ());
101
101
of.close ();
102
102
migrate (txt_filename);
@@ -250,15 +250,15 @@ bool RollbackManager::createTables()
250
250
}
251
251
252
252
253
- void RollbackManager::initDatabase ()
253
+ bool RollbackManager::initDatabase ()
254
254
{
255
255
verbosestream << " RollbackManager: Database connection setup" << std::endl;
256
256
257
- bool needsCreate = !fs::PathExists (database_path);
257
+ bool needs_create = !fs::PathExists (database_path);
258
258
SQLOK (sqlite3_open_v2 (database_path.c_str (), &db,
259
259
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL ));
260
260
261
- if (needsCreate ) {
261
+ if (needs_create ) {
262
262
createTables ();
263
263
}
264
264
@@ -374,6 +374,8 @@ void RollbackManager::initDatabase()
374
374
);
375
375
}
376
376
SQLOK (sqlite3_reset (stmt_knownNode_select));
377
+
378
+ return needs_create;
377
379
}
378
380
379
381
@@ -672,23 +674,27 @@ void RollbackManager::migrate(const std::string & file_path)
672
674
673
675
std::streampos file_size = fh.tellg ();
674
676
675
- if (file_size > 10 ) {
677
+ if (file_size < 10 ) {
676
678
errorstream << " Empty rollback log." << std::endl;
677
679
return ;
678
680
}
679
681
680
682
fh.seekg (0 );
681
683
684
+ sqlite3_stmt *stmt_begin;
685
+ sqlite3_stmt *stmt_commit;
686
+ SQLOK (sqlite3_prepare_v2 (db, " BEGIN" , -1 , &stmt_begin, NULL ));
687
+ SQLOK (sqlite3_prepare_v2 (db, " COMMIT" , -1 , &stmt_commit, NULL ));
688
+
682
689
std::string bit;
683
690
int i = 0 ;
684
- int id = 1 ;
685
691
time_t start = time (0 );
686
692
time_t t = start;
687
- sqlite3_exec (db, " BEGIN" , NULL , NULL , NULL );
693
+ SQLRES (sqlite3_step (stmt_begin), SQLITE_DONE);
694
+ sqlite3_reset (stmt_begin);
688
695
do {
689
696
ActionRow row;
690
-
691
- row.id = id;
697
+ row.id = 0 ;
692
698
693
699
// Get the timestamp
694
700
std::getline (fh, bit, ' ' );
@@ -758,17 +764,24 @@ void RollbackManager::migrate(const std::string & file_path)
758
764
++i;
759
765
760
766
if (time (0 ) - t >= 1 ) {
761
- sqlite3_exec (db, " COMMIT" , NULL , NULL , NULL );
767
+ SQLRES (sqlite3_step (stmt_commit), SQLITE_DONE);
768
+ sqlite3_reset (stmt_commit);
762
769
t = time (0 );
763
770
std::cout
764
771
<< " Done: " << static_cast <int >((static_cast <float >(fh.tellg ()) / static_cast <float >(file_size)) * 100 ) << " %"
765
772
<< " Speed: " << i / (t - start) << " /second \r " << std::flush;
766
- sqlite3_exec (db, " BEGIN" , NULL , NULL , NULL );
773
+ SQLRES (sqlite3_step (stmt_begin), SQLITE_DONE);
774
+ sqlite3_reset (stmt_begin);
767
775
}
768
776
} while (fh.good ());
777
+ SQLRES (sqlite3_step (stmt_commit), SQLITE_DONE);
778
+ sqlite3_reset (stmt_commit);
779
+
780
+ SQLOK (sqlite3_finalize (stmt_begin));
781
+ SQLOK (sqlite3_finalize (stmt_commit));
769
782
770
783
std::cout
771
- << " Done: 100% " << std::endl
784
+ << " Done: 100% " << std::endl
772
785
<< " Now you can delete the old rollback.txt file." << std::endl;
773
786
}
774
787
0 commit comments