Last active
August 29, 2015 14:26
-
-
Save perlpunk/ab26c0d56f29bf29b747 to your computer and use it in GitHub Desktop.
DBIx::Class Bug with Sybase and Identity Retrieval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
BEGIN { | |
$ENV{LANG} = "C"; | |
$ENV{DBIC_TRACE} = 1; | |
} | |
use strict; | |
use warnings; | |
use 5.010; | |
use Example; | |
use Net::Netrc; | |
my $dsn = "dbi:Sybase:server=$ENV{SERVER};database=$ENV{DB}"; | |
my $cred = Net::Netrc->lookup($ENV{SERVER}, $ENV{USER}); | |
my ($login, $password) = $cred->lpa; | |
my $schema = Example->connect($dsn, $login, $password); | |
my $deleted = $schema->resultset('Mytable')->search({ | |
})->delete; | |
my $code = sub { | |
$schema->resultset('Mytable')->create({ | |
content => "blubb", | |
}); | |
}; | |
if (1) { | |
# this one has the bug | |
# see DBIx/Class/Storage/DBI/Sybase/ASE.pm line 405 | |
# if ($self->{transaction_depth} | |
eval { | |
$schema->txn_do($code); | |
}; | |
if ($@) { | |
say "ERROR: $@"; | |
} | |
} | |
else { | |
# this one doesn't | |
eval { | |
$code->(); | |
}; | |
if ($@) { | |
say "ERROR: $@"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use utf8; | |
package Example; | |
use strict; | |
use warnings; | |
use base 'DBIx::Class::Schema'; | |
__PACKAGE__->load_namespaces(); | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use utf8; | |
package Example::Result::Mytable; | |
use base 'DBIx::Class::Core'; | |
__PACKAGE__->table("mytable"); | |
__PACKAGE__->add_columns( | |
"id", | |
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, | |
"content", | |
{ data_type => "text", is_nullable => 0 }, | |
); | |
__PACKAGE__->set_primary_key("id"); | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table mytable (id numeric(10, 0) identity, content text not null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment