Improved SQLParser to work with triggers in additional .sql files #381

Merged
merged 7 commits into from Jul 24, 2012

Conversation

Projects
None yet
3 participants
Contributor

rozwell commented Jun 13, 2012

Improved SQLParser will now allow to add triggers in additional .sql files (added in sqldb.map):

Example triggers.sql file:

ALTER TABLE unit ADD `symbol_sort` VARCHAR(255) NOT NULL;

DROP TRIGGER IF EXISTS symbol_sort_insert;
DROP TRIGGER IF EXISTS symbol_sort_update;

DELIMITER |

CREATE TRIGGER symbol_sort_insert BEFORE INSERT
ON unit FOR EACH ROW
BEGIN
  SET @tail = new.symbol;
  SET @output = '';
  WHILE @tail != '' DO
    SET @head = SUBSTRING_INDEX(@tail, '-', 1);
    SET @tail = SUBSTRING(@tail, LENGTH(@head) + 2);
    SET @output = CONCAT(@output, LPAD(@head, 4, 0));
  END WHILE;
  SET new.symbol_sort = @output;
END|

CREATE TRIGGER symbol_sort_update BEFORE UPDATE
ON unit FOR EACH ROW
BEGIN
  SET @tail = new.symbol;
  SET @output = '';
  WHILE @tail != '' DO
    SET @head = SUBSTRING_INDEX(@tail, '-', 1);
    SET @tail = SUBSTRING(@tail, LENGTH(@head) + 2);
    SET @output = CONCAT(@output, LPAD(@head, 4, 0));
  END WHILE;
  SET new.symbol_sort = @output;
END|

DELIMITER ;

And it will work like a charm now instead of throwing errors.

Because SQLParser uses semicolon to explode queries, it wasn't possible to insert triggers.

Note: only single character can be used as delimiter (for now)

This pull request passes (merged 05b7e1d into 66f9eda).

Owner

willdurand commented Jun 13, 2012

Could you provide some unit tests please?

Owner

willdurand commented Jul 13, 2012

ping @rozwell

Contributor

rozwell commented Jul 15, 2012

pong @willdurand
Sorry again, will do something tommorow.

This pull request passes (merged 8cafbd6 into debd94f).

This pull request fails (merged 9667675 into debd94f).

Contributor

rozwell commented Jul 22, 2012

@willdurand I'm not a tests master so let me know if any tests are missing.

This pull request fails (merged fc47459e into debd94f).

This pull request fails (merged 97f9241e into debd94f).

This pull request fails (merged d068c963 into debd94f).

This pull request fails (merged 0e46b461 into debd94f).

This pull request fails (merged d5146541 into debd94f).

This pull request fails (merged 8dfe1969 into debd94f).

This pull request fails (merged 20d0d4c9 into debd94f).

This pull request fails (merged 1f156f00 into debd94f).

This pull request fails (merged 7d6cbb97 into debd94f).

Contributor

rozwell commented Jul 22, 2012

I've rebased this branch so feel free to cleanup travis comments.
I'll run tests locally and then push when it's done and working.

Owner

willdurand commented Jul 23, 2012

No problem, we can wait :)

This pull request fails (merged 4516f01d into debd94f).

This pull request fails (merged 5bc53b0a into debd94f).

This pull request fails (merged aeb010ba into debd94f).

This pull request passes (merged b12704cd into debd94f).

Contributor

rozwell commented Jul 24, 2012

Ok, seems to be done.

This pull request passes (merged 6bae0ca into debd94f).

This pull request fails (merged 5e9dfc1 into debd94f).

willdurand added a commit that referenced this pull request Jul 24, 2012

Merge pull request #381 from rozwell/delimiter-trigger-parser
Improved SQLParser to work with triggers in additional .sql files

@willdurand willdurand merged commit 7f9a5b7 into propelorm:master Jul 24, 2012

Owner

willdurand commented Jul 24, 2012

Perfect! Thank you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment