config.maxReconnectionDelay)?config.maxReconnectionDelay:newDelay;};var LEVEL_0_EVENTS=['onopen','onclose','onmessage','onerror'];var reassignEventListeners=function(ws,oldWs,listeners){Object.keys(listeners).forEach(function(type){listeners[type].forEach(function(_a){var listener=_a[0],options=_a[1];ws.addEventListener(type,listener,options);});});if(oldWs){LEVEL_0_EVENTS.forEach(function(name){ws[name]=oldWs[name];});}};var ReconnectingWebsocket=function(url,protocols,options){var _this=this;if(options===void 0){options={};} var ws;var connectingTimeout;var reconnectDelay=0;var retriesCount=0;var shouldRetry=true;var savedOnClose=null;var listeners={};if(!(this instanceof ReconnectingWebsocket)){throw new TypeError("Failed to construct 'ReconnectingWebSocket': Please use the 'new' operator");} var config=getDefaultOptions();Object.keys(config).filter(function(key){return options.hasOwnProperty(key);}).forEach(function(key){return config[key]=options[key];});if(!isWebSocket(config.constructor)){throw new TypeError('Invalid WebSocket constructor. Set `options.constructor`');} var log=config.debug?function(){var params=[];for(var _i=0;_iconfig.maxRetries){emitError('EHOSTDOWN','Too many failed connection attempts');return;} if(!reconnectDelay){reconnectDelay=initReconnectionDelay(config);} else{reconnectDelay=updateReconnectionDelay(config,reconnectDelay);} log('reconnectDelay:',reconnectDelay);if(shouldRetry){setTimeout(connect,reconnectDelay);}};var connect=function(){log('connect');var oldWs=ws;ws=new config.constructor(url,protocols);connectingTimeout=setTimeout(function(){log('timeout');ws.close();emitError('ETIMEDOUT','Connection timeout');},config.connectionTimeout);log('bypass properties');for(var key in ws){if(['addEventListener','removeEventListener','close','send'].indexOf(key)<0){bypassProperty(ws,_this,key);}} ws.addEventListener('open',function(){clearTimeout(connectingTimeout);log('open');reconnectDelay=initReconnectionDelay(config);log('reconnectDelay:',reconnectDelay);retriesCount=0;});ws.addEventListener('close',handleClose);reassignEventListeners(ws,oldWs,listeners);ws.onclose=ws.onclose||savedOnClose;savedOnClose=null;};log('init');connect();this.close=function(code,reason,_a){if(code===void 0){code=1000;} if(reason===void 0){reason='';} var _b=_a===void 0?{}:_a,_c=_b.keepClosed,keepClosed=_c===void 0?false:_c,_d=_b.fastClose,fastClose=_d===void 0?true:_d,_e=_b.delay,delay=_e===void 0?0:_e;if(delay){reconnectDelay=delay;} shouldRetry=!keepClosed;ws.close(code,reason);if(fastClose){var fakeCloseEvent_1={code:code,reason:reason,wasClean:true,};handleClose();ws.removeEventListener('close',handleClose);if(Array.isArray(listeners.close)){listeners.close.forEach(function(_a){var listener=_a[0],options=_a[1];listener(fakeCloseEvent_1);ws.removeEventListener('close',listener,options);});} if(ws.onclose){savedOnClose=ws.onclose;ws.onclose(fakeCloseEvent_1);ws.onclose=null;}}};this.send=function(data){ws.send(data);};this.addEventListener=function(type,listener,options){if(Array.isArray(listeners[type])){if(!listeners[type].some(function(_a){var l=_a[0];return l===listener;})){listeners[type].push([listener,options]);}} else{listeners[type]=[[listener,options]];} ws.addEventListener(type,listener,options);};this.removeEventListener=function(type,listener,options){if(Array.isArray(listeners[type])){listeners[type]=listeners[type].filter(function(_a){var l=_a[0];return l!==listener;});} ws.removeEventListener(type,listener,options);};};module.exports=ReconnectingWebsocket;},{}],2:[function(require,module,exports){'use strict';Object.defineProperty(exports,"__esModule",{value:true});exports.WebSocketBridge=undefined;var _extends=Object.assign||function(target){for(var i=1;iconfig.showChars+config.minHideChars){var c=content.substr(0,config.showChars);if(c.indexOf('<')>=0) {var inTag=false;var bag='';var countChars=0;var openTags=[];var tagName=null;for(var i=0,r=0;r<=config.showChars;i++){if(content[i]=='<'&&!inTag){inTag=true;tagName=content.substring(i+1,content.indexOf('>',i));if(tagName[0]=='/'){if(tagName!='/'+openTags[0]){config.errMsg='ERROR en HTML: the top of the stack should be the tag that closes';}else{openTags.shift();}}else{if(tagName.toLowerCase()!='br'){openTags.unshift(tagName);}}} if(inTag&&content[i]=='>'){inTag=false;} if(inTag){bag+=content.charAt(i);} else{r++;if(countChars<=config.showChars){bag+=content.charAt(i);countChars++;}else {if(openTags.length>0) {for(j=0;j';} break;}}}} c=$('
').html(bag+''+config.ellipsesText+'').html();}else{c+=config.ellipsesText;} var html='
'+c+'
'+content+'
'+config.moreText+'';$this.html(html);$this.find(".allcontent").hide();$('.shortcontent p:last',$this).css('margin-bottom',0);}});};})(jQuery);function format(text){return text.replace(/{i}(.*?){\/i}/g,"$1").replace(/{b}(.*?){\/b}/g,"$1").replace(/{u}(.*?){\/u}/g,"$1").replace(/{\^}(.*?){\/\^}/g,"$1").replace(/{overline}(.*?){\/overline}/g,"$1").replace(/{s (\d+)}(.*?){\/s}/g,"$2").replace(/{c (\d+),(\d+),(\d+)}(.*?){\/c}/g,"$4").replace(/{c (\w+)}(.*?){\/c}/g,function(){var color=Controller.COLORS[arguments[1]]||'',contents=arguments[2] return""+contents+"";}).replace(/{newline}/g,"
").replace(/{n}/g,"
").replace(/{p}(.*?){\/p}/g,"

$1

").replace(/{fraction}([^\[][^\/s]*\s)?((\[(.*?)\])|([^\/]+))\/(\[(.*?)\]|([^{]+)){\/fraction}/g,function(){var coefficient=(arguments[1]||'').trim(),numerator=arguments[4]||arguments[5]||'',denominator=arguments[7]||arguments[8]||'';return''+ coefficient+''+''+numerator+''+''+denominator+''+''+'';}).replace(/{q}(.*?){\/q}/g,"$1").replace(/{em}(.*?){\/em}/g,"$1").replace(/{note}(.*?){\/note}/g,"$1").replace(/{hint (\d+)}(.*?){\/hint}/g,'$2 ');} function intComma(val){while(/(\d+)(\d{3})/.test(val.toString())){val=val.toString().replace(/(\d+)(\d{3})/,'$1'+','+'$2');} return val;} function getCookie(cname){var name=cname+"=";var ca=document.cookie.split(';');for(var i=0;i=65281&&str.charCodeAt(i)<=65374){tmp+=String.fromCharCode(str.charCodeAt(i)-65248)}else if(str.charCodeAt(i)==12288){tmp+=' ';}else{tmp+=str[i];}} return tmp;}

C# 遇到的关于MySq操作报错l的问题


在C#中用MySql语句删除数据库的某条记录时一直报错,代码如下:

   
  String queryString = String.Format("delete from {0} where log_level = '{2}' and message='{1}'", ip, model.Message, type);
  
result = m_DB.ExecuteStoreCommand(queryString);

错误内容为:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1.0' encoding='utf-8' ?>'' at line 1
MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1.0' encoding='utf-8' ?>'' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at System.Data.Objects.ObjectContext.ExecuteStoreCommand(String commandText, Object[] parameters)
还求高手帮忙指导一下

c# mysql

小早川黑二 11 years, 10 months ago

check the manual that corresponds to your MySQL server version for the right syntax to use near '1.0' encoding='utf-8' ?>'' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()

以上是你的部分错误信息,指示你SQL语句错误在第一行,"'1.0' encoding='utf-8' ?>''"附近。这似乎是一段声明,所以很可能是你的三个参数ip, model.Message, type之一发生了错误,解决的办法是在VS中加入断点,断点加在result = m_DB.ExecuteStoreCommand(queryString)这句上,然后等程序运行到这里的时候看看queryString是什么,是否符合你的预期,即可修正。

如果你本意就是写出一条带有“'1.0' encoding='utf-8' ?>''”这样的SQL语句的话,应该注意,在MYSQL中,单引号被当做字符串的结束标志,如果本身SQL语句中包含单引号,请使用转义,将单引号置换为两个单引号即可。例如: insert into tableA (field) values ('abc''de')
在C#中,可以使用string的Replace方法来完成该置换操作。

xzafe answered 11 years, 10 months ago

Your Answer