Skip to content

Commit

Permalink
Merge pull request #2191 from YasserHassan/2.0
Browse files Browse the repository at this point in the history
Fix #2185 when $$ not at line start ONLY
  • Loading branch information
Naktibalda committed Jul 27, 2015
2 parents fa31fa1 + 083c82e commit f8daba7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Codeception/Lib/Driver/PostgreSql.php
Expand Up @@ -26,8 +26,11 @@ public function load($sql)
continue;
}

if (strpos(trim($sqlLine), '$$') === 0) {
$dollarsOpen = !$dollarsOpen;
if (!preg_match('/\'.*\$\$.*\'/', $sqlLine)) { // Ignore $$ inside SQL standard string syntax such as in INSERT statements.
$pos = strpos($sqlLine, '$$');
if (($pos !== false) && ($pos >= 0)) {
$dollarsOpen = !$dollarsOpen;
}
}

$query .= "\n" . rtrim($sqlLine);
Expand Down
10 changes: 10 additions & 0 deletions tests/data/dumps/postgres.sql
Expand Up @@ -294,6 +294,16 @@ BEGIN
END;
$$;

-- Test $$ opening quote when is not at the beginning of the line.
CREATE OR REPLACE FUNCTION upd_timestamp() RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
NEW.created_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;

INSERT INTO users (name, email) VALUES ('This should work as well', 'user2@example.org');
--
-- end test for triggers with $$ syntax
Expand Down

0 comments on commit f8daba7

Please sign in to comment.