On 30 March 2012 10:39, YAN HONG YE <yanhong...@mpsa.com> wrote:
> this following code is my import girl.jpg to my sqlite database, but I don't 
> know why JPG didn't up to the bin.db.
>
> #include <string.h>
> #include<stdio.h>
> #include<stdlib.h>
> #include"sqlite3.h"
>
> #pragma comment(lib, "sqlite3.lib")
>
> sqlite3 * db;
>
> sqlite3_stmt *stat;
> int main(int argc, char **argv)
> {
> char *zErrMsg=0;
> FILE *fp=NULL;
> long filesize=0;
> char* ffile=NULL;
> char* buf=NULL;
> sqlite3_open("Bin.db",&db);
> if(db==NULL)
> { return 0;}
> fp=fopen("girl.jpg","rb");
> if(fp!=NULL)
> {fseek(fp,0,SEEK_END);
> filesize=ftell(fp);
> fseek(fp,0,SEEK_SET);
> ffile=(char*)malloc(filesize);
>
> size_t sz=fread(ffile,sizeof(char),filesize,fp);
> printf("%s",ffile);
> printf("%d",filesize);
> fclose(fp);
> }
>
> sqlite3_exec(db,"create table image (filename varchar(128) unique,img 
> blob);",0,0,&zErrMsg);
>
> sqlite3_prepare(db,"insert into image values  ('girl.jpg',?)",-1,&stat,0);
>
> sqlite3_bind_blob(stat,1,ffile,filesize,NULL);
>
> sqlite3_step(stat);
> free(ffile);
>
> sqlite3_finalize(stat);
>
> sqlite3_close(db);

It is worthwhile checking for errors from the api calls...

>
>    return 0;
> }

How are you determining that the blob is not in the database?

Regards,
Simon
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to