问题
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:
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(?, ?)
来源:https://stackoverflow.com/questions/34093083/query-parameters-with-impala-odbc-driver