views:

24

answers:

0

I am having a date datatype to be added into the database but i dont know how to insert the date datatype into the database ` +(void)insertbarcodeid:(NSString *)barcode brand:(NSString *)brand productname:(NSString *)productname productsize:(NSString *)productsize productcategory:(NSString *)productcategory productopendate:(NSDate *)productopendate productexpirydate:(NSDate *)productexpirydate greendate:(NSDate *)greenDate yellowdate:(NSDate *)yellowDate redDate:(NSDate *)redDate notificationGreenDate:(NSDate *)notificationGreenDate notificationYellowDate:(NSDate *)notificationYellowDate notificationRedDate:(NSDate *)notificationRedDate DaystogoForGreen:(int)DaysToGoForGreen DaystogoForYellow:(int)DaystogoForYellow{ @try { sqlite3 *database;

    sqlite3_stmt *insertStatement; 
    insertStatement =nil;
    ZXingAppDelegate *object=(ZXingAppDelegate *)[[UIApplication sharedApplication]delegate];

    if(insertStatement == nil  && (sqlite3_open([[object dataBasePath] UTF8String],&database) == SQLITE_OK )) 
    {
        const char *sql = "insert into foodproduct(barcodeid,brand,productname,productsize,productcategory,productopendate,productexpirydate,greendate,yellowdate,reddate,notificationdateforgreen,notificationdateforyellow,notificationdateforred,DaysToGoForGreen,DaysToGoForYellow) Values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        if(sqlite3_prepare_v2(database, sql, -1, &insertStatement, NULL) != SQLITE_OK)
        NSAssert1(0, @"Error in Insert Statement. '%s'", sqlite3_errmsg(database));



    /*  const char *sql = "insert into Baby_Master (BabyNumber,BabyName,BabyType,DueDate,FatherName,MotherName,StartDate) Values(?,?,?,?,?,?,?)";
        if(sqlite3_prepare_v2(iBabySonoDatabase, sql, -1, &insertStatement, NULL) != SQLITE_OK) 
            NSAssert1(0, @"Error in Insert Statement. '%s'", sqlite3_errmsg(iBabySonoDatabase));*/
    }
    barcode=@"1111111";

    sqlite3_bind_text(insertStatement, 8, [barcode UTF8String], -1, SQLITE_TRANSIENT);      
    sqlite3_bind_text(insertStatement, 2, [brand UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(insertStatement, 3, [productname  UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(insertStatement, 4, [productsize  UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(insertStatement, 5, [productcategory UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(insertStatement, 6, [productopendate UTF8String ] , -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(insertStatement, 7, [productexpirydate UTF8String], -1, SQLITE_TRANSIENT);

    if(SQLITE_DONE != sqlite3_step(insertStatement))
    {
        NSAssert1(0, @"Error while Inserting New Baby '%s'", sqlite3_errmsg(database));
    }
    sqlite3_reset(insertStatement);
    sqlite3_finalize(insertStatement);
    insertStatement = nil;
}
@catch (NSException *e)
{
    NSLog(@"insert new baby....................");
}

}

Here the code runs succesfully but there is warning when i add the line

sqlite3_bind_text(insertStatement, 6, [productopendate UTF8String ] , -1, SQLITE_TRANSIENT); sqlite3_bind_text(insertStatement, 7, [productexpirydate UTF8String], -1, SQLITE_TRANSIENT);

The datatype for productopendate ,productexpirydate is NSDate. here i dont know what to write in place of UTF8String. here it shows the error of incompatible pointer type conversion.

thanks in advance .....