Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

How to "Include" a .def file

Quote Reply
How to "Include" a .def file

Is it possible to #include or execute a .def file?

I have a plugin that needs to import from 1 of several differently formated CSV files.
The DATA FILE to be imported from is chosen via a dropdown menu during the plugin installation.

In order to import the data, I have to create the table first, so in addition to choosing a data file,
the installer also has a dropdown menu for DATA FORMAT that must also be selected by the User.

The idea is that the Admin installing the plugin chooses a data file AND data format, then the plugin
creates the table via DB->creator($table) and imports the matching data file into the table. Simple right?

Here's what I have, but I am getting this error:
GT::SQL::Creator (10729): You must define your table before creating it at /home/blah/ZipCodeSearch.pm line 469.

my $error;
my $zipcode_table_name = 'ZipCodes';
my $creator = $DB->creator ($zipcode_table_name);

# Include the data format file HERE. Works like a plugin system.
my $inc;
my $formatname = $CFG->{admin_root_path} ."/Plugins/ZipCodeData/". $IN->param('data_format_file');
open (INCL, "$formatname") || return $GT::SQL::error;
$inc = join ("", <INCL> );
close INCL;

# Set the primary key, auto-increment and index.
# These columns MUST be in the data_format_file included above.

if (! $creator->create('force')) {
$GT::SQL::errcode ||= ''; #silence -w warning.
$GT::SQL::errcode eq 'TBLEXISTS' ? ($error = "Could not create table ZipCodes (table already exists)\n") :
($error = "Could not create table ZipCodes: $GT::SQL::error)");


The DATA FORMAT file to be included is simply a list of columns

$creator->cols ( {
ZipCode => { pos => 1, type => 'VARCHAR', size => '5', not_null => 1, default => ''},
City => { pos => 2, type => 'VARCHAR', size => '35', not_null => 0, default => ''},
State => { pos => 3, type => 'CHAR', size => '2', not_null => 0, default => '' },
Latitude => { pos => 4, type => 'DOUBLE', not_null => 1, default => '0'},
Longitude => { pos => 5, type => 'DOUBLE', not_null => 1, default => '0' },
TimeZone => { pos => 6, type => 'CHAR', size => '3', not_null => 0, default => '' },
DST => { pos => 7, type => 'CHAR', size => '1', not_null => 0, default => '' }

The reason for doing all this, is so that when someone purchases a Zip Code data file
from who-knows-where in some unknown-to-me file format, they can simply ftp the
data file to a directory on their server, then choose it via a dropdown menu in installer.

I plan to include several data FORMAT files with the plugin. I can create these for the
most popular (paid) Zip Code data formats available on the internet. If there is a format
that I haven't included, a data FORMAT file can easily be created by te User and ftp'd
to the server along with the CSV data file and whola!

So, how do I accomplish the inclusion of different table schema?

RGB World, Inc. - Software &amp; Web Development.
Quote Reply
Re: [rgbworld] How to "Include" a .def file In reply to

PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.