Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite data file on Linux and OS X incompatible?

I create a table and fill it by executing the following on an ARM Linux machine

~ # sqlite3 /mnt/mmc/test.db
SQLite version 3.6.12
sqlite> create table a (d);
sqlite> insert into a values (1.5);
sqlite> select * from a;
1.5

I then transfer the file to my Mac and execute the following

themac:~ me$ sqlite3 test.db 
SQLite version 3.6.12
sqlite> select * from a;
5.30239915051991e-315

Whaaat? I thought the data file was platform independent.

like image 693
Johnny Avatar asked Sep 08 '25 17:09

Johnny


1 Answers

I have no particular knowledge of SQLite, but this is indicative of a problem where two 32-bit words of a 64-bit IEEE 754 format double are swapped over, as you can see in this example (which was run using gcc on an x86 machine):

$ cat test.c
#include <stdio.h>

int main(void)
{
    union {
        double d;
        unsigned long long ull;
    } u;

    u.d = 1.5;
    printf("%016llx\n", u.ull);

    u.d = 5.30239915051991e-315;
    printf("%016llx\n", u.ull);

    return 0;
}
$ gcc -Wall -o test test.c
$ ./test
3ff8000000000000
000000003ff80000
$ 
like image 176
Matthew Slattery Avatar answered Sep 11 '25 16:09

Matthew Slattery