ddb Database tool

table of contents

about this document

operators

copy

This is the default operation. It just copies the data from the input to the output. This is usually used to translate between database formats.

join

This operator takes a many to many relationship and translates it to a one to many database.

For example:

a 1
a 2
a 3
b 4
b 5
would translate to:
a 1 2 3
b 4 5

split

This is the reverse of join. It takes a database with a unique key and one or more values and translates it into a single key/value pair for each of the values.

diff

The diff operator only works if there is a unique key. Otherwise, it has no basis for comparison. If this cramps your style, perhaps you wish to do a diffc on the product of two joins.

The output of diff is a series of key/value sets describing the difference between the i database and the c database with the removes and adds designated by '<' and '>' respectively, and the data position amonst the delimiters corresponding to the actual position of the changed data. For example, the given i:

a 1 2 3
b 4 5 6
and c:
a 3 2 1
b 4 5 7
the result would be o:
< a 1  3
> a 3  1
< b   6
> b   7
.

diffc

This is the same as diff except it ignores the position of the value and the removes and adds are designated by '{' and '}' respectively. Therefor:

a 1 2 3
is the same as
a 3 2 1
and given i:
a 1 2 3
b 4 5 6
and c:
a 3 2 1
b 4 5 7
the result would be o:
} b   6
{ b   7
.

patch

This reads diffs and diffcs and applies them to the input database.

examples

ddb converts/compares data from/to gdbm, SQL (through a DBI interface), and flat text file. Here is an example usage that creates and plays with a gdbm file with the keys (a,b,c):

example 1: stdin > gdbm file with ':' separated values

./ddb.pl ofg=a.gdbm odelim=':' idelim=' '
a 1 2 3
b 4 5 6
c 7 8 9
^D

example 2: show gdbm keys and values

./ddb.pl ifg=a.gdbm idelim=' ' odelim=' '
b 4:5:6
a 1:2:3
c 7:8:9
^D

example 3: compare against slightly different DB

./ddb.pl idelim=' ' cfg=a.gdbm cdelim=':' op=diff odelim=' '
a 3 2 1
b 4 5 6
c 7 8 0
^D
< a 3  1
> a 1  3
< c   0
> c   9

example 4: compare again not caring about value positions

./ddb.pl idelim=' ' cfg=a.gdbm cdelim=':' op=diffc odelim=' '
a 3 2 1
b 4 5 6
c 7 8 0
^D
{ c 0
} c 9

remaining issues