Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm Building Audit Trail with Trigger, and want to convert the inserted / updated / deleted value into XML and store it into another table.

my trigger look like this:

DELIMITER $$

CREATE
    TRIGGER `MyDB`.`TriggerAudit` AFTER INSERT
    ON `MyDB`.`settings`
    FOR EACH ROW BEGIN
    INSERT INTO insert_audit_trail (user_uid, table_name, inserted_value) 
    VALUES ('the Username', 'the table name', 'Select to XML In Here')
    END$$

DELIMITER ;

Normally in MSSQL I can use FOR XML function, but in I Don't know to do this in MySQL. Is there any solutions for this?

share|improve this question

1 Answer 1

It appears this has already been answered here.

The answer references this article.

From the answer:

From the article:

use strict;
use DBI;
use XML::Generator::DBI;
use XML::Handler::YAWriter;

my $dbh = DBI->connect ("DBI:mysql:test",
                       "testuser", "testpass",
                       { RaiseError => 1, PrintError => 0});
my $out = XML::Handler::YAWriter->new (AsFile => "-");
my $gen = XML::Generator::DBI->new (
                               Handler => $out,
                               dbh => $dbh
                           );
$gen->execute ("SELECT name, category FROM animal");
$dbh->disconnect ();
share|improve this answer
    
Yes, but its not a MySQL Query. any solution to integrate that into triggers or store procedures? –  reptildarat Mar 7 at 15:36
    
If you already know the xml schema or can dynamically build it in the procedure, you can use UpdateXML - a description of which is detailed here. –  Thomas Cleberg Mar 7 at 15:43
    
If you'd like, I could help with using the function. Could you please provide an example of a desired XML result and source data? –  Thomas Cleberg Mar 7 at 15:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.