2

Wanting to run a query in a C# application against hive.

OdbcCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM user WHERE id = ?";
cmd.Parameters.Add("?id", OdbcType.Int).Value = 4;

OdbcDataReader reader = cmd.ExecuteReader();

But end up getting an error from the ODBC driver

ERROR [HY000] [Hortonworks][HiveODBC] (80) Syntax or semantic analysis error thrown in server while execurint query. Error message from server: Error while compiling statement: FAILED: ParseException line 1:42 cannot recognize input near '?' '' in expression specification

nobody
  • 10,892
  • 8
  • 45
  • 63
Kevin Vasko
  • 1,561
  • 3
  • 22
  • 45
  • http://stackoverflow.com/questions/18082840/how-to-bind-parameters-via-odbc-c – Chad May 31 '16 at 18:49
  • @Chad thanks. I saw that but that doesn't seem to solve the issue (unless I screwed up). I am questioning if the driver even supports parameterized queries. – Kevin Vasko May 31 '16 at 18:51
  • this is incorrect `cmd.Parameters.Add("?id", OdbcType.Int).Value = 4;` you should try it like this `cmd.Parameters.Add("@id", OdbcType.Int).Value = 4;` [ODBC Parameter Class](https://msdn.microsoft.com/en-us/library/system.data.odbc.odbcparameter(v=vs.110).aspx) – MethodMan May 31 '16 at 19:25
  • We tried it both ways @id and ?id and it still does not work. – Kevin Vasko May 31 '16 at 19:50
  • @KevinVasko did you figure this out yet? we ran into the same problem? – looooongname Mar 20 '18 at 13:12
  • @hngdev unfortunately I did not. I posted this question on Hortonworks website as well and only got the same suggestions. https://community.hortonworks.com/questions/36773/hive-odbc-parameterized-query.html I think we ended up going a different path. – Kevin Vasko Mar 20 '18 at 13:21
  • @KevinVasko I saw your question on that site, I'm thinking of using stored procedure on Hive. Not sure it's going to work. – looooongname Mar 20 '18 at 13:26

0 Answers0