editable report - pass fixed parameter

(6 posts) (2 voices)

Tags:

No tags yet.

  1. maron, Member

    Hello.

    I use inline editing quite a lot, and in some cases to save time I want to create one procedure - like the following:

    DROP PROCEDURE IF EXISTS sp_DBR_update_translation $$ CREATE PROCEDURE sp_DBR_update_translation(inId int, inText varchar(255), inAction varchar(16)) BEGIN

    IF (inAction) = 'translation' THEN UPDATE innflutningur.translations SET translation = (inText) WHERE id = (inId) LIMIT 1; ELSEIF (inAction) = 'original' THEN UPDATE innflutningur.translations SET original = (inText) WHERE id = (inId) LIMIT 1; ELSEIF (inAction) = 'delete' THEN DELETE FROM innflutningur.translations WHERE id = (inId) LIMIT 1; ELSE -- Debug SELECT concat("Error: ", (inId), " ", (inText), " ", (inAction)); END IF;

    END

    This way I can use the same procedure for different actions. However, how can I pass a fixed string parameter to the inAction in the following code.

    select 'dbr.editable', 'orig', 'sp_DBR_update_translation', 'inId=id', 'inText=orig', 'inAction="original"'; select 'dbr.editable', 'orig', 'sp_DBR_update_translation', 'inId=id', 'inText=translation', 'inAction="translation"'; select 'dbr.editable', 'orig', 'sp_DBR_update_translation', 'inId=id', 'inText=orig', 'inAction="delete"'; select id, original as orig, translation from innflutningur.translations;

    In short, I want to be able to use the same stored procedure to handle all updates for a table.

  2. myDBR Team, Key Master

    Hi,
    you already had the correct syntax: 'parameter="constant"'

    For example:

    select 'dbr.editable', 'orig', 'sp_DBR_update_translation', 'inId=id', 'inText=translation', 'inAction="translation"';

    --
    myDBR Team

  3. maron, Member

    Yes - I thought so - I have this working elsewhere for dbr.report.

    However in this case it is not working - the debug returns nothing for the inAction parameter - any idea what I could have wrong?

    I'm running the latest version.

    -- Maron

  4. myDBR Team, Key Master

    Ah ok,
    the last parameter of the editable procedure should be the parameter getting the value user enters. It is automatically handled by myDBR. In your example you have three parameters:

    1) 'inId' to hold the ID of the translations to be updated
    2) 'inText' to which is the original cell value before the user edit
    3) 'inAction' the constant value

    What you are missing is the fourth parameter that is automatically filled with the data user enters. Just add the parameter to sp_DBR_update_translation and use that as updated value. You do not need to pass the original value unless you actually use it.

    As for the delete, you might want to consider adding a column which would just hold a delete button and attach the delete action to it. See a demo in action.

    --
    myDBR Team

  5. maron, Member

    Thanks, swapping the parameters in sp_DBR_update_translation fixed the problem.

    Thanks.

  6. myDBR Team, Key Master

    You only need to use format:

    select 'dbr.editable', 'orig', 'sp_DBR_update_translation', 'inId=id', 'inAction="original"';

    for the dbr.editable. The last parameter (inText) is automatically populated with user edited value.

    --
    myDBR Team


Reply

You must log in to post.