Tuesday, October 13, 2009 - 文章

OracleCommand.CommandText的換行符號處理

使用System.Data.OracleClient連線Oracle執行指令,發現以下的程式寫法會引發奇怪的錯誤:

using (OracleConnection cn = new OracleConnection(cnStr))
{
    cn.Open();
    OracleCommand cmd = new OracleCommand(@"
begin
update myJobQueue set SendFlag = 'X' where JobId = 'XXX';
update myJobQueue set SendFlag = 'D' where JobId = 'ZZZ';
end;
", cn);
    cmd.ExecuteNonQuery();
    cn.Close();
}

ORA-06550: line 1, column 1:
PLS-00103: Encountered the symbol "" when expecting one of the following:

  begin case declare exit for function goto if loop mod null
  package pragma procedure raise return select separate type
  update while with <an identifier>
  <a double-quoted delimited-identifier> <a bind variable> <<
  form table call close current define delete fetch lock insert
  open rollback savepoint set sql execute commit forall merge
  library OPERATOR_ <a single-quoted SQL string> pipe

Oracle抱怨遇到**空字串**??

指令非常單純,看不出任何可疑之處! 不意外地,將指令文字Copy到Toad或其他Oracle Client程式測試,都可以成功執行。

幾經推敲,終於找出原因來,原來錯誤是字串夾帶的換行符號所引起的(這讓我想起上次在SSMS也有類似遭遇)。測試結果,對字串來個Replace("\r", ""),只留下\n,問題就可以排除囉!

jQuery-將網頁元素名稱標示出來

不知有沒有人跟我有一樣的困擾? 步入中年後,腦容量似有變小趨勢,每次寫網頁Client Script時,<input>, <select>的欄位名稱老記不住,要用時總是要回HTML Source或用IE Dev Tools去查,查完了一轉頭又忘了,再不然就是切換回Script Editor時搞不清楚剛才寫到哪裡。幾番折騰下來,效率很差,心情很糟。(老了,不中用了~~ 不中用了~~ 不~中~用~了了了了~~~)

於是我寫了以下的jQuery Plugin,試圖把所有的輸入元素id直接顯示在網頁上,方便對照,也試圖挽救我岌岌可危的事業。

$.fn.showElemId = function(bgc, fc) {
    return this.each(function() {
        var $elem = $(this);
        //if (!$elem.is(":visible")) return;
        var pos = $elem.offset();
        var html = "<span style='position: absolute; z-index: 999; top: " +
        (pos.top - 15) + "px; left: " + pos.left +
        "px; background-color: " + (bgc || "red") + "; color: " +
        (fc || "white") + "; font-size: 11px; line-height: 12px; padding: 1px;'>" +
        (this.id || "----") +
        "</span>";
        $("body").append(html);
    });
};
/* 使用範例: $(":text,select").showElemId(); */

用Hotmail的註冊畫面做個示範(只查:text,select,不包含:button,:password),如下圖所示,輸入欄位元素名稱一目瞭然,列印出來,就不用每次去HTML Source裡找半天了,真是中年程式開發人員的福音呀~~~

搜尋

Go

<October 2009>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
 
RSS
【工商服務】
最新回應

Tags 分類檢視
關於作者

一個醉心技術又酷愛分享的Coding魔人,十年的IT職場生涯,寫過系統、管過專案, 也帶過團隊,最後還是無怨無悔地選擇了技術鑽研這條路,近年來則以做一個"有為的中年人"自許。

文章典藏
其他功能

這個部落格


BlogLook Score and Rank

Syndication