summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Dorn <jeremy@jeremydorn.com>2012-11-12 15:36:05 -0800
committerJeremy Dorn <jeremy@jeremydorn.com>2012-11-12 15:36:05 -0800
commit8599a1ff7e35ee072959688baef1c7613839ed7c (patch)
treede74a296ef98843b31da9a37d096d2f259b52f8d
parente3083aafdf447af4abb47342158f6778e03c6d4b (diff)
downloadsql-formatter-8599a1ff7e35ee072959688baef1c7613839ed7c.zip
sql-formatter-8599a1ff7e35ee072959688baef1c7613839ed7c.tar.gz
sql-formatter-8599a1ff7e35ee072959688baef1c7613839ed7c.tar.bz2
Fixing several bugs.
An exception was being thrown when the last line of a query was a comment (without trailing \n). A PHP notice was being thrown when the last character in a query was a '('. A PHP notice was being thrown when the last part of a query was a '(' followed by a string or punctuation and missing the closing ')'.
-rw-r--r--lib/SqlFormatter.php8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php
index 5bd2b2f..e6bb3f7 100644
--- a/lib/SqlFormatter.php
+++ b/lib/SqlFormatter.php
@@ -97,6 +97,10 @@ class SqlFormatter
$type = 'block comment';
}
+ if($last === false) {
+ $last = strlen($string);
+ }
+
return array(
'token'=>substr($string, 0, $last),
'type'=>$type
@@ -131,7 +135,7 @@ class SqlFormatter
// this makes it so we don't split things like NOW() or COUNT(*) into separate lines
if ($string[0] === '(') {
// "()"
- if ($string[1] === ')') {
+ if (isset($string[1]) && $string[1] === ')') {
return array(
'token'=>'()',
'type'=>'word'
@@ -140,7 +144,7 @@ class SqlFormatter
// "(word/whitespace/boundary)"
$next_token = self::getNextToken(substr($string, 1));
- if ($string[strlen($next_token['token']) + 1] === ')') {
+ if (isset($string[strlen($next_token['token']) + 1]) && $string[strlen($next_token['token']) + 1] === ')') {
if (in_array($next_token['type'], array('word', 'whitespace', 'boundary'))) {
return array(
'token'=>'(' . $next_token['token'] . ')',