Permalink
Browse files

Refactor the table contents view and start implementing pagination

  • Loading branch information...
mvantellingen committed Apr 15, 2012
1 parent ad6ccfa commit 9ce63740164823f806e55f4fbdcb07dde2198d26

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -30,6 +30,9 @@
E833EE4A1533669E0015521A /* OLConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = E833EE471533669E0015521A /* OLConnection.m */; };
E833EE4B1533669E0015521A /* OLQueryResult.m in Sources */ = {isa = PBXBuildFile; fileRef = E833EE491533669E0015521A /* OLQueryResult.m */; };
E833EE4E153366DC0015521A /* OLSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = E833EE4C153366DB0015521A /* OLSettings.m */; };
+ E842CF191535EDCF0010312F /* ContentPaginationView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E842CF181535EDCF0010312F /* ContentPaginationView.xib */; };
+ E842CF1C1535F1010010312F /* OLTableContentsDatasource.m in Sources */ = {isa = PBXBuildFile; fileRef = E842CF1B1535F1010010312F /* OLTableContentsDatasource.m */; };
+ E842CF1F1535F3050010312F /* OLQueryBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = E842CF1E1535F3050010312F /* OLQueryBuilder.m */; };
E88C6E9C15322BC0003D9E05 /* OLTableOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = E88C6E9B15322BC0003D9E05 /* OLTableOutlineView.m */; };
E8B5B2181530EAEB00C14A87 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8B5B2171530EAEB00C14A87 /* MainWindow.xib */; };
E8C2CFA015317A45000DEDE8 /* OLConnectionOutlineController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8C2CF9F15317A45000DEDE8 /* OLConnectionOutlineController.m */; };
@@ -150,6 +153,11 @@
E833EE491533669E0015521A /* OLQueryResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OLQueryResult.m; path = Connection/OLQueryResult.m; sourceTree = "<group>"; };
E833EE4C153366DB0015521A /* OLSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OLSettings.m; sourceTree = "<group>"; };
E833EE4D153366DB0015521A /* OLSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OLSettings.h; sourceTree = "<group>"; };
+ E842CF181535EDCF0010312F /* ContentPaginationView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ContentPaginationView.xib; sourceTree = "<group>"; };
+ E842CF1A1535F1010010312F /* OLTableContentsDatasource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OLTableContentsDatasource.h; path = TableControllers/OLTableContentsDatasource.h; sourceTree = "<group>"; };
+ E842CF1B1535F1010010312F /* OLTableContentsDatasource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OLTableContentsDatasource.m; path = TableControllers/OLTableContentsDatasource.m; sourceTree = "<group>"; };
+ E842CF1D1535F3050010312F /* OLQueryBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OLQueryBuilder.h; path = Connection/OLQueryBuilder.h; sourceTree = "<group>"; };
+ E842CF1E1535F3050010312F /* OLQueryBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OLQueryBuilder.m; path = Connection/OLQueryBuilder.m; sourceTree = "<group>"; };
E88C6E9A15322BBF003D9E05 /* OLTableOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OLTableOutlineView.h; sourceTree = "<group>"; };
E88C6E9B15322BC0003D9E05 /* OLTableOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OLTableOutlineView.m; sourceTree = "<group>"; };
E8B5B2171530EAEB00C14A87 /* MainWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = MainWindow.xib; path = "../../Olifant-old/Resources/MainWindow.xib"; sourceTree = "<group>"; };
@@ -246,6 +254,7 @@
E8B5B2171530EAEB00C14A87 /* MainWindow.xib */,
E82DE6F81530E86400C759DA /* DatabaseView.xib */,
E82DE6FB1530E86400C759DA /* Preferences.xib */,
+ E842CF181535EDCF0010312F /* ContentPaginationView.xib */,
);
path = Interfaces;
sourceTree = "<group>";
@@ -255,6 +264,8 @@
children = (
E833EE4115334B0E0015521A /* OLTableContentsController.h */,
E833EE4215334B0E0015521A /* OLTableContentsController.m */,
+ E842CF1A1535F1010010312F /* OLTableContentsDatasource.h */,
+ E842CF1B1535F1010010312F /* OLTableContentsDatasource.m */,
);
name = TableControllers;
sourceTree = "<group>";
@@ -266,6 +277,8 @@
E833EE471533669E0015521A /* OLConnection.m */,
E833EE481533669E0015521A /* OLQueryResult.h */,
E833EE491533669E0015521A /* OLQueryResult.m */,
+ E842CF1D1535F3050010312F /* OLQueryBuilder.h */,
+ E842CF1E1535F3050010312F /* OLQueryBuilder.m */,
);
name = Connection;
sourceTree = "<group>";
@@ -461,6 +474,7 @@
E82DE7001530E86400C759DA /* Preferences.xib in Resources */,
E82DE7021530E8D300C759DA /* MainMenu.xib in Resources */,
E8B5B2181530EAEB00C14A87 /* MainWindow.xib in Resources */,
+ E842CF191535EDCF0010312F /* ContentPaginationView.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -512,6 +526,8 @@
E833EE4A1533669E0015521A /* OLConnection.m in Sources */,
E833EE4B1533669E0015521A /* OLQueryResult.m in Sources */,
E833EE4E153366DC0015521A /* OLSettings.m in Sources */,
+ E842CF1C1535F1010010312F /* OLTableContentsDatasource.m in Sources */,
+ E842CF1F1535F3050010312F /* OLQueryBuilder.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -68,5 +68,31 @@
landmarkName = "@interface OLConnection"
landmarkType = "2">
</FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "Source/Connection/OLQueryBuilder.m"
+ timestampString = "355860110.660007"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "13"
+ endingLineNumber = "13"
+ landmarkName = "@implementation OLQueryBuilder"
+ landmarkType = "3">
+ </FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "Source/Connection/OLQueryBuilder.m"
+ timestampString = "355861381.520794"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "77"
+ endingLineNumber = "77"
+ landmarkName = "-generate"
+ landmarkType = "5">
+ </FileBreakpoint>
</FileBreakpoints>
</Bucket>
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "E81EA2C71530E48F00214734"
+ BuildableName = "Olifanto.app"
+ BlueprintName = "Olifanto"
+ ReferencedContainer = "container:Olifanto.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ buildConfiguration = "Debug">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "E81EA2E81530E48F00214734"
+ BuildableName = "OlifantoTests.octest"
+ BlueprintName = "OlifantoTests"
+ ReferencedContainer = "container:Olifanto.xcodeproj">
+ </BuildableReference>
+ </TestableReference>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "E81EA2C71530E48F00214734"
+ BuildableName = "Olifanto.app"
+ BlueprintName = "Olifanto"
+ ReferencedContainer = "container:Olifanto.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </TestAction>
+ <LaunchAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Debug"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "E81EA2C71530E48F00214734"
+ BuildableName = "Olifanto.app"
+ BlueprintName = "Olifanto"
+ ReferencedContainer = "container:Olifanto.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Release"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "E81EA2C71530E48F00214734"
+ BuildableName = "Olifanto.app"
+ BlueprintName = "Olifanto"
+ ReferencedContainer = "container:Olifanto.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
@@ -61,6 +61,7 @@ - (BOOL) selectDatabase: (NSString *)database
- (OLQueryResult *) executeQuery:(NSString *)statement
{
+ NSLog(@"Statement: %@", statement);
PGCcursor *cursor = [conn cursor];
NSError *error = nil;
[cursor execute: statement error:&error];
@@ -83,7 +84,25 @@ - (OLQueryResult *) executeQuery:(NSString *)statement
- (OLQueryResult *) executeQuery:(NSString *)statement withParams:(NSArray *)params
{
- NSLog(@"With params");
+ NSLog(@"Statement: %@", statement);
+ PGCcursor *cursor = [conn cursor];
+ NSError *error = nil;
+ [cursor execute:statement withParams:params error:&error];
+
+ // Get the columns names
+ NSMutableArray *columns = [NSMutableArray array];
+ NSEnumerator *e = [cursor.fields objectEnumerator];
+ PGCdescription *field;
+ while (field = [e nextObject]) {
+ [columns addObject: field.name];
+ }
+
+ OLQueryResult *result = [[OLQueryResult alloc] init];
+
+ result.rows = [cursor fetchAll];
+ result.columns = columns;
+ return result;
+
}
@@ -0,0 +1,32 @@
+//
+// OLQueryBuilder.h
+// Olifanto
+//
+// Created by Michael van Tellingen on 4/11/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface OLQueryBuilder : NSObject
+{
+ NSMutableArray *selectFields;
+ NSMutableArray *fromTables;
+ NSMutableArray *whereClauses;
+ NSMutableArray *groupByClauses;
+ NSMutableArray *orderByClauses;
+
+}
+
+@property (assign) int limit;
+@property (assign) int offset;
+
+- (id) init;
+
+- (void) select:(NSMutableArray *)fields;
+- (void) from:(NSString *)value;
+- (void) filter:(NSString *)clause value:(NSString *)value;
+
+- (NSString *)generate;
+
+@end
@@ -0,0 +1,98 @@
+//
+// OLQueryBuilder.m
+// Olifanto
+//
+// Created by Michael van Tellingen on 4/11/12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "OLQueryBuilder.h"
+#import "OLQueryResult.h"
+#import "OLConnection.h"
+
+@implementation OLQueryBuilder
+
+@synthesize limit;
+@synthesize offset;
+
+- (id) init
+{
+ self = [super init];
+ if (self != nil) {
+ selectFields = [NSMutableArray array];
+ fromTables = [NSMutableArray array];
+
+ self.limit = 0;
+ self.offset = 0;
+ }
+ return self;
+}
+
+- (void) select:(NSMutableArray *)fields
+{
+ NSEnumerator *e = [fields objectEnumerator];
+ NSString *item;
+ while (item = [e nextObject]) {
+ [selectFields addObject: item];
+ }
+}
+
+- (void) from:(NSString *)value
+{
+ [fromTables addObject:value];
+}
+
+
+- (void) filter:(NSString *)clause value:(NSString *)value
+{
+
+}
+
+
+- (NSString *)generate
+{
+ NSMutableArray *parts = [NSMutableArray array];
+ NSString *buffer;
+
+ if ([selectFields count] > 0) {
+ buffer = [NSString stringWithFormat:@"SELECT %s",
+ [selectFields componentsJoinedByString:@", "]];
+ [parts addObject:buffer];
+ }
+ else {
+ [parts addObject:@"SELECT *"];
+ }
+
+ if ([fromTables count] > 0) {
+ buffer = [NSString stringWithFormat:@"FROM %@",
+ [fromTables componentsJoinedByString:@", "]];
+ [parts addObject:buffer];
+ }
+
+ if ([whereClauses count] > 0) {
+ buffer = [NSString stringWithFormat:@"WHERE %@",
+ [selectFields componentsJoinedByString:@" AND "]];
+ [parts addObject:buffer];
+ }
+
+ if (limit > 0) {
+ buffer = [NSString stringWithFormat:@"LIMIT %d", limit];
+ [parts addObject:buffer];
+ }
+
+ if (offset > 0) {
+ buffer = [NSString stringWithFormat:@"OFFSET %d", offset];
+ [parts addObject:buffer];
+ }
+
+ return [parts componentsJoinedByString: @" "];
+}
+
+- (OLQueryResult *)execute: (OLConnection *)connection
+{
+ NSString *query = [self generate];
+ NSMutableArray *params = [NSMutableArray array];
+ return [connection executeQuery:query withParams: params];
+}
+
+@end
@@ -1,10 +1,21 @@
#import <Foundation/Foundation.h>
#import "OLConnection.h"
#import "OLTableResultView.h"
+#import "OLTableContentsDatasource.h"
+
@interface OLTableContentsController : NSObject
{
- IBOutlet OLTableResultView *resultTableController;
+ IBOutlet NSTableView *tableView;
+ IBOutlet NSButton *paginationNextButton;
+ IBOutlet NSButton *paginationPrevButton;
+ IBOutlet NSButton *paginationViewButton;
+
+ IBOutlet NSView *paginationView;
+
+ IBOutlet OLTableContentsDatasource *dataSource;
+
+
OLConnection *connection;
NSString *tableName;
@@ -16,4 +27,7 @@
- (void) selectTable:(NSString *)tableName;
- (void) setConnection:(OLConnection *)newConnection;
+- (IBAction)paginationNextPage:(id)sender;
+- (IBAction)paginationPrevPage:(id)sender;
+
@end
Oops, something went wrong.

0 comments on commit 9ce6374

Please sign in to comment.