saran_techie has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
For a web application, we have written perl scripts to provide values for controls (textbox, checkbox, etc) in a page (say for example, user creation screen) and thereby updating them as well, by clicking a Save button. We need to check the Database whether the data have been updated appropriately. How can we achieve this through perl scripting?
Kindly assist

Thank You
Saravanan.S
  • Comment on How to do Database checking through Perl?

Replies are listed 'Best First'.
Re: How to do Database checking through Perl?
by targetsmart (Curate) on Feb 25, 2009 at 06:35 UTC
    see 'man DBI' and see DBD:: modules for connecting with specific databases.

    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
Re: How to do Database checking through Perl?
by CountZero (Bishop) on Feb 25, 2009 at 09:44 UTC
    Can you be reasonably certain that your database will return an error code if the update did not succeed? If so, you just have to check the errors (if any) returned by DBI to see if all went well.

    If you want to be really paranoid about it, you could do as follows:

    • Add an "UUID" field to each record
    • With each update, also update the record's UUID field with a fresh UUID value (I use the same UUID-value for each atomic update even if it concerns many records over many tables)
    • Then select all records in all tables which (should) have this UUID value and see if the updates succeeded.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: How to do Database checking through Perl?
by irah (Pilgrim) on Feb 25, 2009 at 09:14 UTC

    Before updating, you can store the value into variable. After updation, You can execute the select query with the condition. For example, I am going to update the name.

    Update names set first_name = 'irah';
    After that,
    select * from names where first_name = 'irah';

    If the number of rows, not equal to zero, the values are updated. If the same value already (before updating) available, you can execute the same select query before updating and compare the number of rows before updating and after updating.

Re: How to do Database checking through Perl?
by Anonymous Monk on Feb 25, 2009 at 09:14 UTC
    I would have thought that if you have the Perl code to update the database then it should be fairly straightforward to read it back. What have you tried?