A very efficient way to re-arrange the byte ordering is to use a free union. No function calls involved or tests.

Jakub Ladman wrote:
I think there is no need to change endianess.
Sqlite is shadowing out this and similar low level aspects.
If you need to get data from database and use it in something what needs it in other endianess, you may use something like this.

int change_endianess(unsigned char *data, int length)
{
        unsigned char *buffer;
        int i;
        buffer = malloc(length);
        for(i=0;i<length;i++)
        {
                buffer[i] = data[length - i];
        }
        memcpy(data, buffer, length);
        free(buffer);
        return length;
} For example, i have whole system with big endian, but only ferroelectric ram connected via i2c bus needs addresses in little endian, address is an 16bit number, so i must to swap the two bytes.

        *((unsigned char *)&(buffer[0])) = addr >> 8;
        *((unsigned char *)&(buffer[1])) = addr & 0xff;

If i understand it correctly, changing physical representation of data in the database conflicts with SQL and relational databases principle.

Jakub

Dne úterý 03 duben 2007 09:49 Martin Pfeifle napsal(a):

Dear all,
in an upcoming project, it is required to store all integer values as
little endian instead of big endian (don't ask why).
Nevertheless, I would like to use SQLite in that project.
What do we have to change in the sqlite library,
if we store the integers as little endian.
I came across some functions in B-tree.c and pager.c.

In B-tree.c
/* Read or write a two- and four-byte big-endian integer values.*/
get2byte,
get4byte,
put2byte,
put4byte
/* pager.c*/
** All values are stored on disk as big-endian.
*/
read32bits,
write32bits

Is that enough.
Another question, what do we have to change if we would
also store the utf-chars as little endian?
I appreciate your help.
Martin






___________________________________________________________
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail:
http://mail.yahoo.de


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



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

Reply via email to