Skip to content

Commit f8a0f84

Browse files
authored
escape substr parameters (#70)
* format substr * 2.6.9
1 parent de1c9cc commit f8a0f84

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/SqliteFormatter.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ class SqliteFormatter extends SqlFormatter {
147147
* @returns {string}
148148
*/
149149
$substring(p0, pos, length) {
150-
if (length)
151-
return sprintf('SUBSTR(%s,%s,%s)', this.escape(p0), pos.valueOf() + 1, length.valueOf());
152-
else
153-
return sprintf('SUBSTR(%s,%s)', this.escape(p0), pos.valueOf() + 1);
150+
if (length) {
151+
return sprintf('SUBSTR(%s,%s + 1,%s)', this.escape(p0), this.escape(pos), this.escape(length));
152+
} else {
153+
return sprintf('SUBSTR(%s,%s + 1)', this.escape(p0), this.escape(pos));
154+
}
154155
}
155156
/**
156157
* Implements substring(str,pos) expression formatter.
@@ -160,10 +161,11 @@ class SqliteFormatter extends SqlFormatter {
160161
* @returns {string}
161162
*/
162163
$substr(p0, pos, length) {
163-
if (length)
164-
return sprintf('SUBSTR(%s,%s,%s)', this.escape(p0), pos.valueOf() + 1, length.valueOf());
165-
else
166-
return sprintf('SUBSTR(%s,%s)', this.escape(p0), pos.valueOf() + 1);
164+
if (length) {
165+
return sprintf('SUBSTR(%s,%s + 1,%s)', this.escape(p0), this.escape(pos), this.escape(length));
166+
} else {
167+
return sprintf('SUBSTR(%s,%s + 1)', this.escape(p0), this.escape(pos));
168+
}
167169
}
168170
/**
169171
* Implements length(a) expression formatter.

0 commit comments

Comments
 (0)