My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

SPAWK is an elegant collection of functions for accessing and manipulating MySQL databases from within awk programs. SPAWK is based on MySQL's C API and awk's sources. It's all about a dozen of functions grouped into a GNU awk (gawk) "extension" library. The following example shows how to use SPAWK for printing all tables and columns of all schemas in your MySQL database:

BEGIN {
    extension("libspawk.so", "dlload")
    SPAWKINFO["database"] = "information_schema"
    SPAWKINFO["OFS"] = "."
    spawk_query("SELECT TABLE_SCHEMA, TABLE_NAME FROM TABLES")
    spawk_select()
    while (spawk_data(table)) {
        print table[0]
        spawk_query("SELECT COLUMN_NAME FROM COLUMNS " \
            "WHERE TABLE_SCHEMA = '" table[1] \
            "' AND TABLE_NAME = '" table[2] "'")
            spawk_select()
            while (spawk_data(column))
                print "\t" column[1]
    }

    exit(0)
}
Powered by Google Project Hosting