On 09/10/2007, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I got an error when I try to read some data outside the while{}, inside the 
> while{} it's ok, an idea ?
> test.db have just one "table1" and a "field1" with values "one", "two", 
> "three".
.
.
.
>    const unsigned char *my_array[3];
.
>    while(sqlite3_step(pStat) == SQLITE_ROW)
>    {
>        my_array[i] = sqlite3_column_text(pStat, 0);
>        printf ("%s\n",my_array[i]); // ok
>
>        i++;
>    }
>
>    for (i = 0; i<3; i++);{
>        printf ("%s\n", my_array[i]); // error
>    }
>

Hi Fred,

sqlite3_column_text is returning a pointer to a text string stored
within sqlite's private address space. If you want to access that data
after calling sqlite_step() again, then copy the data to some storage
of your own.

i.e
    unsigned char* my_array[3];

    while(sqlite3_step(pStat) == SQLITE_ROW)
    {
        my_array[i] = malloc( sqlite3_column_bytes(pStat, 0) );
        memcpy( my_array[i], sqlite3_column_text(pStat, 0));
        printf ("%s\n",my_array[i]);
        i++;
    }

    for (i = 0; i<3; i++);{
        printf ("%s\n", my_array[i]);
        free( my_array[i] );
    }

(or something like this - have not tested this code...)

Rgds,
Simon

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

Reply via email to