• Resolved rladha

    (@rladha)


    Looking for a suggestion, but also suggesting an enhancement.

    During CRUD process: upon INSERT , I am able to auto capture user_name ($$USERID$$) , create timestamp ($$NOWDT$$) and store them in the table.

    But, during the UPDATE, the auto_capture doesn’t work, because, default value only works with the underline field is empty.

    Any idea, how to handle this use-case?

    My suggestion: In the template setup, add a new checkbox if the default column has a value then display a checkbox — checkbox can be called “override upon update” screenshot (https://drive.google.com/file/d/14AY9doT9NTl3EkmSoPA0hlrUKHwJqRe6/view?usp=sharing)

    in the backend, WPDA, if the box is checked, take the default value and pass to an update statement. if the box is checked, but default value is empty then ignore it.

    Happy to discuss further if required.

    thanks

    Rahim

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Rahim,

    Your DBMS can automatically update the timestamp column for you:
    alter table sms_reg_ao_203_bui_offering_sections modify column log_update_ts timestamp default current_timestamp on update current_timestamp
    Or you can use a database trigger to achieve the same result.

    Does this solve the timestamp issue?

    In WordPress your database has no access to your WordPress user ID. So database triggers are no real option. Maybe the plugin can store a global value in the session and you can use that value in a database trigger? Not sure if this will work, but I can give it a try. It would be an interesting features as this would for auditing as well.

    Before I dive into it, are you allowed to create database triggers? Do you have the necessary DBMS credentials?

    Thanks,
    Peter

    Thread Starter rladha

    (@rladha)

    Thanks, Peter.

    – Yes, I am able to create Trigger to capture the update Timestamp, and already doing that on few tables.
    – The gap I am finding is, how to capture the WP_Use name and save in the table during the UPDATE.
    – I would also suggest, if you can explore my above suggestion (checkbox in the template screen)

    Happy to provide more detail and happy to assist in testing too.

    I believe this feature will be helpful for many users who are trying to build CRUD screen using WPDA.

    Rahim

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Rahim,

    I released version 5.2.3 early today which is the first version that supports access to the WordPress user ID in SQL. ?? You can now access the WordPress user ID from your queries, views, triggers, procedures and functions.

    Here is the documentation:
    https://wpdataaccess.com/2022/08/18/wordpress-user-id-in-sql/

    You’ll also find a description how to make other WordPress user info like user login or email available in SQL.

    Hope this help! Let me know if you need assistance.

    Best regards,
    Peter

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Suggestion: CRUD – capture user name during update’ is closed to new replies.