Notes

postgres

It builds just fine:

imac:~/postgresql/bin root# file initdb postgres   
initdb:   Mach-O executable acorn
postgres: Mach-O executable acorn


However, needs IPC shmem, not in kernel:

imac:~ root# sysctl -a | grep shmmax
kern.sysv.shmmax: 4194304

not found on iphone, so this fails:

# ./bin/initdb -d -D /var/root/postgresql/data

DEBUG:  invoking IpcMemoryCreate(size=1138688)
child process was terminated by signal 12
initdb: removing data directory "/var/root/postgresql/data"


hacked code initdb to remove auto detection, still no dice, no go for me on pgsql (sorry)


MySQL

Ported over, seems to work fine so far, install howto, can run this all directly on the iphone:

# pwd
/var/root

# wget http://wickedpsyched.net/iphone/databases/mysql.tgz

# tar zxf mysql.tgz

# cd mysql/bin 

# ./mysql_install_db 
[snip]
Installing MySQL system tables...
OK
Filling help tables...
OK

Now start the daemon (you should really make a local mysql user but --user will work for now):

# ./mysqld_safe --user=root &
[1] 284
# Starting mysqld daemon with databases from /var/root/mysql//var


# ./mysql mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.45 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select host from user where host like '%iPhone%';
+--------+
| host   |
+--------+
| iPhone | 
+--------+
1 row in set (0.02 sec)

Tada!








Berkeley DB

Make a database:

# awk -F: '{print $1; print $0}' < /etc/passwd | sed 's/\\/\\\\/g' | ./db_load -T -t hash passwd.db

Check the vital statistics:

# ./db_stat -d passwd.db                                                                         
Sun Sep  9 14:56:52 2007        Local time
61561   Hash magic number
8       Hash version number
Little-endian   Byte order
        Flags
4096    Underlying database page size
0       Specified fill factor
11      Number of keys in the database
11      Number of data items in the database
2       Number of hash buckets
7242    Number of bytes free on bucket pages (11% ff)
0       Number of overflow pages
0       Number of bytes free in overflow pages (0% ff)
0       Number of bucket overflow pages
0       Number of bytes free in bucket overflow pages (0% ff)
0       Number of duplicate pages
0       Number of bytes free in duplicate pages (0% ff)
0       Number of pages on the free list


Test data:

# ./db_dump -d h passwd.db                                                                        
In-memory DB structure:
hash: 0x90000 (open called, read-only)
meta_pgno: 0
h_ffactor: 0
h_nelem: 11
h_hash: 0xcef08
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
page 0: hash metadata: LSN [0][1]: level 0
        magic: 0x61561
        version: 8
        pagesize: 4096
        type: 8
        keys: 11        records: 11
        free list: 0
        last_pgno: 2
        flags: 0
        uid: f6 20 0 0 2 0 0 e e0 51 e3 77 8c 0 0 0 0 0 0 0
        max_bucket: 1
        high_mask: 0x1
        low_mask:  0
        ffactor: 0
        nelem: 11
        h_charkey: 0x5e688dd1
        spare points: 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
page 1: hash: LSN [0][1]: level 0
        prev:    0 next:    0 entries:   16 offset: 3413
page 2: hash: LSN [0][1]: level 0
        prev:    0 next:    0 entries:    6 offset: 3925