Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_run_sql_array / _split_sql_chunk split too agressively, breaking triggers #22

Closed
Leeft opened this issue Jun 15, 2014 · 1 comment
Closed

Comments

@Leeft
Copy link
Contributor

Leeft commented Jun 15, 2014

The first thing _run_sql_array in DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator does during the deploy stage:

$sql = [ _split_sql_chunk( @$sql ) ];

And _split_sql_chunk executes:

my @sql = map { split /;\n/, $_ } @_;

This naive splitter which strips all semicolons doesn't work well with slightly more complex SQL, e.g. a MySQL trigger example:

sub sqlt_deploy_hook {
   my ( $self, $sqlt_table ) = @_;
   $sqlt_table->schema->add_trigger({
      name                => 'foo',
      perform_action_when => 'BEFORE',
      database_events     => [qw(INSERT)],
      fields              => [qw(name)],
      on_table            => $sqlt_table->name,
      schema              => $sqlt_table->schema,
      scope               => 'row',
      action              => q#
         IF ( 1 = 1 ) THEN
            SET NEW.name = 'foo';
         END IF;
      #,
   });
};

While deploying, the SQL is split just before the END IF, the semicolon is removed from the SQL (that first part is then fed to $dbh->do) and MySQL correctly returns a syntax error on the statement.

I don't see an obvious way yet to solve it properly with a patch for DH; in my subclassed ::DeployMethod::SQL::Translator class I've overridden _run_sql_array to skip calling _split_sql_chunk entirely (which isn't a method and thus not overridable), and this works around the problem for me. I haven't seen any adverse effects yet from leaving out the SQL splitting, though no doubt it'll have some effect somewhere.

@frioux
Copy link
Owner

frioux commented Jul 25, 2014

Yeah this is a big bummer see #11 as that is the real fix for this.

@frioux frioux closed this as completed Jul 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants