Clark:
I ended up using the brute fore approach you suggested with a small
variation.
Thank you for your feedback.
############################################# PERL
###############################
# note: @cleanenv = (fld-1 .... fld-n);
eval
{
local $dbh -> {PrintError} = 0;
$dbh -> do("DROP TABLE cleanenv");
};
# build CREATE Table statement #
$cleanenv_sql = '$dbh->do(q{ CREATE TABLE cleanenv ';
$cleanenv_sql .= '(id INTEGER PRIMARY KEY,';
foreach $item (@cleanenv_fields)
{
$cleanenv_sql .= "$item TEXT,";
}
$cleanenv_sql = substr($cleanenv_sql,0,length($cleanenv_sql)-1);
$cleanenv_sql = $cleanenv_sql . ')}) or die $dbh->errstr;';
# print "stm=$cleanenv_sql\n";
eval $cleanenv_sql; # execute CREATE Table statement #
print "$scriptname ERROR during EVAL=$cleanenv_sql: [EMAIL PROTECTED]" if
($@);
############################################# END
################################
Regards,
Uriel_Carrasquilla
Clark Christensen
<[EMAIL PROTECTED] To:
[email protected]
om> cc:
Subject: Re: [sqlite] CREATE
TABLE $table_name (\%HASH)
02/02/2005 05:03
PM
Please respond to
sqlite-users
--- [EMAIL PROTECTED] wrote:
>
>
>
>
> Question:
> I have a perl %HASH that contains the column names and
> type for the TABLE I
> am trying to create.
> HOW can I achieve such a task?
> I have looked into SQL::Abastract DBIx::Simple and DBI
> without any success.
>
> Regards,
>
> Uriel_Carrasquilla
>
You might have to use the brute force method of looping
through the hash and building the SQL statement as you go.
So, assuming the hash key names represent the column names,
and the values contain the datatypes, you could do
something like:
$tableName = 'MY_TABLE';
$sqlCreate = "create table $tableName (";
foreach $i (keys %schemaHash) {
$sqlCreate .= "$i $schemaHash{$i},\n";
}
$sqlCreate .= ');';
$dbh->do($sqlCreate);
But then, you were probably trying to avoid having to do it
this way :-(
-Clark