Why is the rollback method not available for the DBI descriptor?

For some reason, I am having problems with the DBI descriptor. Basically, what happened was that I made a special connection function in the perl module and switched from it:

do 'foo.pl' 

to

 use Foo; 

and then i do

 $dbh = Foo->connect; 

And now for some reason I keep getting the error:

It is not possible to find the method of "rollback" the method of the object through the package "Foo" on the page .. /Foo.pm line 171.

So, it is strange that $ dbh is definitely not Foo, it is just defined in foo. Anyway, so far I have not had any problems. Any ideas what?

Edit : @Axeman: connect does not exist in the original. Before we got the line we used as follows:

 do 'foo.pl'; $dbh = DBI->connect($DBConnectString); 

and so connect something like this

 sub connect { my $dbh = DBI->connect('blah'); return $dbh; } 
+4
source share
3 answers

From perlfunc :

  do 'stat.pl';

     is just like

         eval `cat stat.pl`;

So, when you do 'foo.pl' , you are executing the code in the current context. Since I do not know what is going on in foo.pl or Foo.pm , I cannot tell you what has changed. But I can say that it always runs in the current context, and now runs in the Foo:: namespace.

As you call it, you pass 'Foo' as the first parameter to Foo::connect or the return element from Foo->can('connect') . It seems that in some way this is being passed to some code, which considers it a database descriptor and tells the rollback to this object.

+4
source

We need to see the actual code in Foo in order to be able to answer this question. You will probably want to read DBI Subclassing from the documentation to see how to do this properly.

Basically, you need either Foo to subclass the DBI correctly (again, you will need to read the documents), or you need to declare a connection function in order to properly delegate the DBI :: connect method. However, be careful when writing the generated wrapper for OO code. It is terribly difficult to maintain in this way.

+7
source

I agree with Axeman. You should probably call your function using

 use Foo; ... $dbh = Foo::connect(); 

instead of Foo-> connect ();

+3
source

Source: https://habr.com/ru/post/1277712/


All Articles