0

I'm fairly new to sqlite (3 hours)

What i want to do here is to get a database row into a custom object (the objects has the same nr. of propertys as the nr. of columns in the table...so it shouldn't be a problem there)

So this is my code :

#import <Foundation/Foundation.h>
#import "/usr/include/sqlite3.h"
#import "Headers.h"
@interface DataDb : NSObject{
sqlite3 *database;
}

+(DataDb*)database;
+(Singleton*)getSgForIndex:(int)index;

@end





#import "DataDb.h"

@implementation DataDb

static DataDb *database;


+(DataDb*)database
{
    if(database==nil){
        database=[[DataDb alloc]init];
    }
    return database;
}


-(id)init{
    if(self=[super init]){
        NSString *sqliteDb =[[NSBundle mainBundle] pathForResource:@"Data" ofType:@"sqlite3"];

        if(sqlite3_open([sqliteDb UTF8String], &database) !=SQLITE_OK){
            NSLog(@"Failed to open database!");
            return nil;
        }

    }
    return self;
}


+(Singleton*)getSgForIndex:(int)index{

    Singleton *returnSingleton =[[[Singleton alloc]init]autorelease];
    NSString *query =[NSString stringWithFormat:@"SELECT * FROM Quiz WHERE Q_Id=%i",index];
    sqlite3_stmt *statement;

    if (sqlite3_prepare_v2(database,[query UTF8String], -1, &statement, NULL)==SQLITE_OK) {
        NSLog (@"Works!");
        /*
        ...code...
        */

        sqlite3_finalize(statement);
    }else{
        NSLog(@"Failed!!");
    }


    return returnSingleton;
}


-(void)dealloc{
    sqlite3_close(database);
    [super dealloc];
}
@end

..and the compiler has the following problem at the sqlite3_prepare_v2 function:

Incompatible pointer types passing 'DataDb *' to parameter of type 'sqlite3 *' (aka 'struct sqlite3 *')

To be fair...the code is a modified version of a sample code i found but it worked for the guy in question and i don't understand why doesn't it work for me

1
  • show me which tutorial you use
    – Hector
    Mar 15, 2012 at 5:17

1 Answer 1

0

Because you've declare getSgForIndex as a class method not an instance, the reference to database ends up being the static DataDb *database and not the sqlite3 *database that you want. You'll have to make getSgForIndex be an instance method, not a class method. (and you might want to not call them both database to aid in reducing confusion)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.