Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:34:44+00:00 2026-05-27T15:34:44+00:00

-(void)myDatabaseFunction { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString

  • 0
-(void)myDatabaseFunction
{   
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"HHAuditToolDatabase.sqlite"];
if (sqlite3_open([writableDBPath UTF8String], &database) == SQLITE_OK){
NSLog(@"opening db");
NSString *keyValue;
NSString *sqlStr = @"SELECT * FROM HHAuditTable";
//following if() not working dude!!!!
//its working with !=SQLITE_OK      
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

sqlite3_stmt *addStmt = nil;

if(sqlite3_prepare_v2(database,[sqlStr UTF8String], -1, &addStmt, NULL) != SQLITE_OK){
    NSLog(@"%@",sqlStr);
    while (sqlite3_step(addStmt) == SQLITE_ROW) {


const unsigned char *querry_returns = sqlite3_column_text(addStmt, 0);
        keyValue = [[NSString alloc]initWithUTF8String:(char *) sqlite3_column_text(addStmt, 0)];
        }

        NSLog(@"value from DB = %@",keyValue);

That if() with comment doesn’t work….Some have a cure!!! i have been on it for last 3 hrs….please come up with a soln

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:34:45+00:00Added an answer on May 27, 2026 at 3:34 pm

    Hay you can use my code its working fine for me:-

     (void)myDatabaseFunction {
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    dbPath = [self getDBPath];
    BOOL success = [fileManager fileExistsAtPath:dbPath]; 
    
    if(!success) {
    
        NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"flipsy.sqlite"];
        success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
    
        if (!success) 
            NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    
    }
    NSString *sql = @"SELECT * FROM HHAuditTable";
     NSInteger *intvalue;
        result = [[NSMutableArray alloc] init]; 
       // NSLog(@"sql--------->%@",sql);
        const char *sqlStatement = [sql UTF8String];
    
    //if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
    
        if(sqlite3_prepare_v2(database, sqlStatement, -1, &selectstmt , NULL)!= SQLITE_OK) {
        }
    
        else {
    
            //NSLog(@"%@",dataTypeArray);
    
            for(int i=0;i<[dataTypeArray count];i++) {
                temp = [[NSMutableArray alloc] init];
                [result addObject:temp];
               // [temp release];
            }
            while(sqlite3_step(selectstmt) == SQLITE_ROW) {
    
                for(int i=0;i<[dataTypeArray count];i++) {
    
                    switch( [[dataTypeArray objectAtIndex:i] integerValue] ) {
    
                        case 0:
                            intvalue = (NSInteger *)sqlite3_column_int(selectstmt,i);
                            strvalue = [NSString stringWithFormat:@"%d",intvalue];
                            [[result objectAtIndex:i] addObject:(NSNumber *)strvalue];
    
    
                            break;
    
                        case 1:
                            [[result objectAtIndex:i]  addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, i)]];
                            break;
    
                        case 2:
    
                            blob = [[NSData alloc] initWithBytes:sqlite3_column_blob(selectstmt, i) length:sqlite3_column_bytes(selectstmt, i)];
                            [[result objectAtIndex:i] addObject:blob];
                            [blob autorelease];
                            break;
    
    
                        default:
                            defaultValue=[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, i)];
                            break;
    
                        }//switch
    
                }//for(int i=0;i<[dataTypeArray count];i++)
    
            }//while(sqlite3_step(selectstmt) == SQLITE_ROW)
    
        //}//else
    
        //sqlite3_close(database);
        sqlite3_finalize(selectstmt);
        [temp release];
    
    }//if (sqlite3_open([dbPath UTF
    
    }
    
    - (NSString *) getDBPath {
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    return [documentsDir stringByAppendingPathComponent:@"flipsy.sqlite"];
    }
    

    Please let me know if any clarification needed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

-(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSString *theXML = [[NSString alloc] initWithBytes: [myWebData mutableBytes] length:[myWebData length] encoding:NSUTF8StringEncoding];
- (void)loadLocations { NSString *url = @<URL to a text file>; NSStringEncoding enc =
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint
- (void)viewDidLoad { moveObjectTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(moveObject) userInfo:nil repeats:YES] -(void)moveObject image.center =
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //currentElenet is NSString
- (void)viewDidLoad { [super viewDidLoad]; definedNames = [[NSArray alloc] initWithObjects:@Ohio, @Newark, @Steve, @Coffee, nil];
void (int a[]) { a[5] = 3; // this is wrong? } Can I
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
void some_func(int param = get_default_param_value());
void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.