Using Sql parameters on Ingres Database error

504 views Asked by At

Exception:

Local variable/parameter ':your-param-name' can only be used within a database procedure.

In MSSQL, the param character is @. In INGRES Database, really is : ? I cannot find official documentation for that...

SELECT * FROM MyIngresTable WHERE MyColumn = :poorParam

C# with Spring.NET AdoTemplate:

IDbParametersBuilder builder = CreateDbParametersBuilder();

builder.Create().Name("poorParam").Type(DbType.Int32).Value(1);

Any help?

1

There are 1 answers

0
Renato Mestre On

Solved!

Just use INTERROGATION without named param, and pass values in order of usage.

        string query = "SELECT * FROM MyIngresTable WHERE MyColumn >= ? and OtherColumn = ?";

        IDbParametersBuilder builder = CreateDbParametersBuilder();

        builder.Create().Type(DbType.Int32).Value(10);
        builder.Create().Type(DbType.String).Size(4).Value("test");

        IList<YourModelType> data = AdoTemplate.QueryWithRowMapper(
            CommandType.Text,
            query,
            new YourRowMapper<YourModelType>(),
            builder.GetParameters()
        );

Another tip about Spring.NET AdoTemplate:

    using Spring.Data.Common;
    using Spring.Data.Generic;

    protected virtual IDbParametersBuilder CreateDbParametersBuilder()
    {
        return new DbParametersBuilder(AdoTemplate.DbProvider);
    }

Thanks also, Panagiotis Kanavos.