开发者

@ is not an in parameter in my mysql query

开发者 https://www.devze.com 2022-12-17 03:01 出处:网络
I\'m running this query: LOAD DATA INFILE \'SomePath\' INTO TABLE SomeTable FIELDS TERMINATED BY \',\' ENCLOSED BY \'\"\' LINES TERMINATED BY \'\\r\\n\'

I'm running this query:

LOAD DATA INFILE 'SomePath' INTO TABLE SomeTable 
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' 
(column1,column2,@Column3Value) 
SET column3 = CAST(@Column3Value AS UNSIGNED);

I'm using the @Column3Value param because this field is a bit type field and this is the only way to do a loading from a file to this type of field. This query works fine in MySQL Query Browser.

The problem is when I run开发者_JS百科 this query from my .net application using the .net connector. I get an error that I'm not supplying the @Column3Value parameter, but the thing is that I shouldn't supply anything. How can I tell the query that @Column3Value is not an in parameter?

any suggestions?


Liron, add 'AllowUserVariables=true' to your connection string - this will cause your user variable to be recognized as such as not an input parameter.

This happens because the MySql connector code (as of 6.4) tries to determine whether a given token is an input parameter by looking for '?' and '@' at the beginning of the string - if 'AllowUserVariables' is set to true, it'll ignore variables that start with '@' while serializing the parameter list. Check out the code for MySql.Data.MySqlClient.Statement to see this for yourself if you're interested.

p.s. This was posted two months ago, not sure if this is useful to you anymore - I found the question while looking for an answer to a question I had myself. >_<


the at symbol is considered a bound parameter in some interfaces. you can escape it with a backslash (\), but make sure the backslash is preserved when passed to the underlying query function and not lost...

0

精彩评论

暂无评论...
验证码 换一张
取 消