Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command builder generates invalid commands using a select query with aliases #2560

Open
jlareo opened this issue Aug 12, 2019 · 3 comments

Comments

@jlareo
Copy link

commented Aug 12, 2019

If I use a select query where aliases are defined, the command builder will generate commands with invalid queries. The problem is that the query inside the insert, update and delete commands uses the alias of a column instead of the name of the column, so the query will fail.

By using the following query:

Select "id" as "myid" , "column" as "mycolumn"
From "table"

The expected query in the update command should be:

Update "table" set "id" = @p0 "column" = @p1 where (("id" = @p2))

Instead of:

Update "table" set "myid" = @p0 "mycolumn" = @p1 where (("myid" = @p2))

@jlareo jlareo changed the title Command builder generates invalid query for insert, update and delete commands. Command builder generates invalid commands using a select query with aliases Aug 12, 2019

@jlareo

This comment has been minimized.

Copy link
Author

commented Aug 16, 2019

Using the odbc driver seems like the proper query without aliases is generated

@roji roji added the bug label Aug 19, 2019

@roji

This comment has been minimized.

Copy link
Member

commented Aug 19, 2019

/cc @Brar who worked around this area before (although it's not parameter derivation).

@jlareo can you please submit a minimal code sample that reproduces the issue?

@jlareo

This comment has been minimized.

Copy link
Author

commented Aug 19, 2019

using (NpgsqlConnection conn = this.GetConnection())
{
                    NpgsqlCommand npgsqlCommand = new NpgsqlCommand("SELECT id as myid, column as mycolumn from table", conn);
                    NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(npgsqlCommand);
                    NpgsqlCommandBuilder builder = new NpgsqlCommandBuilder(adapter);

                    // The generated query inside updateCommand will have an invalid query because the aliases are used
                    // The same problem is also in the insert and delete command
                    var updateCommand = builder.GetUpdateCommand();
}

@roji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.