@@ -856,6 +856,71 @@ - (IBAction)alterDatabase:(id)sender
856
856
contextInfo:SPAlterDatabaseAction];
857
857
}
858
858
859
+ - (IBAction)compareDatabase:(id)sender
860
+ {
861
+ /*
862
+
863
+
864
+ This method is a basic experiment to see how long it takes to read an string compare an entire database. It works,
865
+ well, good performance and very little memory usage.
866
+
867
+ Next we need to ask the user to select another connection (from the favourites list) and compare chunks of ~1000 rows
868
+ at a time, ordered by primary key, between the two databases, using three threads (one for each database and one for
869
+ comparisons).
870
+
871
+ We will the write to disk every difference that has been found and open the result in FileMerge.
872
+
873
+ In future, add the ability to write all difference to the current database.
874
+
875
+
876
+ */
877
+ NSLog(@"=================");
878
+
879
+ SPMySQLResult *showTablesQuery = [mySQLConnection queryString:@"show tables"];
880
+
881
+ NSArray *tableRow;
882
+ while ((tableRow = [showTablesQuery getRowAsArray]) != nil) {
883
+ @autoreleasepool {
884
+ NSString *table = tableRow[0];
885
+
886
+ NSLog(@"-----------------");
887
+ NSLog(@"Scanning %@", table);
888
+
889
+
890
+ NSDictionary *tableStatus = [[mySQLConnection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS LIKE %@", [table tickQuotedString]]] getRowAsDictionary];
891
+ NSInteger rowCountEstimate = [tableStatus[@"Rows"] integerValue];
892
+ NSLog(@"Estimated row count: %li", rowCountEstimate);
893
+
894
+
895
+
896
+ SPMySQLResult *tableContentsQuery = [mySQLConnection streamingQueryString:[NSString stringWithFormat:@"select * from %@", [table backtickQuotedString]] useLowMemoryBlockingStreaming:NO];
897
+ //NSDate *lastProgressUpdate = [NSDate date];
898
+ time_t lastProgressUpdate = time(NULL);
899
+ NSInteger rowCount = 0;
900
+ NSArray *row;
901
+ while (true) {
902
+ @autoreleasepool {
903
+ row = [tableContentsQuery getRowAsArray];
904
+ if (!row) {
905
+ break;
906
+ }
907
+
908
+ [row isEqualToArray:row]; // TODO: compare to the other database, instead of the same one (just doing that to test performance)
909
+
910
+ rowCount++;
911
+ if ((time(NULL) - lastProgressUpdate) > 0) {
912
+ NSLog(@"Progress: %.1f%%", (((float)rowCount) / ((float)rowCountEstimate)) * 100);
913
+ lastProgressUpdate = time(NULL);
914
+ }
915
+ }
916
+ }
917
+ NSLog(@"Done. Actual row count: %li", rowCount);
918
+ }
919
+ }
920
+
921
+ NSLog(@"=================");
922
+ }
923
+
859
924
#ifndef SP_CODA /* operations on whole databases */
860
925
/**
861
926
* opens the copy database sheet and copies the databsae
0 commit comments