Skip to content

Commit

Permalink
Fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
NSExceptional committed Jul 30, 2019
1 parent e78dc57 commit 993c84e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
#import "FLEXDatabaseManager.h"

@interface FLEXSQLiteDatabaseManager : NSObject <FLEXDatabaseManager>
- (NSString *)executeNonSelectQuery:(NSString *)sql;
- (NSArray<NSDictionary<NSString *, id> *> *)executeSelectionQuery:(NSString *)sql and: (NSString **)error;
- (NSString *)executeNonSelectQuery:(NSString *)sql;
- (NSArray<NSDictionary<NSString *, id> *> *)executeSelectionQuery:(NSString *)sql error:(NSString **)error;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
static NSString *const QUERY_TABLENAMES_SQL = @"SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";

@implementation FLEXSQLiteDatabaseManager
{
sqlite3* _db;
NSString* _databasePath;
}
{
sqlite3* _db;
NSString* _databasePath;
}

- (instancetype)initWithPath:(NSString*)aPath
{
self = [super init];

if (self) {
_databasePath = [aPath copy];
}
return self;
{
self = [super init];
if (self) {
_databasePath = [aPath copy];
}

return self;
}

- (BOOL)open {
if (_db) {
return YES;
Expand All @@ -51,7 +51,7 @@ - (BOOL)open {
}
return YES;
}

- (BOOL)close {
if (!_db) {
return YES;
Expand Down Expand Up @@ -84,12 +84,12 @@ - (BOOL)close {
_db = nil;
return YES;
}


- (NSArray<NSDictionary<NSString *, id> *> *)queryAllTables {
return [self executeQuery:QUERY_TABLENAMES_SQL];
}

- (NSArray<NSString *> *)queryAllColumnsWithTableName:(NSString *)tableName {
NSString *sql = [NSString stringWithFormat:@"PRAGMA table_info('%@')",tableName];
NSArray<NSDictionary<NSString *, id> *> *resultArray = [self executeQuery:sql];
Expand All @@ -100,12 +100,12 @@ - (BOOL)close {
}
return array;
}

- (NSArray<NSDictionary<NSString *, id> *> *)queryAllDataWithTableName:(NSString *)tableName {
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM %@",tableName];
return [self executeQuery:sql];
}

- (NSString *)executeNonSelectQuery:(NSString *)sql {
NSString *error = nil;

Expand All @@ -115,18 +115,18 @@ - (NSString *)executeNonSelectQuery:(NSString *)sql {
if (sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pstmt, NULL) != SQLITE_OK) {
return [NSString stringWithFormat: @"Prepare failure: %s", sqlite3_errmsg(_db)];
}

if (sqlite3_step(pstmt) != SQLITE_DONE) {
return [NSString stringWithFormat: @"Step failure: %s", sqlite3_errmsg(_db)];
}

sqlite3_finalize(pstmt);

[self close];

return error;
}

- (NSArray<NSDictionary<NSString *, id> *> *)executeSelectionQuery: (NSString *)sql and: (NSString **)error {
[self open];

Expand Down Expand Up @@ -165,11 +165,11 @@ - (NSString *)executeNonSelectQuery:(NSString *)sql {

return resultArray;
}


#pragma mark -
#pragma mark - Private

- (NSArray<NSDictionary<NSString *, id> *> *)executeQuery:(NSString *)sql {
[self open];
NSMutableArray<NSDictionary<NSString *, id> *> *resultArray = [NSMutableArray array];
Expand Down Expand Up @@ -198,10 +198,10 @@ - (NSString *)executeNonSelectQuery:(NSString *)sql {

return resultArray;
}

- (id)objectForColumnIndex:(int)columnIdx stmt:(sqlite3_stmt*)stmt {
int columnType = sqlite3_column_type(stmt, columnIdx);

id returnValue = nil;

if (columnType == SQLITE_INTEGER) {
Expand All @@ -224,7 +224,7 @@ - (id)objectForColumnIndex:(int)columnIdx stmt:(sqlite3_stmt*)stmt {

return returnValue;
}

- (NSString *)stringForColumnIndex:(int)columnIdx stmt:(sqlite3_stmt *)stmt {

if (sqlite3_column_type(stmt, columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
Expand All @@ -240,21 +240,21 @@ - (NSString *)stringForColumnIndex:(int)columnIdx stmt:(sqlite3_stmt *)stmt {

return [NSString stringWithUTF8String:c];
}
- (NSData *)dataForColumnIndex:(int)columnIdx stmt:(sqlite3_stmt *)stmt {
if (sqlite3_column_type(stmt, columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
return nil;
}
const char *dataBuffer = sqlite3_column_blob(stmt, columnIdx);
int dataSize = sqlite3_column_bytes(stmt, columnIdx);
if (dataBuffer == NULL) {
return nil;
}
return [NSData dataWithBytes:(const void *)dataBuffer length:(NSUInteger)dataSize];
}

- (NSData *)dataForColumnIndex:(int)columnIdx stmt:(sqlite3_stmt *)stmt {

if (sqlite3_column_type(stmt, columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
return nil;
}

const char *dataBuffer = sqlite3_column_blob(stmt, columnIdx);
int dataSize = sqlite3_column_bytes(stmt, columnIdx);

if (dataBuffer == NULL) {
return nil;
}

return [NSData dataWithBytes:(const void *)dataBuffer length:(NSUInteger)dataSize];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#import "FLEXSQLiteDatabaseManager.h"

@interface FLEXSQLCommandExecutionViewController: UIViewController
@property (nonatomic) BOOL isSelectionType;
@property (nonatomic) FLEXSQLiteDatabaseManager* dbManager;
@property (nonatomic) BOOL isSelectionType;
@property (nonatomic) FLEXSQLiteDatabaseManager* dbManager;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#import <objc/runtime.h>

@interface FLEXSQLCommandExecutionViewController ()
@property (nonatomic) UITextView* textView;
@property (nonatomic) UIButton* submitButton;
@property (nonatomic) UILabel* statusLabel;
@end
@property (nonatomic) UITextView* textView;
@property (nonatomic) UIButton* submitButton;
@property (nonatomic) UILabel* statusLabel;
@end

@implementation FLEXSQLCommandExecutionViewController
@synthesize isSelectionType, dbManager, textView, submitButton, statusLabel;
@synthesize isSelectionType, dbManager, textView, submitButton, statusLabel;

- (void)viewDidLoad {
[super viewDidLoad];

Expand All @@ -31,11 +31,11 @@ - (void)viewDidLoad {

[self addOtherUIElementsAndPositionThem];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
[self addOtherUIElementsAndPositionThem];
}

- (void)addOtherUIElementsAndPositionThem {
if(textView == nil) {
textView = [UITextView new];
Expand Down Expand Up @@ -78,7 +78,7 @@ - (void)addOtherUIElementsAndPositionThem {
statusLabel.frame = CGRectMake(sideMargin, textView.frame.origin.y + textViewHeight + sideMargin, width, statusLabelHeight);
submitButton.frame = CGRectMake(sideMargin, statusLabel.frame.origin.y + statusLabelHeight + sideMargin, width, submitButtonHeight);
}

- (void)submitPressed {
NSString* text = textView.text == nil ? @"" : textView.text;

Expand Down Expand Up @@ -115,22 +115,22 @@ - (void)submitPressed {
statusLabel.text = errorMessage == nil ? @"SUCCESS" : errorMessage;
}
}


- (void)presentOnErrorAlert: (NSString *)message
{
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:@"SQL Execution error !!!"
message: message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okButton = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDestructive
handler: nil];
[alert addAction:okButton];
[self presentViewController:alert animated:YES completion:nil];
}
@end
{
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:@"SQL Execution error !!!"
message: message
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* okButton = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDestructive
handler: nil];

[alert addAction:okButton];
[self presentViewController:alert animated:YES completion:nil];
}

@end

0 comments on commit 993c84e

Please sign in to comment.