in reply to Mysql templates

I believe that DBI and DBD::mysql will not allow you to combine distinct statements (e.g. with an SQL string containing ";" to delimit two or more separate operations) in a single prepare.

But I expect it would be fairly simple to set up the perl script so that it reads a template, splits it into its component single statements, and then prepares and executes each in turn. That way, the templates themselves don't need to be changed -- you just need to be scrupulous about how you employ them within a perl script.

But then, I've never used mysql templates, and have never even seen one. If you can provide a simplified example of what such a template would look like, this would be instructive.

Replies are listed 'Best First'.
Re^2: Mysql templates
by red-beard (Scribe) on Nov 08, 2005 at 13:15 UTC
    Basically a template is a file that contains one or more distinct statements ending with a ";"... at least that's what is being used by this reporting program.

    In this file it would contain...

    optimize table test; select * from test;
      So the only "tricky" part is to be able to say, for each operation within a template file, whether it needs to be handled via "do", or via "fetch" -- which might not be all that tricky, really, because the latter type will generally start with "select" (or "describe", or "show") as the first word of the statement.

      In general, you just need to split the template on semicolons (though there is the obvious -- though perhaps unlikely -- risk that a semicolon might appear as data within one of the operations, meaning you have to be careful about how you do the split.

      If the files are consistently formatted as you showed in this brief example (each distinct operation / statement is on a separate line, so that statements are separated by ";\n"), then splitting is much simpler -- you could even set your input record separator like this:  $/ = ";\n"; so that you read one statement at a time from the template, check what sort of statement it is, and pass it to the appropriate DBI method.

        Well I ended up just coding in a seperate prepare/execute statement for each one. It turns out it was less work to just copy and paste than to read the template with special code... Maybe :-(

        Thanks for the help.