Преглед изворни кода

Remove useless methods, About sqlite browser

tttpeng пре 10 година
родитељ
комит
8eea2ec652

+ 36 - 1
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXDatabaseManager.m

@@ -44,6 +44,40 @@ static NSString *const QUERY_TABLENAMES_SQL = @"SELECT name FROM sqlite_master W
   return YES;
 }
 
+- (BOOL)close {
+  if (!_db) {
+    return YES;
+  }
+  
+  int  rc;
+  BOOL retry;
+  BOOL triedFinalizingOpenStatements = NO;
+  
+  do {
+    retry   = NO;
+    rc      = sqlite3_close(_db);
+    if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
+      if (!triedFinalizingOpenStatements) {
+        triedFinalizingOpenStatements = YES;
+        sqlite3_stmt *pStmt;
+        while ((pStmt = sqlite3_next_stmt(_db, nil)) !=0) {
+          NSLog(@"Closing leaked statement");
+          sqlite3_finalize(pStmt);
+          retry = YES;
+        }
+      }
+    }
+    else if (SQLITE_OK != rc) {
+      NSLog(@"error closing!: %d", rc);
+    }
+  }
+  while (retry);
+  
+  _db = nil;
+  return YES;
+}
+
+
 - (NSArray *)queryAllTables
 {
   return [self executeQuery:QUERY_TABLENAMES_SQL];
@@ -71,8 +105,8 @@ static NSString *const QUERY_TABLENAMES_SQL = @"SELECT name FROM sqlite_master W
 
 - (NSArray *)executeQuery:(NSString *)sql
 {
-  NSMutableArray *resultArray = [NSMutableArray array];
   [self open];
+  NSMutableArray *resultArray = [NSMutableArray array];
   sqlite3_stmt *pstmt;
   if (sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pstmt, 0) == SQLITE_OK) {
     while (sqlite3_step(pstmt) == SQLITE_ROW) {
@@ -93,6 +127,7 @@ static NSString *const QUERY_TABLENAMES_SQL = @"SELECT name FROM sqlite_master W
       }
     }
   }
+  [self close];
   return resultArray;
 }
 

+ 3 - 54
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXMultiColumnTableView.m

@@ -10,14 +10,6 @@
 #import "FLEXTableContentCell.h"
 #import "FLEXTableLeftCell.h"
 
-
-typedef NS_ENUM(NSInteger,UIViewSeparatorLocation) {
-  UIViewSeparatorLocationTop,
-  UIViewSeparatorLocationLeft,
-  UIViewSeparatorLocationBottom,
-  UIViewSeparatorLocationRight
-};
-
 @interface FLEXMultiColumnTableView ()
 <UITableViewDataSource, UITableViewDelegate,UIScrollViewDelegate, FLEXTableContentCellDelegate>
 
@@ -61,9 +53,9 @@ static const CGFloat kColumnMargin = 1;
   CGFloat leftHeaderWidth = [self leftHeaderWidth];
   
   CGFloat contentWidth = 0.0;
-  NSInteger rowsCount = [self.dataSource numberOfColumnsInTableView:self];
+  NSInteger rowsCount = [self numberOfColumns];
   for (int i = 0; i < rowsCount; i++) {
-    contentWidth += [self.dataSource multiColumnTableView:self widthForContentCellInColumn:i];
+    contentWidth += [self contentWidthForColumn:i];
   }
   
   self.leftTableView.frame           = CGRectMake(0, topheaderHeight, leftHeaderWidth, height - topheaderHeight);
@@ -76,7 +68,6 @@ static const CGFloat kColumnMargin = 1;
 }
 
 
-
 - (void)loadUI
 {
   [self loadHeaderScrollView];
@@ -239,7 +230,7 @@ static const CGFloat kColumnMargin = 1;
   else {
     FLEXTableLeftCell *cell          = [FLEXTableLeftCell cellWithTableView:tableView];
     cell.contentView.backgroundColor = backgroundColor;
-    cell.titlelabel.text             = [self.dataSource rowNameInRow:indexPath.row];
+    cell.titlelabel.text             = [self rowTitleForRow:indexPath.row];
     return cell;
   }
 }
@@ -351,46 +342,4 @@ static const CGFloat kColumnMargin = 1;
   }
 }
 
-#pragma mark -
-#pragma mark - Private
-
-
-
-- (void)addSeparatorLineInView:(UIView *)view
-                      andWidth:(CGFloat)lineWidth
-                   andLocation:(UIViewSeparatorLocation)location
-                      andColor:(UIColor *)color
-{
-  CGFloat width  = view.frame.size.width;
-  CGFloat height = view.frame.size.height;
-  UIView *line = [[UIView alloc] init];
-  line.backgroundColor = color;
-  switch (location) {
-    case UIViewSeparatorLocationTop:
-      line.frame = CGRectMake(0, 0, width, lineWidth);
-      [view addSubview:line];
-      break;
-    case UIViewSeparatorLocationLeft:
-      line.frame = CGRectMake(0, 0, lineWidth, height);
-      [view addSubview:line];
-      break;
-    case UIViewSeparatorLocationBottom:
-      line.frame = CGRectMake(0, height - lineWidth, width, lineWidth);
-      [view addSubview:line];
-      break;
-    case UIViewSeparatorLocationRight:
-      line.frame = CGRectMake(width - lineWidth, 0, lineWidth, height);
-      [view addSubview:line];
-      break;
-  }
-}
-
-- (UIColor *)randomColor{
-  
-  CGFloat red = (CGFloat)random()/(CGFloat)RAND_MAX;
-  CGFloat green = (CGFloat)random()/(CGFloat)RAND_MAX;
-  CGFloat blue = (CGFloat)random()/(CGFloat)RAND_MAX;
-  return [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
-}
-
 @end

+ 0 - 1
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXTableColumnHeader.h

@@ -14,7 +14,6 @@ typedef NS_ENUM(NSUInteger, FLEXTableColumnHeaderSortType) {
   FLEXTableColumnHeaderSortTypeDesc,
 };
 
-
 @interface FLEXTableColumnHeader : UIView
 
 @property (nonatomic, weak) UILabel *label;

+ 3 - 5
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXTableContentViewController.m

@@ -72,10 +72,9 @@
 
 - (NSString *)rowNameInRow:(NSInteger)row
 {
-  
   return [NSString stringWithFormat:@"%ld",(long)row];
-  
 }
+
 - (NSString *)contentAtColumn:(NSInteger)column row:(NSInteger)row
 {
   if (self.contensArray.count > row) {
@@ -84,7 +83,7 @@
       return [NSString stringWithFormat:@"%@",[dic objectForKey:self.columnsArray[column]]];
     }
   }
-  return @"this is bug";
+  return @"";
 }
 
 - (NSArray *)contentAtRow:(NSInteger)row
@@ -99,6 +98,7 @@
   }
   return nil;
 }
+
 - (CGFloat)multiColumnTableView:(FLEXMultiColumnTableView *)tableView
       heightForContentCellInRow:(NSInteger)row
 {
@@ -111,7 +111,6 @@
   return 120;
 }
 
-
 - (CGFloat)heightForTopHeaderInTableView:(FLEXMultiColumnTableView *)tableView
 {
   return 40;
@@ -127,7 +126,6 @@
   return size.width + 20;
 }
 
-
 #pragma mark -
 #pragma mark MultiColumnTableView Delegate