Kouhei Sutou
null+****@clear*****
Tue Nov 29 18:18:43 JST 2016
Kouhei Sutou 2016-11-29 18:18:43 +0900 (Tue, 29 Nov 2016) New Revision: 0dc3c714769264173c543dd8ff06d4c7650e9f52 https://github.com/pgroonga/pgroonga/commit/0dc3c714769264173c543dd8ff06d4c7650e9f52 Message: Use "query_" as prefix Added files: expected/function/query-escape/all.out sql/function/query-escape/all.sql src/pgrn_query_escape.c Removed files: expected/function/escape-query/all.out sql/function/escape-query/all.sql Modified files: pgroonga--1.1.8--1.1.9.sql pgroonga.sql sources.am src/pgrn_escape.c src/pgroonga.h Deleted: expected/function/escape-query/all.out (+0 -6) 100644 =================================================================== --- expected/function/escape-query/all.out 2016-11-29 18:10:43 +0900 (3f8d84f) +++ /dev/null @@ -1,6 +0,0 @@ -SELECT pgroonga.escape_query('a+B-c< >あいう~*()"\\'':'); - escape_query -------------------------------------- - a\+B\-c\< \>あいう\~\*\(\)\"\\\\'\: -(1 row) - Added: expected/function/query-escape/all.out (+6 -0) 100644 =================================================================== --- /dev/null +++ expected/function/query-escape/all.out 2016-11-29 18:18:43 +0900 (35c4f80) @@ -0,0 +1,6 @@ +SELECT pgroonga.query_escape('a+B-c< >あいう~*()"\\'':'); + query_escape +------------------------------------- + a\+B\-c\< \>あいう\~\*\(\)\"\\\\'\: +(1 row) + Modified: pgroonga--1.1.8--1.1.9.sql (+2 -2) =================================================================== --- pgroonga--1.1.8--1.1.9.sql 2016-11-29 18:10:43 +0900 (3599649) +++ pgroonga--1.1.8--1.1.9.sql 2016-11-29 18:18:43 +0900 (c186b29) @@ -1,6 +1,6 @@ -CREATE FUNCTION pgroonga.escape_query(query text) +CREATE FUNCTION pgroonga.query_escape(query text) RETURNS text - AS 'MODULE_PATHNAME', 'pgroonga_escape_query' + AS 'MODULE_PATHNAME', 'pgroonga_query_escape' LANGUAGE C IMMUTABLE STRICT; Modified: pgroonga.sql (+2 -2) =================================================================== --- pgroonga.sql 2016-11-29 18:10:43 +0900 (b63e603) +++ pgroonga.sql 2016-11-29 18:18:43 +0900 (b313fa0) @@ -65,9 +65,9 @@ CREATE FUNCTION pgroonga.flush(indexName cstring) VOLATILE STRICT; -CREATE FUNCTION pgroonga.escape_query(query text) +CREATE FUNCTION pgroonga.query_escape(query text) RETURNS text - AS 'MODULE_PATHNAME', 'pgroonga_escape_query' + AS 'MODULE_PATHNAME', 'pgroonga_query_escape' LANGUAGE C IMMUTABLE STRICT; Modified: sources.am (+1 -0) =================================================================== --- sources.am 2016-11-29 18:10:43 +0900 (a7d944f) +++ sources.am 2016-11-29 18:18:43 +0900 (5f2e587) @@ -17,6 +17,7 @@ SRCS = \ src/pgrn_match_positions_character.c \ src/pgrn_options.c \ src/pgrn_pg.c \ + src/pgrn_query_escape.c \ src/pgrn_query_extract_keywords.c \ src/pgrn_snippet_html.c \ src/pgrn_value.c \ Deleted: sql/function/escape-query/all.sql (+0 -1) 100644 =================================================================== --- sql/function/escape-query/all.sql 2016-11-29 18:10:43 +0900 (b546f4b) +++ /dev/null @@ -1 +0,0 @@ -SELECT pgroonga.escape_query('a+B-c< >あいう~*()"\\'':'); Added: sql/function/query-escape/all.sql (+1 -0) 100644 =================================================================== --- /dev/null +++ sql/function/query-escape/all.sql 2016-11-29 18:18:43 +0900 (28d6f2b) @@ -0,0 +1 @@ +SELECT pgroonga.query_escape('a+B-c< >あいう~*()"\\'':'); Modified: src/pgrn_escape.c (+0 -30) =================================================================== --- src/pgrn_escape.c 2016-11-29 18:10:43 +0900 (ad06b07) +++ src/pgrn_escape.c 2016-11-29 18:18:43 +0900 (10ec7ab) @@ -9,7 +9,6 @@ static grn_ctx *ctx = &PGrnContext; static struct PGrnBuffers *buffers = &PGrnBuffers; -PG_FUNCTION_INFO_V1(pgroonga_escape_query); PG_FUNCTION_INFO_V1(pgroonga_escape_string); PG_FUNCTION_INFO_V1(pgroonga_escape_boolean); PG_FUNCTION_INFO_V1(pgroonga_escape_int2); @@ -20,35 +19,6 @@ PG_FUNCTION_INFO_V1(pgroonga_escape_float8); PG_FUNCTION_INFO_V1(pgroonga_escape_timestamptz); /** - * pgroonga.escape_query(query text) : text - */ -Datum -pgroonga_escape_query(PG_FUNCTION_ARGS) -{ - grn_rc rc = GRN_SUCCESS; - text *query = PG_GETARG_TEXT_PP(0); - text *escapedQuery; - grn_obj *escapedQueryBuffer; - - escapedQueryBuffer = &(buffers->escape.escapedValue); - GRN_BULK_REWIND(escapedQueryBuffer); - rc = grn_expr_syntax_escape_query(ctx, - VARDATA_ANY(query), - VARSIZE_ANY_EXHDR(query), - escapedQueryBuffer); - - if (rc != GRN_SUCCESS) { - ereport(ERROR, - (errcode(PGrnRCToPgErrorCode(rc)), - errmsg("pgroonga: escape_query: failed to escape"))); - } - - escapedQuery = cstring_to_text_with_len(GRN_TEXT_VALUE(escapedQueryBuffer), - GRN_TEXT_LEN(escapedQueryBuffer)); - PG_RETURN_TEXT_P(escapedQuery); -} - -/** * pgroonga.escape(value text, special_characters text = '"\') : text */ Datum Added: src/pgrn_query_escape.c (+40 -0) 100644 =================================================================== --- /dev/null +++ src/pgrn_query_escape.c 2016-11-29 18:18:43 +0900 (0583f0d) @@ -0,0 +1,40 @@ +#include "pgroonga.h" + +#include "pgrn_global.h" +#include "pgrn_groonga.h" + +#include <utils/builtins.h> + +static grn_ctx *ctx = &PGrnContext; +static struct PGrnBuffers *buffers = &PGrnBuffers; + +PG_FUNCTION_INFO_V1(pgroonga_query_escape); + +/** + * pgroonga.query_escape(query text) : text + */ +Datum +pgroonga_query_escape(PG_FUNCTION_ARGS) +{ + grn_rc rc = GRN_SUCCESS; + text *query = PG_GETARG_TEXT_PP(0); + text *escapedQuery; + grn_obj *escapedQueryBuffer; + + escapedQueryBuffer = &(buffers->escape.escapedValue); + GRN_BULK_REWIND(escapedQueryBuffer); + rc = grn_expr_syntax_escape_query(ctx, + VARDATA_ANY(query), + VARSIZE_ANY_EXHDR(query), + escapedQueryBuffer); + + if (rc != GRN_SUCCESS) { + ereport(ERROR, + (errcode(PGrnRCToPgErrorCode(rc)), + errmsg("pgroonga: query_escape: failed to escape"))); + } + + escapedQuery = cstring_to_text_with_len(GRN_TEXT_VALUE(escapedQueryBuffer), + GRN_TEXT_LEN(escapedQueryBuffer)); + PG_RETURN_TEXT_P(escapedQuery); +} Modified: src/pgroonga.h (+1 -1) =================================================================== --- src/pgroonga.h 2016-11-29 18:10:43 +0900 (4aff56b) +++ src/pgroonga.h 2016-11-29 18:18:43 +0900 (55cf3a7) @@ -67,7 +67,7 @@ extern Datum PGDLLEXPORT pgroonga_match_positions_byte(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_match_positions_character(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_query_extract_keywords(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_flush(PG_FUNCTION_ARGS); -extern Datum PGDLLEXPORT pgroonga_escape_query(PG_FUNCTION_ARGS); +extern Datum PGDLLEXPORT pgroonga_query_escape(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_escape_string(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_escape_boolean(PG_FUNCTION_ARGS); extern Datum PGDLLEXPORT pgroonga_escape_int2(PG_FUNCTION_ARGS); -------------- next part -------------- HTML����������������������������...下載