Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

insert image to database iphone
#1

-(IBAction)setimage
{
UIImagePickerController *imagpicker=[[UIImagePickerController
alloc]init];


imagpicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

imagpicker.delegate=self;

[self presentModalViewController:imagpicker animated:YES];
}
- (void)imagePickerControllerSadUIImagePickerController *)picker
didFinishPickingImageSadUIImage *)image editingInfoSadNSDictionary
*)editingInfo
{
//imag=[info objectForKey:UIImagePickerControllerOriginalImage];

NSData *data=UIImageJPEGRepresentation(image, 1);

NSString *dbpath=[self getdbpath];

if(sqlite3_open([dbpath UTF8String],&database)==SQLITE_OK)
{

const char* sqliteQuery="INSERT INTO imge(img1)VALUES(?) ";

//sqlite3_stmt* statement;

if(sqlite3_prepare_v2(database, sqliteQuery, -1, &addStmt,
NULL)==SQLITE_OK)
{
sqlite3_bind_blob(addStmt,1,[data bytes],[data
length],SQLITE_TRANSIENT);


}
if(SQLITE_DONE!=sqlite3_step(addStmt))

NSAssert1(0,@"error.'%s'",sqlite3_errmsg(database));

sqlite3_reset(addStmt);


imag=[[UIImage alloc] init];
imag=image;

[picker dismissModalViewControllerAnimated:YES];
}
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)