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 = 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 the right
>> sized buffer from the outset? Much easier.
>>
>> Martin
>>
>> -----------------------------------------------------------------------------
>> To unsubscribe, send email to [EMAIL PROTECTED]
>> -----------------------------------------------------------------------------
>>
>>


In cases like this, I tend to just memory map the file and use the
memory mapped pointer for insertion into the DB. I'd use the
parameterized SQL functions though. Where you compile the SQL then
bind the blob pointers. I have an example but, it uses my wrapper and
doesn't show the actual SQLlite API.


....
        unsigned char   pMD5[MD5_DIGEST_LENGTH + 2];
        CMD5File::MD5File(pszFile,(size_t)nLength,pMD5);
        HRESULT hr = Compile("INSERT OR IGNORE INTO Data_V2"
        "("
                "Signature," 
                "File"  
        ") VALUES (?,?);");

        BindBlob(1,pMD5,MD5_DIGEST_LENGTH);
        BindBlob(2,pszFile,static_cast<uint32_t>(nLength));

        uint32_t nResults;
        hr = Step(nResults);
        if( FAILED(hr))
        {
                FreeError();
                assert(0);
                return(E_ABORT);
        }

        ResetBindings();

...



-- 
Best regards,
 Teg                            mailto:[EMAIL PROTECTED]


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to