Skip to content

MySqlBulkCopy can't load column that starts with @ #1365

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

Closed
bgrainger opened this issue Sep 3, 2023 · 0 comments
Closed

MySqlBulkCopy can't load column that starts with @ #1365

bgrainger opened this issue Sep 3, 2023 · 0 comments
Labels
Milestone

Comments

@bgrainger
Copy link
Member

using (var cmd = new MySqlCommand("""
	drop table if exists test;
	create table test(`@a` int);
	insert into test values(1);
	""", conn))
	cmd.ExecuteNonQuery();
	
var bulkCopy = new MySqlBulkCopy(conn)
{
	DestinationTableName = "test",
};

var dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn() { DataType = typeof(int) });
dataTable.Rows.Add(new object[] { 2 });

bulkCopy.WriteToServer(dataTable);

using (var cmd = new MySqlCommand("select * from test;", conn))
using (var reader = cmd.ExecuteReader())
{
	while (reader.Read())
		Console.WriteLine($"{reader.IsDBNull(0)} {reader.GetValue(0)}"); // second row is NULL
}

The leading @ in the column name is detected as a variable; it should be quoted as an identifier instead.

Related to https://github.com/mysql-net/MySqlConnector/security/code-scanning/3.

@bgrainger bgrainger added the bug label Sep 3, 2023
@bgrainger bgrainger added this to the 2.3 milestone Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant