Re: CDBI and Sybase quirks
[prev]
[thread]
[next]
[Date index for 2004/07/28]
> Trouble is that Class::DBI wants to write to primary key
> fields, so we need to prohibit that. Easily done:
>
> MSDW::MDP::Db::Release->flag_column(IDENTITY => qw/release_id/);
Interesting. Why don't you just use a column group though?
> sub _auto_increment_value {
> my $self = shift;
> my $dbh = $self->db_Main;
> my @primary_columns = $self->primary_columns;
>
> #The sybase way
> my $id;
> eval {
> #Can't use placeholders (not conditions)
> my $sth = $dbh->prepare("select MAX( $primary_columns[0] ) from " .
> $self->table);
> $sth->execute();
> $id = ($sth->fetchrow_array)[0];
> };
> $self->_croak("Can't get last insert id") unless defined $id;
> return $id;
> }
This will fail when AutoCommit is on. It's also not a very Sybase-like
implementation; "select @@identity" is the Sybase way. Anyway, I would
probably try to use the DBI's last_insert_id() method if possible. The
DBD::Sybase implementation of last_insert_id() has some caveats though, so
read the following documentation:
http://search.cpan.org/~mewp/DBD-Sybase-1.04/Sybase.pm#Behavior_of_$dbh-%3Elast_insert_id
> So this now works. Next issue is text fields. They cannot be used in
> placeholders ('?') with DBD::Sybase. So we override _insert_row and
> update :
I've encountered this problem with text fields and placeholders myself.
Fortunately for me, I was able to change the text fields to large varchar()
fields, but that's not feasible in a lot of cases, I'm sure.
Again, I would just use a column group to specify the text fields, instead of
this flag_column() method, but, otherwise, this looks rather useful and
something like it should be considered for inclusion in Class::DBI::Sybase, I
think. Have you contacted the author of Class::DBI::Sybase?
Best wishes,
Ed
|
|
Re: CDBI and Sybase quirks
Edward J. Sabol 06:38 on 28 Jul 2004
|