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

CommandBehavior.SchemaOnly not working as expected. #1463

Open
guptaheena opened this issue Mar 18, 2024 · 3 comments
Open

CommandBehavior.SchemaOnly not working as expected. #1463

guptaheena opened this issue Mar 18, 2024 · 3 comments
Labels
waiting for answer Needs more information from the bug reporter

Comments

@guptaheena
Copy link

guptaheena commented Mar 18, 2024

Software versions
MySqlConnector version:
Server type (MySQL, MariaDB, Aurora, etc.) and version: MySQL

Describe the bug
The SchemaOnly command behaviour is not working as expected for DML commands such as insert/update.
When executing CommandBehaviour.SchemaOnly on insert/update statements, it executes the command in the backend which is not the desired behaviour for this command.

Code sample
string query =""
using var command = new MySqlCommand(query, connection) { CommandTimeout = connection.ConnectionTimeout };
MySqlDataReader mysqlDataReader = (MySqlDataReader)await command.ExecuteReaderAsync(CommandBehavior.SchemaOnly, requestCancellationToken).ConfigureAwait(false);

Expected behavior
Only the schema of the table should be returned. The query should not be executed.

@bgrainger
Copy link
Member

When executing CommandBehaviour.SchemaOnly on insert/update statements, it executes the command in the backend which is not the desired behaviour for this command.

What should it do instead?


CommandBehavior.SchemaOnly is implemented via sql_select_limit, which affects SELECT queries only. Its behavior is undefined for other types of queries.

@guptaheena
Copy link
Author

When executing CommandBehaviour.SchemaOnly on insert/update statements, it executes the command in the backend which is not the desired behaviour for this command.

What should it do instead?

Shouldn't it be functioning in the same way how it is working SQL. In SQL CommandBehaviour.SchemaOnly works for select, insert, update as well.

so why is it undefined in MySQL? Also, is there any other way to get the schema for insert and update statements?

@bgrainger
Copy link
Member

Shouldn't it be functioning in the same way how it is working SQL. In SQL CommandBehaviour.SchemaOnly works for select, insert, update as well.

MySQL Server is a different database than Microsoft SQL Server; the "same" features may be implemented slightly differently.

Also, is there any other way to get the schema for insert and update statements?

What information do you want to retrieve? If the query were INSERT INTO Users(Email) VALUES(@Email) or UPDATE Users SET Email = @Email WHERE UserId = @UserId what schema do you want to retrieve?

Can MySqlConnection.GetSchema provide the information you want?

Can you provide a concrete example of what you are hoping to accomplish?

@bgrainger bgrainger added the waiting for answer Needs more information from the bug reporter label Apr 14, 2024
@bgrainger bgrainger changed the title CommandBeaviour - SchemaOnly not working as expected. CommandBehavior.SchemaOnly not working as expected. Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for answer Needs more information from the bug reporter
Development

No branches or pull requests

2 participants