Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS import: othersrc/external/bsd/sqlite3db



Module Name:    othersrc
Committed By:   agc
Date:           Thu Nov 26 19:22:46 UTC 2015

Update of /cvsroot/othersrc/external/bsd/sqlite3db
In directory ivanova.netbsd.org:/tmp/cvs-serv25415

Log Message:
Import sqlite3db into othersrc.

        sqlite3db is a small library and helper program which provides
        a Berkeley-db 1.85/1.86 style API for sqlite3 databases.

        The helper program also provides a conversion facility to change
        bdb databases to sqlite3 ones. This works for hash and btree
        databases. It's also interesting to note that btree databases
        are a lot smaller in sqlite3 than bdb:

                % ls -al *big*
                -rw-r--r--  1 agc  users  11386880 Nov 25 19:43 bigbtree.db
                -rw-r--r--  1 agc  users   5033984 Nov 25 19:44 sql3bigbtree.db
                % file *big*
                bigbtree.db:     Berkeley DB 1.85/1.86 (Btree, version 3, little-endian)
                sql3bigbtree.db: SQLite 3.x database
                %

        I haven't looked at the sizings of hash databases.

        There's one real function in this library, which mirrors the bdb
        dbopen(3):

                DB *sqlite3db_dbopen(const char */*file*/, int /*flags*/,
                        mode_t /*mode*/, DBTYPE /*type*/, const void */*openinfo*/);

        and access to the database is by the "methods" in the DB struct. For example,
        to dump the database to stdout (a bit like db(1)):

                /* dump the contents of the database */
                static int
                dump(const char *f, DBTYPE type)
                {
                        DBT      value;
                        DBT      key;
                        DB      *db;

                        db = sqlite3db_dbopen(f, O_RDONLY, 0666, type, NULL);
                        if (db == NULL) {
                                warn("dump: can't open database '%s'", f);
                                return 0;
                        }
                        while ((*db->seq)(db, &key, &value, R_NEXT) == 0) {
                                printf("%.*s\t%.*s\n",
                                        (int)key.size, (char *)key.data,
                                        (int)value.size, (char *)value.data);
                        }
                        (*db->close)(db);
                        return 1;
                }

        There's also one function which converts from a bdb database to an sqlite3 one:

                int sqlite3db_convert(const char */*oldf*/, const char */*newf*/,
                        DBTYPE /*type*/);

        and conversion is fairly simple:

                /* convert a bdb database to an sqlite3 one */
                static int
                convert(const char *f, DBTYPE type)
                {
                        const char      *slash;
                        char             newname[512];

                        if (f == NULL) {
                                warnx("convert: no file given");
                                return 0;
                        }
                        if ((slash = strrchr(f, '/')) == NULL) {
                                slash = f;
                        } else {
                                slash += 1;
                        }
                        snprintf(newname, sizeof(newname), "sql3%s", slash);
                        return (sqlite3db_convert(f, newname, type) == 0);
                }

        sqlite3 only provides btree databases, so when databases are
        converted, a bdb hash database becomes an sqlite3 btree database.  I
        haven't provided a conversion function to move in the opposite
        direction, from sqlite3 to bdb :)

        Alistair Crooks
        Thu Nov 26 10:51:01 PST 2015

Status:

Vendor Tag:     CROOKS
Release Tags:   sqlite3db-base
                
N othersrc/external/bsd/sqlite3db/Makefile
N othersrc/external/bsd/sqlite3db/bin/pkgdb.byfile.db
N othersrc/external/bsd/sqlite3db/bin/2.expected
N othersrc/external/bsd/sqlite3db/bin/1.in
N othersrc/external/bsd/sqlite3db/bin/4.expected
N othersrc/external/bsd/sqlite3db/bin/5.expected
N othersrc/external/bsd/sqlite3db/bin/Makefile
N othersrc/external/bsd/sqlite3db/lib/shlib_version
N othersrc/external/bsd/sqlite3db/lib/Makefile
N othersrc/external/bsd/sqlite3db/dist/README
N othersrc/external/bsd/sqlite3db/dist/libsqlite3db.3
N othersrc/external/bsd/sqlite3db/dist/Makefile
N othersrc/external/bsd/sqlite3db/dist/main.c
N othersrc/external/bsd/sqlite3db/dist/sqlite3db.c
N othersrc/external/bsd/sqlite3db/dist/sqlite3db.h
N othersrc/external/bsd/sqlite3db/dist/sqlite3db.1

No conflicts created by this import




Home | Main Index | Thread Index | Old Index