void ParseSQLStrings(const std::vector<std::string>& sql_strings, const bool expect_failure) { // Initialize the postgres memory context pg_query_init(); for (auto sql_string : sql_strings) { PgQueryParseResult result = pg_query_parse(sql_string.c_str()); if (expect_failure == true) { EXPECT_NE(result.error, nullptr); LOG_INFO("input: %s", sql_string.c_str()); LOG_ERROR("error: %s at %d", result.error->message, result.error->cursorpos); } else { EXPECT_EQ(result.error, nullptr); LOG_INFO("parse tree: %s", result.parse_tree); } pg_query_free_parse_result(result); } // Destroy the postgres memory context //pg_query_destroy(); }
void* test_runner(void* ptr) { size_t i; for (i = 0; i < testsLength; i += 2) { PgQueryParseResult result = pg_query_parse(tests[i]); if (strcmp(result.parse_tree, tests[i + 1]) == 0) { printf("."); } else { printf("INVALID result for \"%s\"\nexpected: %s\nactual: %s\n", tests[i], tests[i + 1], result.parse_tree); } pg_query_free_parse_result(result); } return NULL; }