Re[2]: [sqlite] BLOB question

2007-02-23 Thread Teg
Hello Cesar, Friday, February 23, 2007, 11:19:23 AM, you wrote: CR> good idea!! i didn't think in this!! CR> On 23/02/07, Martin Jenkins <[EMAIL PROTECTED]> wrote: >> Cesar Rodas wrote: >> >while ( (n=fread(buff,Buffsize,1,file)) > 0) >> >{ >> >if (i>0) >> >*value = r

Re: [sqlite] BLOB question

2007-02-23 Thread Cesar Rodas
good idea!! i didn't think in this!! On 23/02/07, Martin Jenkins <[EMAIL PROTECTED]> wrote: Cesar Rodas wrote: >while ( (n=fread(buff,Buffsize,1,file)) > 0) >{ >if (i>0) >*value = realloc(*value, (i+1) * Buffsize); >memcpy(*value + (i * Buffsize), buff, Buffs

Re: [sqlite] BLOB question

2007-02-23 Thread John Stanton
I would make your routine more like this. It avoids the needless buffer shadowing you get by using fopen and also avoids unecessary mallocs. I haven't tested the code, it just presents the method. unsigned char *bp; int fd; long fsize; fd = open(path, O_RDWR);

Re: [sqlite] BLOB question

2007-02-23 Thread Martin Jenkins
Wesley W. Terpstra wrote: This segfaults because there is no null terminator on the value string. I tested this and it crapped out in the memcpy, ie before it gets to the sqlite3_mprintf. Not to say there isn't a problem there too but I don't know the API details offhand so can't comment. I'

Re: [sqlite] BLOB question

2007-02-23 Thread Martin Jenkins
Cesar Rodas wrote: while ( (n=fread(buff,Buffsize,1,file)) > 0) { if (i>0) *value = realloc(*value, (i+1) * Buffsize); memcpy(*value + (i * Buffsize), buff, Buffsize); *len += n; i++; } An afterthought, why don't you just stat the file and malloc

Re: [sqlite] BLOB question

2007-02-23 Thread Cesar Rodas
Sorry I copy bad when I wanted to write "#define uchar unsigned char" but I did "#define uchar unsigned char *" On 23/02/07, Martin Jenkins <[EMAIL PROTECTED]> wrote: Cesar Rodas wrote: > #define uchar unsigned char * suggests it's a char but is in fact a pointer to a char so the signature o

Re: [sqlite] BLOB question

2007-02-23 Thread Cesar Rodas
I found the answer!! http://www.sqlite.org/cvstrac/wiki?p=BlobExample thanks for you help too Wesley On 23/02/07, Cesar Rodas <[EMAIL PROTECTED]> wrote: #define E_IO_COULDNT_OPEN - 1 #define E_IO_ERRO -2 #define uchar unsigned char * int LoadFileContent(uchar *path, uchar ** value, long * len

Re: [sqlite] BLOB question

2007-02-23 Thread Martin Jenkins
Cesar Rodas wrote: > #define uchar unsigned char * suggests it's a char but is in fact a pointer to a char so the signature of LoadFileContent is actually int LoadFileContent(unsigned char **path, unsigned char ***value, ... and that triggers my "three levels of indirection is usually an err

Re: [sqlite] BLOB question

2007-02-23 Thread Wesley W. Terpstra
A couple of comments. On Feb 23, 2007, at 3:03 PM, Cesar Rodas wrote: while ( (n=fread(buff,Buffsize,1,file)) > 0) { if (i>0) *value = realloc(*value, (i+1) * Buffsize); memcpy(*value + (i * Buffsize), buff, Buffsize); *len += n; i++; } You are

Re: [sqlite] BLOB question

2007-02-23 Thread Cesar Rodas
#define E_IO_COULDNT_OPEN - 1 #define E_IO_ERRO -2 #define uchar unsigned char * int LoadFileContent(uchar *path, uchar ** value, long * len) { #define Buffsize 1024*4 int n; long i=0; FILE *file; unsigned char buff[Buffsize]; if ( (file=fopen(path,"rb"))==0) { retur

[sqlite] BLOB question

2007-02-23 Thread Cesar Rodas
Does any one has a C code to save a binary file into a blob, and wants to share? Because i am getting an "segmentation fault" error from a file that I load into memory then I generate the query with a sqlite3_mprintf.. Thanks to all -- Cesar Rodas http://www.sf.net/projects/pagerank (The PageRan