Canonicalized queries remove non-executable comments
The comments which do not alter the functionality of a query are now removed from canonicalized queries. Also fixed missing semicolon in the comment removal regex and added tests for comment removal.
This commit is contained in:
@ -29,3 +29,10 @@ add_test(NAME Internal-CanonicalQueryAlter COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/c
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/alter.output
|
${CMAKE_CURRENT_BINARY_DIR}/alter.output
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/alter.expected
|
${CMAKE_CURRENT_SOURCE_DIR}/alter.expected
|
||||||
$<TARGET_FILE:canonizer>)
|
$<TARGET_FILE:canonizer>)
|
||||||
|
|
||||||
|
add_test(NAME Internal-CanonicalQueryComment COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/canontest.sh
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/test.log
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/comment.sql
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/comment.output
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/comment.expected
|
||||||
|
$<TARGET_FILE:canonizer>)
|
||||||
|
11
query_classifier/test/canonical_tests/comment.expected
Normal file
11
query_classifier/test/canonical_tests/comment.expected
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
select ?;
|
||||||
|
select ?;
|
||||||
|
select ?;
|
||||||
|
select /*! ? + */ ?;
|
||||||
|
select /*!? ? + */ ?;
|
||||||
|
select /*!? ? + */ ?;
|
||||||
|
SELECT ? ;
|
||||||
|
SELECT ? /*! +? */;
|
||||||
|
SELECT ? /*!? +? */;
|
||||||
|
SELECT ? /*M! +? */;
|
||||||
|
SELECT ? /*M!? +? */;
|
11
query_classifier/test/canonical_tests/comment.sql
Normal file
11
query_classifier/test/canonical_tests/comment.sql
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
select 1;-- comment after statement
|
||||||
|
select 1;# comment after statement
|
||||||
|
select /* inline comment */ 1;
|
||||||
|
select /*! 1 + */ 1;
|
||||||
|
select /*!300000 1 + */ 1;
|
||||||
|
select /*!300000 1 + */ 1;
|
||||||
|
SELECT 2 /* +1 */;
|
||||||
|
SELECT 1 /*! +1 */;
|
||||||
|
SELECT 1 /*!50101 +1 */;
|
||||||
|
SELECT 2 /*M! +1 */;
|
||||||
|
SELECT 2 /*M!50101 +1 */;
|
@ -2034,13 +2034,13 @@ void skygw_file_close(
|
|||||||
#define BUFFER_GROWTH_RATE 1.2
|
#define BUFFER_GROWTH_RATE 1.2
|
||||||
static pcre2_code* remove_comments_re = NULL;
|
static pcre2_code* remove_comments_re = NULL;
|
||||||
static const PCRE2_SPTR remove_comments_pattern = (PCRE2_SPTR)
|
static const PCRE2_SPTR remove_comments_pattern = (PCRE2_SPTR)
|
||||||
"(?:`[^`]*`\\K)|(?:#.*|--[[:space]].*)";
|
"(?:`[^`]*`\\K)|(\\/[*](?!(M?!)).*?[*]\\/)|(?:#.*|--[[:space:]].*)";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove SQL comments from the end of a string
|
* Remove SQL comments from the end of a string
|
||||||
*
|
*
|
||||||
* The inline comments are not removed due to the fact that they can alter the
|
* The inline executable comments are not removed due to the fact that they can
|
||||||
* behavior of the query.
|
* alter the behavior of the query.
|
||||||
* @param src Pointer to the string to modify.
|
* @param src Pointer to the string to modify.
|
||||||
* @param srcsize Pointer to a size_t variable which holds the length of the string to
|
* @param srcsize Pointer to a size_t variable which holds the length of the string to
|
||||||
* be modified.
|
* be modified.
|
||||||
|
Reference in New Issue
Block a user