Computer \Com*put"er\ (k[o^]m*p[=u]t"[~e]r), n.
1. One who computes.
| Name | Last modified | Size | Description | |
|---|---|---|---|---|
| Parent Directory | - | |||
| Template.xs | 21-Apr-2008 17:30 | 1.6K | ||
| mkobj | 21-Apr-2008 16:09 | 13K | ||
| vpbs-db-template.c | 21-Apr-2008 17:30 | 5.6K | ||
| vpbs-db-template.h | 21-Apr-2008 17:30 | 2.3K | ||
The mkobj script is what I use to generate code from a simple description of the database layout, and it uses a few templates.
The script should be called with one argument: the name of the master template. The format of this file is:
MASTER_TEMPLATE::= TABLE [ TABLE ... ] TABLE::= table name "|" FIELD_DESCRIPTIONS "|" [ N_LINKS ] "|" [ M_N_LINKS ] "|" [ EXTRA_FILE ] "\n" FIELD_DESCRIPTIONS::= FIELD_DESCRIPTION [ "," FIELD_DESCRIPTION ... ] FIELD_DESCRIPTION::= field name ":" DATA_TYPE [ "n" ] DATA_TYPE::= "s" | "f" | "i" | "b" N_LINKS::= N_LINK [ "," N_LINK ... ] N_LINK::= linked table name M_N_LINKS::= M_N_LINK [ "," M_N_LINK ... ] M_N_LINK::= linked table name ":" auxiliary table name
The data types can be "s" (for string), "f" (for foreign keys), "i" (for integers), or "b" (for booleans). Other data types are not currently supported by mkobj; I suggest you use the "s" data type instead. Using 'f' will generate a function like "invoice_get_customer" which will return the customer object for whom this invoice is. If you append the "n", it is assumed that this field may be NULL.
The N_LINK field is for the other end of foreign keys, and will generate a function like "customer_get_invoices" which will return an array containing all invoice objects related to this customer.
The M_N_LINK field is for M:N links. The auxiliary table should contain exactly two fields: one with the name of this table, one with the name of the table we're linking to. Both should be foreign keys. It will not be possible to create an object from the auxiliary table, but this will generate a function like "student_get_courses" (and if you add the reverse definition on the "course" table, it will also generate a function like "course_get_students").
Finally, the EXTRA_FILE can contain a filename in which to add extra functions. The format of this file is:
/* public header additions */ -------- /* public API declarations */ hhhhhhhh /* private header additions */ cccccccc /* private C code */ xhxhxhxh /* XS header additions */ xxxxxxxx /* XS code */
The "public header additions" will be added to prefix-table.h, right after the #include lines. The "public API declarations" is meant to add forward declarations of your custom functions. The "private header additions" is added to prefix-table.c, right after the #include lines. The "private C code" is meant to add the implementation of your custom functions. The "XS header additions" get added to the XS file, right after the #include lines; and finally, the "XS" code is meant for your custom XS code (probably to add perl linkage for your custom functions).
You will also need the Template.xs, vpbs-db-template.h, and vpbs-db-template.c files in order to generate any code.