DatabaseAuto
Automatically register existing database tables.
Synopsis
|
DatabaseAuto DSN username password [catalog [schema [name [type]]]]
|
Scope
This directive is only available for use in the local
(catalog.cfg) configuration file.
It will not affect any other website in any way.
This directive will not work in the global
(interchange.cfg) configuration file.
Description
This directive automatically registers all of the tables found in
the specified DSN.
This only works for SQL databases.
The parameters provided to this directive are used to establish the
connection to the database.
For example, a setting of:
|
DatabaseAuto dbi:mysql:database_name username password
|
would generate the equivalent of one of the following blocks
for every table in the "database_name" database:
NoImport table_name
Database table_name tablename.txt dbi:mysql:database_name
Database table_name USER username
Database table_name PASS password
|
|
Note
Views are not automatically registered by default (see below).
|
Any additional space-separated arguments are passed to DBI's
"table_info()" subroutine as the "catalog",
"schema", "name" and "type".
Quotes are only required if the values contain whitespace
or need to be left blank (specified as "").
The "catalog" parameter is not currently used by any of the DBD
drivers, but it may be in the future.
The "schema", "name" and "type" parameters
are database-specific.
See the Perl DBI and DBD module manual pages for details on these parameters.
If the
DBIx::DBSchema
Perl module is found,
then the SQL that would be required to re-create each table will be
stored in the appropriate Database directive's
CREATE_SQL attribute.
If you need to see the SQL, for whatever reason,
then you could put something like this on a page:
<pre>
[calcn]
my $buf = '';
foreach (values(%{$Config->{Database}})) {
$buf .= "$_->{CREATE_SQL}\n\n" if length($_->{CREATE_SQL});
}
return $buf;
[/calcn]
</pre>
|
PostgreSQL users can restrict the table auto-registration to a specific
schema, perhaps the "public" schema, by using
the following parameters:
|
DatabaseAuto dbi:Pg:dbname=database_name username password "" schema_name
|
|
Note
The "schema" parameter helps avoid the use of the
DatabaseAutoIgnore directive,
which can easily ignore more tables than expected.
|
You can switch on view recognition by setting the "type" parameter to "VIEW" (capital letters are required), as follows:
|
DatabaseAuto dbi:Pg:dbname=database_name username password "" schema_name "" VIEW
|
|
Warning
It is possible to make some confusing configuration mistakes here -
especially when using PostgreSQL.
For instance, the specified schema may not be in the database
user's SEARCH_PATH session variable,
or the SEARCH_PATH might contain other schemas that have
tables with the names you are expecting to see.
|
See also