XS, Advanced XS Callback Patch For OCI, Part VII Back into 'C' and a little XS

Tonight's installment for my new chapter in XS Fun I am heading back to the 'c' land again looking at the function that actuality sets up the callback.

So now that we have a place to store of callback we can have another quick look at the 'dbd_db_STORE_attrib' function and this little addtion

 
    if (SvTRUE(valuesv)) {
        enable_ha(dbh, imp_dbh);
    } 
   else {
       disable_ha(imp_dbh);
   }

Now these are simple function calls in 'c' out to the two functions that obviously enable and disable out FAN callback, now there is no real reason to do this exactly this way, as it could be done with just one function call later on down the line, except that is good style to keep the same sort of implementation as the TAF. Both TAF and FAN are callback by TAF does have a test in OCI to see if it it is activate on the current Oracle connection. I am not aware of at this time if there is such a test in OCI to see if FAN or HA events are enables but Oracle may likely add one someday so we can account for that by building our FAN implementation about the same way. It may be a few lines of code but it could save time in the future.

So my next patch is

 
   return;
}

++/* FAN Events */

++ static int enable_ha(
++ SV *dbh,
++ imp_dbh_t *imp_dbh) {

++ sword status;
++ status = reg_ha_callback(dbh, imp_dbh);
++ if (status != OCI_SUCCESS) {
++ oci_error(dbh, NULL, status, "Setting FAN Callback Failed! ");
++ return 0;
++ }
++ return 1;
++}

static int enable_taf(

So my function is a simple static function that returns a int either 1 pass or 0 fail.

It has two parameters 'SV *dbh' which is a pointer to the current Perl db handle and 'imp_dbh_t *imp_dbh' which points to that 'c' struct we just did the last patch on that contains the function we just passed in.

The next line 'sword status;' has nothing to do with a silly 'Manga' cartoon or 'Sir Thomas Connery' it is just a predefined OCI typedef for a 'signed int' a sort to OCI shorthand like XS SV or alike that we can use because we have included it well before.

Next I make another function call out to 'reg_ha_callback' which will do the registration of our callback with Oracle, but that is for a later patch, here we are passing it the dbh and imp_dbh pointers and notice we do not add the '*' to these as they are already pointers.

Now that function will return either the OCI_SUCCESS constant or some other OCI constant and it will give that value to 'status' . Now we could of course add a very large if else block here to trap anything but success but that would not be practical or anything close to good style, instead we pass the status off to the oci_error function that will handle it for us all we need to to is supply some sort of error message. You can have a look at this function if you want it is in the 'dbdimp.c' file same as this patch. Next I just return 0 as an fail indicator or just a 1 as a pass.


That's all for today enjoy this blast from my past

imagesd.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations