找到你要的答案

Q:inserting image into sqlite3 database all my fields insert correct excepts image

Q:将图像分成sqlite3数据库我所有的字段插入正确的外形象

my image was not inserting into my database but my all fields inserted excepts images how can i inserted image in my database i want to pick images from image picker and from camera then save to database.

 const char*dbspath=[_database UTF8String];
if (sqlite3_open(dbspath,&_db)==SQLITE_OK) {
    sqlite3_busy_timeout(_db, 500);
    NSString*insert_sql=[NSString stringWithFormat:@"INSERT INTO addmedicien (medicienname,typesofmedicien,fromdate,date,noofdose,image)values('%s','%s','%s','%s','%s','%@')",[self.medicienname.text UTF8String],[self.typesofmedicien.text UTF8String],[self.fromdate.text UTF8String],[self.date.text UTF8String],[self.noofdose.text UTF8String],images];
     const char*insert_statement=[insert_sql UTF8String];
    sqlite3_stmt*statement;

    if (sqlite3_prepare_v2(_db, insert_statement, -1, &statement, NULL)==SQLITE_OK) {
        sqlite3_bind_blob(statement,6, [UIImagePNGRepresentation(self.imagess.image)bytes], [UIImagePNGRepresentation(self.imagess.image) length], SQLITE_TRANSIENT);
        NSData*data=[NSData dataWithBytes:sqlite3_column_blob(statement, 6) length:sqlite3_column_bytes(statement, 6)];
        if (data) {
            self.imagess.image=[UIImage imageWithData:data];
        }

        sqlite3_step(statement);
        NSLog(@"medicien and images added to db");

    }
    else
    {

        [self showUIAlertviewwithmessage:@"images not added" andtitle:@"message"];
    }sqlite3_finalize(statement);

}

     sqlite3_close(_db);       
}

我的形象是不插进我的数据库,但是我所有的领域外,我怎么能插入图像插入图像在我的数据库,我要选的图像从图像选择器和相机然后保存到数据库。

 const char*dbspath=[_database UTF8String];
if (sqlite3_open(dbspath,&_db)==SQLITE_OK) {
    sqlite3_busy_timeout(_db, 500);
    NSString*insert_sql=[NSString stringWithFormat:@"INSERT INTO addmedicien (medicienname,typesofmedicien,fromdate,date,noofdose,image)values('%s','%s','%s','%s','%s','%@')",[self.medicienname.text UTF8String],[self.typesofmedicien.text UTF8String],[self.fromdate.text UTF8String],[self.date.text UTF8String],[self.noofdose.text UTF8String],images];
     const char*insert_statement=[insert_sql UTF8String];
    sqlite3_stmt*statement;

    if (sqlite3_prepare_v2(_db, insert_statement, -1, &statement, NULL)==SQLITE_OK) {
        sqlite3_bind_blob(statement,6, [UIImagePNGRepresentation(self.imagess.image)bytes], [UIImagePNGRepresentation(self.imagess.image) length], SQLITE_TRANSIENT);
        NSData*data=[NSData dataWithBytes:sqlite3_column_blob(statement, 6) length:sqlite3_column_bytes(statement, 6)];
        if (data) {
            self.imagess.image=[UIImage imageWithData:data];
        }

        sqlite3_step(statement);
        NSLog(@"medicien and images added to db");

    }
    else
    {

        [self showUIAlertviewwithmessage:@"images not added" andtitle:@"message"];
    }sqlite3_finalize(statement);

}

     sqlite3_close(_db);       
}
ios7  sqlite3