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

'VARCHAR' is not a supported type

Quote Reply
'VARCHAR' is not a supported type
This probably belongs with my other post titled "How to "Include" a .def file",
but I didn't want it to look like I have gotten a reply to that question, cause I haven't (yet) <g>

When supplying a hash of hashes to $creator->cols (\%HoH);, I get the following error:
GT::SQL::Creator (24307): 'VARCHAR' is not a supported type at GT::SQL::Driver::column_sql line 537.

Why the error on VARCHAR?

The file I am trying to #include and feed to $creator->cols object is basically a def file formatted like this:
Code:
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 => '' }

Then in my plugin ZipCodeSearch.pm file I have:
Code:
my $error;
my %HoH = ();
my (@def,$lastchar, @pairs, $pairs, $pairname, $pairvalue, $key, $value);
my $zipcode_table_name = 'ZipCodes';
my $creator = $DB->creator ($zipcode_table_name);

my $formatname = $CFG->{admin_root_path} ."/Plugins/ZipCodeData/". $IN->param('data_format_file');
open (DEF, "$formatname") || return $GT::SQL::error;
@def = <DEF>;
close DEF;

foreach (@def) {
$_ =~ s/\n//g; # Remove newline ?
$_ =~ s/\t//g; # Remove tabs ?
$_ =~ s/ //g; # Remove spaces ?

$lastchar = substr ($_, (length $_) - 1, 1);
if($lastchar eq ',') {
$_ = substr($_, 0, -1);
}

$_ =~ s/=>/\|/; # ZipCode | { pos => 1, type => 'VARCHAR', size => '5', not_null => 1, default => ''}
$_ =~ s/{//; # ZipCode | pos => 1, type => 'VARCHAR', size => '5', not_null => 1, default => ''}
$_ =~ s/}//; # ZipCode | pos => 1, type => 'VARCHAR', size => '5', not_null => 1, default => ''

@pairs = split /\|/, $_;
$pairname = $pairs[0]; # ZipCode
$pairvalue = $pairs[1]; # pos => 1, type => 'VARCHAR', size => '5', not_null => 1, default => ''

for $pairvalue ( split /,/, $pairvalue) {
($key, $value) = split /\=>/, $pairvalue;
$HoH{$pairname}{$key} = $value;
print "Column/key = value: $pairname/$key = $value<br>";
}
}

$creator->cols (\%HoH);
$creator->pk('ZipCode','Latitude','Longitude');

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)");
}

$creator->load_table();

$creator->save_schema();

I could really use some help with this. I swear I am passing a "hash of hashes" to the creator->cols object.
I have spent days doing this, and all I am trying to do is read in a file and create a table from it. Unsure
My perl is getting better. I am a complete rookie. I think I got hashes understood though.

FYI, I tried just feeding the file directly to creator->cols(), but was getting other errors such as:
$creator->cols (%{$def}); # Can't use string when strict refs in use
$creator->cols (%{%def}); # wrong arg, must be a hash of hashes
$creator->cols (%{@def}); # Can't coerce array into hash

Thanks for any help,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Subject Author Views Date
Thread 'VARCHAR' is not a supported type rgbworld 2191 May 21, 2006, 3:42 PM
Thread Re: [rgbworld] 'VARCHAR' is not a supported type
rgbworld 2117 May 21, 2006, 9:17 PM
Post Re: [rgbworld] 'VARCHAR' is not a supported type
rgbworld 2101 May 23, 2006, 1:21 AM