[Dbix-class] Oracle AutoPK and Sequencies
Doug Scoular
dscoular at cisco.com
Thu Jun 11 07:38:11 GMT 2009
Hi All,
I've managed to get thoroughly confused with how to insert
new records in an ORACLE database using DBIC. I wonder
if anyone can help.
Say I have the following model code:
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('standards_baseline_prep');
__PACKAGE__->add_columns(
id => {
data_type => 'integer',
is_auto_increment => 1,
sequence => 'hw_stds_baseline_prep_id_seq',
},
audit_item => {
data_type => 'varchar',
size => 32,
},
.... etc ...
This allows me to create new records without having
to worry about the "id". I assume this is being obtained from
the next val in the sequence (hw_stds_baseline_prep_id_seq). Anyway,
this lets me call create without specifying the "id":
$baseline = $schema->resultset('StandardsBaselinePrep')->create({
type =>
'hardware',
audit_item =>
'model',
...
However, I've recently discovered that people sometimes
manually add records to the database without obtaining
IDs from the sequence. If this happens what is the best
way to obtain the next ID value ? My suspicion is that
my use of sequences becomes invalid.
Can I just ignore the sequence in this case...
I thought I could just select all IDs in order and add one
to the highest one and use that... is this sensible ?
Can DBIC already do this for me ?
Any thoughts much appreciated...
Cheers,
Doug
More information about the DBIx-Class
mailing list