Re: SQLITE Blob writing error

Discussion in 'C Programming' started by Ben Bacarisse, Nov 17, 2008.

  1. "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.
     
    Ben Bacarisse, Nov 17, 2008
    #1
    1. Advertising

  2. On 17 Nov, 16:06, Ben Bacarisse <> 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...
     
    Nick Keighley, Nov 18, 2008
    #2
    1. Advertising

  3. Nick Keighley <> writes:

    > On 17 Nov, 16:06, Ben Bacarisse <> 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.
     
    Ben Bacarisse, Nov 18, 2008
    #3
  4. "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.
     
    Ben Bacarisse, Nov 18, 2008
    #4
  5. Ben Bacarisse

    James Kuyper Guest

    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.
     
    James Kuyper, Nov 18, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maury

    Writing a BLOB by UPDATE

    Maury, Jul 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,498
    =?Utf-8?B?RWx0b24gVw==?=
    Jul 8, 2005
  2. Fred

    Re: SQLITE Blob writing error

    Fred, Nov 14, 2008, in forum: C Programming
    Replies:
    3
    Views:
    313
    Ben Bacarisse
    Nov 14, 2008
  3. Nick Keighley

    Re: SQLITE Blob writing error

    Nick Keighley, Nov 17, 2008, in forum: C Programming
    Replies:
    1
    Views:
    367
    Nick Keighley
    Nov 17, 2008
  4. Carl Youngblood
    Replies:
    1
    Views:
    230
    Carl Youngblood
    Apr 9, 2005
  5. Replies:
    4
    Views:
    350
Loading...

Share This Page