I am working on adding support for Cypher clauses on Postgres psql. So far, we have added if clauses with string comparison to separate Cypher clauses from SQL clauses, with one parser for each. The HandleCypherCmds()
function calls the Cypher parser, and the SendQuery()
function calls the SQL parser.
/* handle cypher match command */
if (pg_strncasecmp(query_buf->data, "MATCH", 5) == 0 ||
pg_strncasecmp(query_buf->data, "OPTIONAL", 8) == 0 ||
pg_strncasecmp(query_buf->data, "EXPLAIN", 7) == 0 ||
pg_strncasecmp(query_buf->data, "CREATE", 6) == 0)
{
cypherCmdStatus = HandleCypherCmds(scan_state,
cond_stack,
query_buf,
previous_buf);
success = cypherCmdStatus != PSQL_CMD_ERROR;
if (cypherCmdStatus == PSQL_CMD_SEND)
{
success = SendQuery(convert_to_psql_command(query_buf->data));
}
}
else
success = SendQuery(query_buf->data);
The problem with this approach is that, for example, CREATE could be a SQL clause or a Cypher clause. Also, if the user inserts a typo in the clause, like "MATH" instead of "MATCH," the clause will not reach the parser. To solve this problem, I am thinking of a better way to differentiate a Cypher clause from a SQL one. Is there a way to do this in C?