gpt4 book ai didi

perl - DBIx::Class 可以与存储过程而不是表一起使用吗?

转载 作者:行者123 更新时间:2023-12-04 20:20:09 25 4
gpt4 key购买 nike

从数据库读取的访问权限已通过返回结果集而不是表或 View 的 mssql 存储过程授予我。但我希望能够使用 ORM 读取数据。

我尝试使用 DBIx::Class::ResultSource::View将过程调用(例如 EXEC my_stored_proc ? )作为自定义查询进行,但这不起作用,因为它试图将过程调用转换为 select 语句。

有人有其他建议吗?

最佳答案

不,没有合理的方法可以在 DBIx::Class 的上下文中执行存储过程。

据我所知,最接近解决方法的是“使用 ORM”来获取数据库句柄,这是弱汤:

   my @results = $schema->storage->dbh_do(sub{
my ($storage, $dbh, @args) = @_;
my $sth = $dbh->prepare('call storedProcNameFooBar()');
my @data;
$sth->execute();
while( my $row = $sth->fetchrow_hashref){
push @data, $row;
}
return @data;
},());

[详情见
http://metacpan.org/pod/DBIx::Class::Storage::DBI#dbh_do ]

...因为您无法从 ORM 中获得任何好处。

关于perl - DBIx::Class 可以与存储过程而不是表一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7512375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com