Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Re: How to override methods which use my() variables?

by Mur (Pilgrim)
on Nov 01, 2002 at 14:26 UTC ( #209722=note: print w/replies, xml ) Need Help??

in reply to Re: How to override methods which use my() variables?
in thread How to override methods which use my() variables?

Sure. DBIx::TextIndex ships with MySQL support (only); I'm trying to adapt it to work with PostgreSQL. However, the way the author implemented the database-specific support was to accept a parameter, "db => $dbname", and construct a partial file path, essentially via
$db = "DBIx/TextIndex/${db}.pm" require $db;
Thus, any db-specific code must reside in that file. In particular, it's intended that functions defined in that file return valid SQL statements as text for certain operations like CREATE TABLE, UPDATE, SELECT, etc.

The problem comes from the MySQL-centric code ... several of the internal operations involve putting a row in a table via "REPLACE INTO", which has no corresponding statement in most other RDBMS, including PostgreSQL. I really have to perform a DELETE and INSERT at that point, or a SELECT followed by an UPDATE (if successful) or an INSERT (if not). And I can't do the delete in the function that returns the SQL code, because the caller doesn't provide any info about parameters at that point; instead, it takes the SQL and executes it in a loop.

The code in TextIndex expects only a single SQL statement to be returned. Thus, I need to provide a function to override the TextIndex function, so that it gets both the DELETE statement and the INSERT statement, prepares both, and executes both in a loop.

The problem is that the function I'm overriding makes use of a lexical defined elsewhere in the package. At this point I think my only options are to rewrite the whole package or writing a new class that inherits from the old.
Jeff Boes
Database Engineer
Nexcerpt, Inc.
vox 269.226.9550 ext 24
fax 269.349.9076
...Nexcerpt...Connecting People With Expertise

Replies are listed 'Best First'.
Re^3: How to override methods which use my() variables?
by adrianh (Chancellor) on Nov 01, 2002 at 18:05 UTC

    Ahhh... understand now. You're right, the DB specific module is a bit hard to extend to anything apart from MySQL. Not even a proper factory class which is what I assumed. Eww...

    If you're feeling nice (and have the time) I'd patch the main module to cope with multiple SQL statements and send the patch to the module author along with your new and funky DBIx::TextIndex::pg extension.

    If you can't spare the time, drop a line to the author anyway so they know there's a problem (it's the only way it they get fixed :-)

    If you're into a evil hack type solution take a look at PadWalker, which can access lexical vars in calling subroutines.

    Alternatively I think you could subvert the intent of the DBIx::TextIndex::whatever methods and actually run the SQL there. You're passed $self so you have access to the database handle. This would probably be excessively evil tho :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://209722]
davido needs to close laptop to board flight home from yapc.
[davido]: I'll look into it in a few hours probably.
[davido]: when i do get to that point I think I'll do it in a vm snapshot just in case. :)
[oiskuu]: tye, you were right: loginuid/sessionid are part of task struct if compiled with AUDITSYSCALL. I have some doubts if you should actually depend on that feature.
[Corion]: oiskuu: Depends on what you want to do with that information
[tye]: I'm not depending on that feature. But I could in this environment. I'm using getlogin(). shrug
[Corion]: For benign logging (which user started this DB instance), it's OK
[tye]: We use auditd for security monitoring. So we can rely on auditing being enabled. I'm not sure who would want to not be able to audit. Maybe some VM inside another system with audit?
[SuicideJunkie]: spies would want a system to not be able to audit.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-06-23 20:12 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (555 votes). Check out past polls.