Вот код запроса:
using (var connection = Connection) {
string commandText;
OdbcCommand command;
if (loadedNodes.Count > 0)
{
commandText = "SELECT * FROM TABLENAME where (PAR_1 = ? OR PAR_2 = ?) and PAR_1 NOT IN ({0}) and PAR_2 NOT IN ({0}) LIMIT ?";
var paramNames = loadedNodes.Select((s, index) => $"'@param{index}'").ToArray();
var inClause = string.Join(", ", paramNames);
command = new OdbcCommand(string.Format(commandText, inClause), connection);
for (int i = 0; i < paramNames.Length; i++)
{
command.Parameters.AddWithValue(paramNames[i], loadedNodes[i]);
}
}
else
{
commandText = "SELECT * FROM TABLENAME where (PAR_1 = ? OR PAR_2 = ?) LIMIT ?";
command = new OdbcCommand(commandText, connection);
}
command.Parameters.Add("@PAR_1", OdbcType.VarChar).Value = inn;
command.Parameters.Add("@PAR_2", OdbcType.VarChar).Value = inn;
command.Parameters.Add("", OdbcType.Int).Value = limit;//!!!
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
relatedRegistries.Add(Mapper.Resolve().Map<NdsRegistry>(reader));
}
}
}
В первом случае, когда я передаю параметр limit с помощью ""
- работает нормально.
Во втором случае commandText
из command
объект выглядит так:
SELECT * FROM TABLENAME where (PAR_1 = ? OR PAR_2 = ?) and PAR_1 NOT IN ('@param0') and PAR_2 NOT IN ('@param0') LIMIT ?
И я получаю сообщение об ошибке:
ERROR [HY000] [Hortonworks][Phoenix] (2020) An error occured while executing statement:
8org.apache.calcite.avatica.proto.Responses$ErrorResponse‘
ћjava.lang.RuntimeException: org.apache.phoenix.schema.TypeMismatchException: ERROR 203 (22005): Type mismatch. INTEGER and VARCHAR
at org.apache.calcite.avatica.jdbc.JdbcMeta.propagate(JdbcMeta.java:683)
at org.apache.calcite.avatica.jdbc.JdbcMeta.execute(JdbcMeta.java:878)
at org.apache.calcite.avatica.remote.LocalService.apply(LocalService.java:268)
at org.apache.calcite.avatica.remote.Service$ExecuteRequest.accept(Service.java:1026)
at org.apache.calcite.avatica.remote.Service$ExecuteRequest.accept(Service.java:1002)
at org.apache.calcite.avatica.remote.AbstractHandler.apply(AbstractHandler.java:94)
at org.apache.calcite.avatica.remote.ProtobufHandler.apply(ProtobufHandler.java:46)
at org.apache.calcite.avatica.server.AvaticaProtobufHandler.handle(AvaticaProtobufHandler.java:127)
at org.apache.phoenix.shaded.org.eclipse.jetty.server.handler.HandlerList.handle...
Кто-нибудь может предложить, как правильно передать параметр в команду odbc без знака =
?