Matthew Wickline wrote:
>
> > The AnyData modules support tables that have a
> > single key column that uniquely identifies each
> > row as well as tables that do not have such keys.
>
> How does one insert a row into a tied-hash $table which has no key column?
Answer 1: use the DBI interface instead :-)
Answer 2: or stick with the tiedhash interface and ...
All tables have *hash* keys (defaults to the first column) even if they
don't have *table* keys, the hash keys just don't necessarily uniquely
identify a single row. Basically if you have a hash with a scalar key
on the left of an equal sign, it does an insert and if you have a hash
with a hashref key on the left of an equal sign it does an update.
So, given a table
col1 | col2 | col3
a | b | c
$t->{a} = {col2=>'d',col3=>'e'} does an insert, producing:
col1 | col2 | col3
a | b | c
a | d | e
But if, instead you did $t->{{col1=>'a'}} = {col2=>'d',col3=>'e'} that
would have done an update,, producing:
col1 | col2 | col3
a | d | e
Assuming you did the insert and you now want to update the first row, a
single column doesn't uniquely identify it, so you need to identify it
with two columns:
$t->{{col1=>'a',col2=>'b'}} = {col2=>'foo',col3=>'bar'};
Which would produce:
col1 | col2 | col3
a | foo | bar
a | d | e
If you want to update all rows with the first column equal to 'a', you
would use
$t->{{col1=>'a'}} = {col3=>'baz'};
Which would mofify the table above to:
col1 | col2 | col3
a | foo | baz
a | d | baz
Clear as mud?
--
Jeff