Skip to content

Query parameters logged in wrong order #1401

Closed

Description

@omatrot

I have the following PostgreSQL function declared as the following:

CREATE OR REPLACE FUNCTION public.test(param1 integer, param2 character varying, param3 character varying)

I'm using Dapper to call this function like this:

cnx.QueryAsync($@"SELECT * FROM public.test(@param1, @Param2, @param3);",
new { Param1 = 12, Param2 = mylongstring1, Param3 = mylongstring2});

As you can see the first parameter is of type integer, the 2 remaining are of type character vayring. Following is the ouput in the log:

Executing statement(s):
select * from public.test($1, $2, $3)
Parameters:
$1: mylongstring1 $2: mylongstring2 $3: 51

For the last part, it shoud be:

$1: 51 $2: mylongstring1 $3: mylongstring2
instead.

Activity

  1. roji commented on Jan 17, 2017

    @roji
    Member

    @omatrot have deleted the previous comments and will take a look.

  2. roji commented on Jan 17, 2017

    @roji
    Member

    @omatrot I wrote this up as a test but couldn't reproduce, everything seems to be fine. Could you please try to reproduce this in a minimal code sample and submit it?

    Here's my test:

    [Test]
    public async Task DapperOrdering()
    {
        using (var conn = OpenConnection())
        {
            using (var cmd = new NpgsqlCommand("CREATE FUNCTION pg_temp.test(param1 integer, param2 character varying, param3 character varying) RETURNS int AS $$ SELECT param1 $$ language 'sql'", conn))
            {
                cmd.ExecuteNonQuery();
            }
    
            var results = await conn.QueryAsync<int>($@"SELECT * FROM pg_temp.test(@Param1, @Param2, @Param3);",
                new { Param1 = 12, Param2 = "mylongstring1", Param3 = "mylongstring2" });
            Assert.That(results.Single(), Is.EqualTo(12));
        }
    }
  3. omatrot commented on Jan 17, 2017

    @omatrot
    Author

    You have to set up logging and look at the traces.
    The function call itself is OK, it is just the log output that is not in the correct order. This is confusing.

  4. roji commented on Jan 17, 2017

    @roji
    Member

    Which logging are you using, Npgsql's? I turned on Npgsql logging and it looks good (I admit I'm using 3.2, this could be a 3.1 issue):

          [12888] Executing statement(s):
            SELECT * FROM pg_temp.test($1, $2, $3)
          Parameters:
            $1: 12  $2: mylongstring1       $3: mylongstring2
    
  5. omatrot commented on Jan 17, 2017

    @omatrot
    Author

    I'm also using 3.2 and had the same problem in 3.1. This is not always wrong, it would be too simple. May be it is tied to the number and size of the parameters. Let me check.

  6. omatrot commented on Jan 17, 2017

    @omatrot
    Author

    Well, I switched from using Dapper-Async to Dapper and the problem is gone. Bad day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions