aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/MainMenu.xib16
-rw-r--r--Source/SPDatabaseDocument.m65
2 files changed, 76 insertions, 5 deletions
diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib
index d77e21c2..3ee6f8b8 100644
--- a/Interfaces/English.lproj/MainMenu.xib
+++ b/Interfaces/English.lproj/MainMenu.xib
@@ -1,9 +1,8 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6751" systemVersion="13F1507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
- <development version="5100" identifier="xcode"/>
- <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6751"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11542"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -12,7 +11,7 @@
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
- <customObject id="-3" userLabel="Application">
+ <customObject id="-3" userLabel="Application" customClass="NSObject">
<connections>
<outlet property="delegate" destination="213" id="1001"/>
</connections>
@@ -675,6 +674,13 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="1084"/>
+ <menuItem title="Compare with Database..." id="FTw-6C-ZIz">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="compareDatabase:" target="-1" id="byr-GU-wZt"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="yfj-rl-UMP"/>
<menuItem title="Duplicate Database..." id="1077">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m
index c338224b..6b61a99e 100644
--- a/Source/SPDatabaseDocument.m
+++ b/Source/SPDatabaseDocument.m
@@ -856,6 +856,71 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0;
contextInfo:SPAlterDatabaseAction];
}
+- (IBAction)compareDatabase:(id)sender
+{
+ /*
+
+
+ This method is a basic experiment to see how long it takes to read an string compare an entire database. It works,
+ well, good performance and very little memory usage.
+
+ Next we need to ask the user to select another connection (from the favourites list) and compare chunks of ~1000 rows
+ at a time, ordered by primary key, between the two databases, using three threads (one for each database and one for
+ comparisons).
+
+ We will the write to disk every difference that has been found and open the result in FileMerge.
+
+ In future, add the ability to write all difference to the current database.
+
+
+ */
+ NSLog(@"=================");
+
+ SPMySQLResult *showTablesQuery = [mySQLConnection queryString:@"show tables"];
+
+ NSArray *tableRow;
+ while ((tableRow = [showTablesQuery getRowAsArray]) != nil) {
+ @autoreleasepool {
+ NSString *table = tableRow[0];
+
+ NSLog(@"-----------------");
+ NSLog(@"Scanning %@", table);
+
+
+ NSDictionary *tableStatus = [[mySQLConnection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS LIKE %@", [table tickQuotedString]]] getRowAsDictionary];
+ NSInteger rowCountEstimate = [tableStatus[@"Rows"] integerValue];
+ NSLog(@"Estimated row count: %li", rowCountEstimate);
+
+
+
+ SPMySQLResult *tableContentsQuery = [mySQLConnection streamingQueryString:[NSString stringWithFormat:@"select * from %@", [table backtickQuotedString]] useLowMemoryBlockingStreaming:NO];
+ //NSDate *lastProgressUpdate = [NSDate date];
+ time_t lastProgressUpdate = time(NULL);
+ NSInteger rowCount = 0;
+ NSArray *row;
+ while (true) {
+ @autoreleasepool {
+ row = [tableContentsQuery getRowAsArray];
+ if (!row) {
+ break;
+ }
+
+ [row isEqualToArray:row]; // TODO: compare to the other database, instead of the same one (just doing that to test performance)
+
+ rowCount++;
+ if ((time(NULL) - lastProgressUpdate) > 0) {
+ NSLog(@"Progress: %.1f%%", (((float)rowCount) / ((float)rowCountEstimate)) * 100);
+ lastProgressUpdate = time(NULL);
+ }
+ }
+ }
+ NSLog(@"Done. Actual row count: %li", rowCount);
+ }
+ }
+
+ NSLog(@"=================");
+}
+
#ifndef SP_CODA /* operations on whole databases */
/**
* opens the copy database sheet and copies the databsae