top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to check SQLite table is empty or not in objective c

+1 vote
893 views

I want to check specified table contains value or its empty. I used number of complex method to find but no luck, any body can help me.

posted Jul 7, 2014 by Arun

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
NSString *sql2 = SELECT COUNT(*) FROM `myTable`;

If the result is 0 that means table is empty.

if (sqlite3_open([self.dataBasePath UTF8String], &articlesDB) == SQLITE_OK)
    {
        const char* sqlStatement = "SELECT COUNT(*) FROM MYTABLE";
        sqlite3_stmt *statement;

        if( sqlite3_prepare_v2(articlesDB, sqlStatement, -1, &statement, NULL) == SQLITE_OK )
        {
            while( sqlite3_step(statement) == SQLITE_ROW )
            {
                NSInteger count = sqlite3_column_int(statement, 0);
                NSLog(@"Rowcount is %d",count);
            }
        }
        else
        {
            NSLog( @"Failed from sqlite3_prepare_v2. Error is:  %s", sqlite3_errmsg(articlesDB) );
        }
        sqlite3_finalize(statement);
        sqlite3_close(articlesDB);
    }
answer Jul 7, 2014 by Raju
Similar Questions
+1 vote

I used HTTP MANAGER REACHABILITY to check internet availability as provided by AFNetworking document http://cocoadocs.org/docsets/AFNetworking/2.2.4/index.html

NSURL *baseURL = [NSURL URLWithString:@"http://example.com/"];
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];

NSOperationQueue *operationQueue = manager.operationQueue;
[manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
    switch (status) {
        case AFNetworkReachabilityStatusReachableViaWWAN:
        case AFNetworkReachabilityStatusReachableViaWiFi:
            [operationQueue setSuspended:NO];
            break;
        case AFNetworkReachabilityStatusNotReachable:
        default:
            [operationQueue setSuspended:YES];
            break;
    }
}];

but its not working.. i'm looking for your help.. Thanks

+1 vote

I am trying to get index path of cell when we make swipe.

I used below code to recognise cell swipe

in cellForRowAtIndexPath

UISwipeGestureRecognizer *cellRightSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self   action:@selector(cellRightSwipeGeture:)];
    [cellRightSwipe setDirection:UISwipeGestureRecognizerDirectionRight];
    [cell addGestureRecognizer:cellRightSwipe];

and action for RightSwipe

-(void)cellRightSwipeGeture:(UISwipeGestureRecognizer *)gestureRecognizer {
NSIndexPath *indexPath ;
UITableViewCell *cell = [_subItemTbl cellForRowAtIndexPath:indexPath];}

Here i can't identify that which cell was i swiped .

0 votes

I am developing my project which enables ARC feature but still some api am using is not having ARC featured code, So its throughs lot of error.

Here I need help from you to disable ARC for some class.

0 votes

I want to know how to make cross bridging to use SWIFT in Objective C class

+2 votes

I am facing situation to use objective c class in SWIFT. So, i am looking for any instruction to achieve this

...