Hi, I got the code below, but I would like to check if an entry is already in the table and if not insert and if it is update it.

--CODE--


use strict;
use warnings;
use DBI;
use DBD::AnyData;

my $table = "data";

my @fields = qw/ id name /;
my %field_def = (
id => 'char(20)',
name => 'char(20)',
);

my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):')
or die "Can not create database connection";

# build the create table SQL on the fly
$dbh->do (
"CREATE TABLE $table (" .
join(',', map { $_ . ' ' . $field_def{$_} } @fields) .
")" )
or die "Can not create table";

$dbh->do("INSERT INTO $table VALUES ('01', 'FOO' )");


unlink './data.csv'; # delete existing csv file if any
$dbh->func( 'data', 'CSV', './data.csv', 'ad_export');

$dbh->disconnect();

--END CODE--

I've tried loads of different ways I've seen on websites, but none seen to work. I think its something to do with the "INSERT INTO" but, but I can't work it out.

I would also like to know if it is passable to make it so I can have unlimited letters it the fields?

Thanks for your help.