2
votes

I'm using the Impala ODBC driver provided by Cloudera. I can't seem to use query parameters correctly. For instance:

OdbcCommand command = DbConnection.CreateCommand();
command.CommandText = "INSERT INTO TABLE test VALUES(?, ?)";
command.Parameters.Add("key", OdbcType.VarChar).Value = "csharp";
command.Parameters.Add("val", OdbcType.VarChar).Value = "test";
command.ExecuteNonQuery();

throws the following exception.

{"ERROR [HY000] [Cloudera][ImpalaODBC] (110) Error while executing a query in Impala: [HY000] : AnalysisException: Syntax error in line 1:\nINSERT INTO TABLE test VALUES(?, ?)\n
^\nEncountered: Unexpected character\nExpected: CASE, CAST, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, TRUNCATE, TRUE, IDENTIFIER\n\nCAUSED BY: Exception: Syntax error\n"}

Which should manage query parameters (and replacement of ? by values), ODBC library or the driver ? It seems to be the driver and in this case, it's not implemented... And it's a shame because I cannot use prepared statement.

Does somebody know a way to use query parameters with the Impala ODBC driver?

1
I found that I needed to avoid a trailing semicolon. In your example, "command.CommandText = "INSERT INTO TABLE test VALUES(?, ?)"; is correct but command.CommandText = "INSERT INTO TABLE test VALUES(?, ?);"; would give me the same error you got. This isn't your problem, but thought it might help others.Patrick Szalapski

1 Answers

1
votes

INSERT INTO TABLE is Impala specific syntax. To use Impala ODBC to do INSERT with parameters you need the SQL 92 syntax which is INSERT INTO <table name> ...

Can you try the following syntax and see if it help?

INSERT INTO test VALUES(?, ?)