Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
is_reserved()
and quote_ident()
.
These are used for display purposes in diagnostics. Added `tests/utils.my` to test them (and of course fixed bugs for having done so). Think I'll get rid of `tests.sql` next.
- Loading branch information
Showing
2 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
BEGIN; | ||
|
||
SELECT tap.plan(8); | ||
-- CALL tap.no_plan(); | ||
|
||
-- Test is_reserved(). | ||
SELECT tap.ok(tap.is_reserved('table'), '"table" should be an ident'); | ||
SELECT tap.ok(tap.is_reserved('TABLE'), '"TABLE" should be an ident'); | ||
SELECT tap.ok(NOT tap.is_reserved('foo'), '"foo" should not be an ident'); | ||
|
||
-- Test quote_ident(). | ||
SET @qc = CASE LOCATE('ANSI_QUOTES', @@SQL_MODE) WHEN 0 THEN '`' ELSE '"' END; | ||
|
||
SELECT tap.is_eq(tap.quote_ident('foo'), 'foo', '"foo" should be unquoted'); | ||
SELECT tap.is_eq(tap.quote_ident('FOO'), 'FOO', '"FOO" should be unquoted'); | ||
SELECT tap.is_eq( | ||
tap.quote_ident('table'), | ||
concat(@qc, 'table', @qc), | ||
'"table" should be quoted' | ||
); | ||
|
||
SELECT tap.is_eq( | ||
tap.quote_ident('TABLE'), | ||
concat(@qc, 'TABLE', @qc), | ||
'"TABLE" should be quoted' | ||
); | ||
|
||
SET @string = concat('foo', @qc, 'bar'); | ||
SET @qstring = concat(@qc, replace(@string, @qc, concat(@qc, @qc)), @qc); | ||
SELECT tap.is_eq( | ||
tap.quote_ident(@string), | ||
@qstring, | ||
concat('"', @string, '" should be quoted as ', @qstring) | ||
); | ||
|
||
CALL tap.finish(); | ||
|
||
ROLLBACK; |