diff --git a/parsesql.c b/parsesql.c index 5c3cc5b..e45e946 100644 --- a/parsesql.c +++ b/parsesql.c @@ -37,6 +37,11 @@ struct SQL_Token { typedef struct SQL_Token SQL_Token; +static is_hostvar_char(char c) +{ + return isalnum(c) || c == '_'; +} + size_t sql_count_host_vars(const char *s) { size_t ret = 0; @@ -49,7 +54,7 @@ size_t sql_count_host_vars(const char *s) if (!a || b3); + struct st { + const char *a; + bool b; + }; + typedef struct st st; + const st src[] = { + { "foo ", false }, + { ":xyz_id", true }, + { " bar in ", false }, + { ":ab_id:ab_id_ind", true }, + { " blah);", false }, + { 0, 0} + }; + for (size_t i = 0; i<5; ++i) { + ck_assert(tokens[i].host_var == src[i].b); + char b[128] = {0}; + strncpy(b, tokens[i].begin, tokens[i].end - tokens[i].begin); + ck_assert_str_eq(b, src[i].a); + } + ck_assert(!tokens[5].begin); + ck_assert(!tokens[5].end); + free(tokens); +} +END_TEST + START_TEST(quote_01) { char out[32] = {0}; @@ -319,6 +352,7 @@ TCase *parsesql_tc_create() tcase_add_test(tc, token_04); tcase_add_test(tc, token_05); tcase_add_test(tc, token_06); + tcase_add_test(tc, token_07); tcase_add_test(tc, quote_01); tcase_add_test(tc, quote_02); tcase_add_test(tc, quote_03);