[ic] Accessing $Db or $Sql in Jobs?
Stefan Hornburg
racke at linuxia.de
Thu Jan 6 08:20:41 EST 2005
On Thu, 06 Jan 2005 07:49:55 -0500
Ethan Rowe <ethan at endpoint.com> wrote:
> Jeff Fearn wrote:
>
> >On Thu, 6 Jan 2005 15:23:16 +1000, Jeff Fearn <jefffearn at gmail.com> wrote:
> >
> >
> >>On Wed, 05 Jan 2005 18:22:32 -0800, John Young <john_young at sonic.net> wrote:
> >>
> >>
> >>>Ethan Rowe wrote:
> >>>
> >>>
> >>>>Jeff Fearn wrote:
> >>>>
> >>>>
> >>>>
> >>>>>Hi, how do you make $Db or $Sql accessable to usertags run using the
> >>>>>jobs functionality?
> >>>>>
> >>>>>I have a job which uses a new usertag, however $Db and $Sql are empty.
> >>>>>
> >>>>>I have used $Db and $Sql in another usertag; which is used in the
> >>>>>order routing; without a problem. I am assuming this is something to
> >>>>>do with this tag being used via the job queue ... this may be a very
> >>>>>bad assumption :}
> >>>>>
> >>>>>I have tried setting "AllowGlobal foundation" in interchange.cfg,
> >>>>>which I really don't want to do, with no effect.
> >>>>>
> >>>>>The job just contains:
> >>>>>
> >>>>>[x12_945]
> >>>>>
> >>>>>The tag code is:
> >>>>>UserTag x12_945 Routine <<EOR
> >>>>>sub
> >>>>>{
> >>>>> # Make sure we have the EDI module installed
> >>>>> eval
> >>>>> {
> >>>>> use X12::Base;
> >>>>> };
> >>>>>
> >>>>> if($@)
> >>>>> {
> >>>>> ::logError("Could not load X12::Base Module. X12-945
> >>>>>processing failed!\n");
> >>>>> return(1);
> >>>>> }
> >>>>>
> >>>>> # Both of these always die
> >>>>> my $dbh = $Sql{orderline} or die("No SQL orderline database!\n");
> >>>>> my $ref = $Db{orderline} or die("No orderline database!\n");
> >>>>>
> >>>>> .....
> >>>>>}
> >>>>>
> >>>>>TIA, Jeff.
> >>>>>__
> >>>>>
> >>>>>
> >>>>>
> >>>>Having not yet used IC jobs myself, I may be totally useless. That said:
> >>>>Is the usertag defined for a single catalog, or as an Interchange global
> >>>>tag?
> >>>>
> >>>>The $Db and $Sql objects aren't available at the global level. You can
> >>>>effectively access the $Db object for a particular table at the global
> >>>>level, however, via:
> >>>>my $dbh = database_exists_ref( $tablename );
> >>>>$dbh = $dbh->ref();
> >>>>
> >>>> From there, $dbh gives you access to functions like query().
> >>>>
> >>>>I hope this is of some use.
> >>>> - Ethan
> >>>>
> >>>>
> >>>The following link might help, as well, if you are not already familiar
> >>>with its content:
> >>>
> >>>http://www.icdevgroup.org/pipermail/interchange-users/2004-December/041551.html
> >>>
> >>>
> >>>-John Young
> >>>
> >>>
> >>I had not seen that, thanks :)
> >>
> >>I had thought from reading that link that all I had to do was add:
> >>
> >>$Tag->perl({tables => 'orderline'});
> >>
> >>above my existing code. However both attempts to get refs to orderline
> >>still die.
> >>
> >>I have played around with what Ethan sent and I get " Can't call
> >>method "ref" on unblessed reference" errors :{
> >>
> >>
> >
> >Method was actually "prepare" ... need more caffine.
> >
> >
> >The tag is defined for a single catalog, appended to the require
> >UserTag line of catalog.cfg.
> >
> >The tag file is in the /usr/lib/interchange/code/UserTag/ directory.
> >
> >
> Hmm. I would expect any usertag defined in VENDROOT/code/UserTag to be
> an Interchange global usertag rather than a catalog-level usertag. But
> I'm obviously not familiar with your setup.
Yes, this is correct. Usertags in VENDROOT/code are global usertags
versus usertags included with statements in catalog.cfg.
>
> >>These jobs are making me thirsty :}
> >>
> >>
> What version of IC are you on? Not that I expect it to make a difference...
>
> If Perl is complaining that database_exist_ref is giving you an
> unblessed reference, it sounds to me like it's failing to actually see
> Interchange's table object.
>
> Try:
> my $dbh = database_exist_ref( $tablename ) or die "Couldn't get handle
> to table '$tablename'!";
>
> If the table object isn't accessible for whatever reason, you'll get an
> error at this step rather than later on.
>
> Incidentally, the prepare() method won't work on the object (if you
> manage to get said object); the object is equivalent to the $Db object,
> which gives you a query() method but no prepare().
>
> Regarding using $Tag->perl within a usertag to effectively grant
> permission to a particular table, that certainly works, but is only
> necessary in a catalog-level usertag rather than a global one. Global
> code (tags, subs, actionmaps, etc.) are omnisciently omnipotent.
>
> Can I ask a possibly stupid question? (yes.) Have you tested the
> usertag outside the context of jobs? Like, in a simple page?
>
> I'm curious to see where this goes, as I'll very likely be setting up
> Interchange jobs for the first time in a few weeks.
Good luck ! :-)
With regards
Racke
--
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team
More information about the interchange-users
mailing list