Monday, 6 January 2014

1. It's a very easy concept to insert the images in to database but am facing the issue while inserting the values in to DB.

Actually it's executing fine but unable to see the data in the table.

I got the error Msg Like : "error library routine called out of sequence"

If any one know about this issue.. pls suggest how to resolve this.

Here the implementation code is:

-(void)insertDataInToDb1:(UIImage *)image1 image2:(UIImage *)image2 Image3:(UIImage *)image3 Image4:(UIImage *)image4 innerRadius:(float)innervalue outerRadius:(float)OuteValue width:(float)andwidth screenShot:(UIImage *)currentImageScreen


{
    filePath =  [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:@"InstaPicDatabase.sqlite"];
    const char *dbPath = [filePath UTF8String];
    NSLog(@"File Path %@ and Db Path is : %s", filePath, dbPath);
    
        if (sqlite3_open(dbPath, &dataBaseName) == SQLITE_OK)
        {
            NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO InstaPicTable (ImageView1,ImageView2,ImageView3,ImageView4,InnerRadius,OuterRadius,Width,ImageScreenShot) VALUES ('%@','%@','%@','%@','%f','%f','%f','%@')", image1,image2,image3,image4,innervalue,OuteValue,andwidth,currentImageScreen];
            
            const char *insert_Stmt = [insertSQL cStringUsingEncoding:NSUTF8StringEncoding];
            sqlite3_stmt *preparedStatement;
            
            NSData *imageData1 = (UIImagePNGRepresentation(image1));
            NSData *imageData2 = (UIImagePNGRepresentation(image2));
            NSData *imageData3 = (UIImagePNGRepresentation(image3));
            NSData *imageData4 = (UIImagePNGRepresentation(image4));
            NSData *currentData = (UIImagePNGRepresentation(currentImageScreen));
            
          if (sqlite3_prepare_v2(dataBaseName, insert_Stmt, -1, &preparedStatement, NULL) == SQLITE_OK)
          {
            if (sqlite3_step(preparedStatement)!= SQLITE_DONE)
            {
                
            }
            else
            {
                
                sqlite3_bind_blob(preparedStatement, 1, [imageData1 bytes], [imageData1 length], NULL);
                sqlite3_bind_blob(preparedStatement, 2, [imageData2 bytes], [imageData2 length], NULL);
                sqlite3_bind_blob(preparedStatement, 3, [imageData3 bytes], [imageData3 length], NULL);
                sqlite3_bind_blob(preparedStatement, 4, [imageData4 bytes], [imageData4 length], NULL);
                sqlite3_bind_double(preparedStatement, 5, innervalue);
                sqlite3_bind_double(preparedStatement, 6, OuteValue);
                sqlite3_bind_double(preparedStatement, 7, andwidth);
                sqlite3_bind_blob(preparedStatement, 8, [currentData bytes], [currentData length], SQLITE_TRANSIENT);
                NSLog(@"inserting success");
            }
              sqlite3_finalize(preparedStatement);
              sqlite3_close(dataBaseName);
        }
        }
        else
        {
            sqlite3_close(dataBaseName);    //Even though the open call failed, close the database connection to release all the memory.
            
        }
    
    NSLog(@"Error  %s\n", sqlite3_errmsg(dataBaseName));
}

No comments:

Post a Comment