Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: SQLITE Blob writing error

Reply
Thread Tools

Re: SQLITE Blob writing error

 
 
Ben Bacarisse
Guest
Posts: n/a
 
      11-17-2008
"wizard" <> writes:

> Thanks for all replies.
> Sorry I forgot what I'm exactly going to do.
> My case is very simple for You (So I mean)
> Now I'm clearing detaily.
> I would like to write/read geometry of simple 2D objects (shapes but with
> holes) to Sqlite blob field.
> I delivered a little test snippet - what I,m doing wrong.
>
> Maybe my data structure as below is wrong
> typedef struct points
> {
> long numPoints;
> double *x;
> }Points;
>
> Maybe somebody could give some correct piece of code.


There is a standard C part to this question. A "blob" is common term
used to refer to a chuck of uninterpreted data. This means that the
struct you have looks inappropriate; it requires a count and a pointer
to a separate array that contains the data. Now you can do some
tricks to make this into a single, contiguous block of memory but it
is simpler to array in the structure.

If you can something close to a C99 compiler, the language a mechanism
for this purpose: you leave the size empty in the declaration and
allocate the extra space using malloc:

struct points {
long int num;
double data[];
};

struct points blob_ptr;
blob_ptr = malloc(sizeof *blob_ptr + 2 * N * sizeof *blob_ptr->data);

(I multiplied by 2 because I assume you need 2 doubles for each
point.)

If you can't use the device, you should search for the "struck hack".
In older C you need to have an array of size 1, and adjust things
accordingly.

--
Ben.
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      11-18-2008
On 17 Nov, 16:06, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:

> If you can't use the device, you should search for the "struck hack".
> In older C you need to have an array of size 1, and adjust things
> accordingly.


that's "struct hack".
I don't normally correct typos, but that *was* a search string...
 
Reply With Quote
 
 
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      11-18-2008
Nick Keighley <> writes:

> On 17 Nov, 16:06, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>
>> If you can't use the device, you should search for the "struck hack".
>> In older C you need to have an array of size 1, and adjust things
>> accordingly.

>
> that's "struct hack".
> I don't normally correct typos, but that *was* a search string...


Absolutely. That's the last place there should be one. Ta.

--
Ben.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      11-18-2008
"wizard" <> writes:

> Uzytkownik "Ben Bacarisse" <> napisal w wiadomosci
> news:...
>> "wizard" <> writes:

<snip>
>>> I would like to write/read geometry of simple 2D objects (shapes but with
>>> holes) to Sqlite blob field.
>>> I delivered a little test snippet - what I,m doing wrong.
>>>
>>> Maybe my data structure as below is wrong
>>> typedef struct points
>>> {
>>> long numPoints;
>>> double *x;
>>> }Points;

<snip>
>> struct points {
>> long int num;
>> double data[];
>> };
>>
>> struct points blob_ptr;
>> blob_ptr = malloc(sizeof *blob_ptr + 2 * N * sizeof *blob_ptr->data);
>>
>> (I multiplied by 2 because I assume you need 2 doubles for each
>> point.)
>>
>> If you can't use the device, you should search for the "struck hack".
>> In older C you need to have an array of size 1, and adjust things
>> accordingly.
>>
>> --
>> Ben.


Best not to quote sig blocks even though mine is short. In fact it is
best to cut out the parts that you are not commenting on but leaving
enough for context.

<snip>
> But how a can declare a string to store diffrent lenght strings (e.g
> "100/15", "1", "1111155668989" etc.)
> not to loose memory (not static text) I tried as above but a can't compile
> (under VC 6.0)
> - variable text
>
> struct points {
> long int num;
> double data[];
> char text[];
> };


In VC I don't you can use the [] syntax (I know little about VC but it
is a C99 construct and VC is C90). Even if you could, you can't have
more than one such array in a struct and it has to be the last member.
It is probably better to re-think how you are string the data in this
database. DBs are good at storing text, so I don't see why you've now
added a char array to your "blob".

--
Ben.
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      11-18-2008
wizard wrote:
....
> struct points {
> long int num;
> double data[];
> char text[];
> };


A struct can only have one flexible array member, and that member must
be the last member of the struct.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruby sqlite/gem error: Could not load sqlite adapter jhs408@gmail.com Ruby 4 04-18-2009 12:53 AM
Re: SQLITE Blob writing error Nick Keighley C Programming 1 11-17-2008 09:00 AM
Re: SQLITE Blob writing error Fred C Programming 3 11-14-2008 11:16 PM
Writing a BLOB by UPDATE Maury ASP .Net 1 07-08-2005 12:55 PM
Installing sqlite-ruby when sqlite is in non-standard location Carl Youngblood Ruby 1 04-09-2005 03:32 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57