Pass-through extension with parameters - function is called multiple times - what is wrong?

(9 posts) (2 voices)
  • Started 3 weeks ago by Mark Tetrode
  • Latest reply from myDBR Team

Tags:

  1. Mark Tetrode, Member

    Hi support

    I'm experimenting with writing a pass-through extension. I modified the example passthrough.php as follows:


    function Ext_Passthrough($id, $options, $dataIn, $colInfo )
    {
    echo "PASSTRHOUGH";
    print_r(['id'=>$id, 'options'=>$options, 'dataIn'=>$dataIn, 'colInfo'=>$colInfo]);

    and the extensions.php as follows:


    'passthrough' => array(
    'enabled' => true,
    'autoload' => 1,
    'php' => 'passthrough.php',
    // Passthrough extension only handles the single_pass_call
    'single_pass_call' => 'Ext_Passthrough',
    'javascript' => array(),
    'css' => array(),
    'mydbrextension' => 1,
    'cmds' => array(
    array(
    'cmd' => 'dbr.passthrough'
    ),
    array(
    'cmd' => 'dbr.passthrough.bla',
    'bla' => 1
    ),
    ),
    'passthrough' => true
    ),

    When I run a report as follows:


    select 'dbr.passthrough';
    select 'dbr.passthrough.bla', 'bla';
    select 1;

    The Ext_Passthrough function is called twice? What am I doing wrong?

    Thanks

    Mark

    Posted 3 weeks ago #
  2. myDBR Team, Key Master

    Mark,
    you do not want to modify the incuded dbr.passthrough-extension as they will be overwritten in each update, but create your own into user/extensions. A passthrough extension takes data from a result set, does what is designed to the data and returns the data back to myDBR. So you can do pretty much whatever you like with the data (modify it, call external services etc).

    A passthrough extension is defined by the

    'passthrough' => true
    flag in the extension definition. You can define the actual command(s) for the extension (as you would do with other extensions).

    In your example you have assigned two commands for the extension. The 'dbr.passthrough' and 'dbr.passthrough.bla'. The first command in the command definition (dbr.passthrough) is the main command and other commands are the options. When you call the extension, make sure you introduce the options first and the main command as the last one.

    So to call the extension you would use the order:

    select 'dbr.mypassthrough.bla', 'bla';
    select 'dbr.mypassthrough';
    select 1;

    And the extension definition would be in user/extensions.php:

    $dbr_extensions['MyPassthrough'] = array(
    'enabled' => true,
    'autoload' => 1,
    'php' => 'myPassthrough.php',
    // Passthrough extension only handles the single_pass_call
    'single_pass_call' => 'Ext_MyPassthrough',
    'javascript' => array(),
    'css' => array(),
    'cmds' => array(
    array(
    'cmd' => 'dbr.mypassthrough'
    ),
    array(
    'cmd' => 'dbr.mypassthrough.bla',
    'bla' => 1
    ),
    ),
    'passthrough' => true
    );

    Also, make sure you have updated to the latest build as it includes a fix for datatype alignment definitions for the extensions. Just run the automatic updater for this.

    Posted 3 weeks ago #
  3. Mark Tetrode, Member

    Thanks


    I restored to the original files (extensions.php, passthrough.php), edited the users/extensions/extensions.php, moved my extension to users/extensions/myext/myext.php but this gave an error.

    Warning: main(extensions/webservice/webservice.php): failed to open stream: No such file or directory in .../apps/showReport.php on line 34

    Fatal error: main(): Failed opening required 'extensions/webservice/webservice.php' (include_path='.:/usr/share/php') in .../apps/showReport.php on line 34

    When I then moved back users/extensions/myext/myext.php to extensions/myext/myext.php the extension started to work again.

    It seems to me that the correct way is to put the extension in users/extensions/myext but this does not work?

    Thanks

    EDIT:
    It now works, perhaps some PHP caching.

    Posted 3 weeks ago #
  4. myDBR Team, Key Master

    Most likely cause of this is that you have put the option:

      'mydbrextension' => 1,

    into your webservice extensions definition. This is only used with extensions that myDBR ships with. User extensions should not have this at all. See the example above.

    --
    myDBR Team

    Posted 3 weeks ago #
  5. Mark Tetrode, Member

    That might also be the case. One last thing, is it possible to get the parameters in the Show MyDBR Commands list?

    Posted 3 weeks ago #
  6. myDBR Team, Key Master

    Mark,
    what do you mean by this?

    The Show MyDBR Commands list does show the parameters in Example and there is a direct link to documentation.

    How would you like it to work?

    --
    myDBR Team

    Posted 3 weeks ago #
  7. Mark Tetrode, Member

    Hi

    What I mean is that I want to have the dbr.mypassthrough, dbr.mypassthrough.bla etc. in the list of MyDBR Commands so that when I click on the Show MyDBR Commands it is present there.

    Another question, still on the same topic. How can I use the return values of the mypassthrough? For example I would like to so something in the line of:


    select 'dbr.mypassthrough.bla', 'bla';
    select 'dbr.mypassthrough';
    select 'result' into @result, @error;
    -- the mypassthrough will return one row, two columns if @result = 'OK' then
    -- display to the user that the extension functioned properly
    else
    -- display the @error to the user
    end if;

    Possible? Or how can this be done? Have the extension create a temporary table?

    Thanks

    Mark

    Posted 3 weeks ago #
  8. myDBR Team, Key Master

    What I mean is that I want to have the dbr.mypassthrough, dbr.mypassthrough.bla etc. in the list of MyDBR Commands so that when I click on the Show MyDBR Commands it is present there.

    Ah, ok. We'll take a look if this could be added to the extension definition.

    Another question, still on the same topic. How can I use the return values of the mypassthrough?

    A passthrough extension returns the data to myDBR report as if the data would have come from a normal query. What this means is that you can for example get data from external source based on input from your local data and use that external data to draw a chart / use in a crosstab / use any other myDBR functionality.

    To return the data, you return two arrays from the extension using the Extension::result_set() method. See a sample from "A passthrough extension"-section from documentation.

    To use the data as part of myDBR report, put the passthrough call just before the data:

    select 'dbr.chart', 'Pie';
    select 'dbr.get_external_data'; select 20 as 'ExternalID';

    This would draw a pie-chart from the output of a 'dbr.get_external_data' passthrough extension whose input parameters in this case is a single row/column.

    --
    myDBR Team

    Posted 3 weeks ago #
  9. myDBR Team, Key Master

    What I mean is that I want to have the dbr.mypassthrough, dbr.mypassthrough.bla etc. in the list of MyDBR Commands so that when I click on the Show MyDBR Commands it is present there.

    You can now add your own commands into the "Show myDBR Commands" by adding a documentation for the command in the extension declaration (see sqleditor.doc).

    --
    myDBR Team

    Posted 2 weeks ago #

Reply

You must log in to post.