發表文章

Coldfusion 多個 query 合併

簡單的用法: <cfquery name="q1" datasource="store1" blockFactor="100">  select * from sales_lists where sale_date = '2013/05/02' </cfquery> <cfquery name="q2" datasource="store2" blockFactor="100">  select * from sales_lists where sale_date = '2013/05/02' </cfquery> <cfquery name="datesales" dbtype="query">  select * from q1  union  select * from q2  order by sale_employee </cfquery> 把多個 DB 查詢用 in memory 查詢 union 起來。 那如果是 LOOP 迴圈連續查詢的 query 呢? 那就讓 query name 不一樣就可以了,然後再用LOOP把query union 起來 <cfloop from="1" to="#ListLen(employeelist)#" index="i">  <cfquery name="qresult#i#" datasource="db1">   select * from employee where employee_no = '#ListGetAt(i)#'  </cfquery> </cfloop> <cfquery name="combine" dbtype="query">   <cfloop fro

Coldfusion Query 的 Commit

最近由coldfusion 操作資料庫查詢時發生的一件事情 在sybase資料庫 做 Replication 的兩部資料庫: A-DB 與 B-DB, 本來,Web-Base的作業都連線在 B-DB 上,App-Base都連在 A-DB上 後來因為B-DB資料區有異常,就把 coldfusion 連線全部連到 A-DB , 接下來,慘事發生了...... A-DB 三不五時發生嚴重 lock ,導致所有作業都停擺,細查原因,發現: 1、全部 lock 都是來自 coldfusion 的 connection ,而且都是 jdbc 驅動連線 2、如果 coldfusion 使用 Sybase 驅動連線,不會發生此現象 3、ColdFusion 不管何種連線到 B-DB 都不太會發生 lock 過久問題 4、Web-Base 的查詢幾乎都是大範圍資料查詢 所以,查了一下設定發現,B-DB 的 lock 範圍強制設定在 row lock等級, Read isolation 屬 uncommit ,這樣的設定應該是為了提高網頁端大量查詢的效率 而 A-DB 屬於內部作業使用有需要極高的正確性,因此屬於page lock等級, Read isolation 屬 commit,因此 App-Base 開發時只要使用到 insert/update 一律要 commit/rollback才能繼續。 以上設定應該是因應公司營業型態調整的 所以,如果在不知道細節的情況下, Coldfusion 的 <cfquery> 指令下完之後 ,無論是Select / Insert / Update 都記得要下一行: <cftransaction action="commit" /> 或是 <cftransaction action="rollback" /> 才不至於出現過度lock狀況,當然這也是比較正統的撰寫習慣 至於 sybase driver connector 與 jdbc driver connector為什麼有不一樣的行為, 應該是差在 select 這個指令,sybase driver 對 select 指令會自動 commit 掉, 但是jdbc d

coldfusion query buildin functions

Method Signiture Return Type Method Signiture Description void queryName.first() jump to the first row of a query void queryName.last() jump to the last row of a query boolean queryName.isFirst() true if we are positioned at the first row boolean queryName.isLast() true if we are positioned at the first row boolean queryName.next() go to the next row, return true if there is a next row boolean queryName.previous() go to the previous row, return true if there is a previous row int queryName.findColumn(String name) get the internal zero based Column ID by name void sort(int columnID, boolean ascending) sort by a column, use findColumn to get the column id String getColumnTypeName(int columnID) gets the data type of a column, this one didn't work properly when I tested it, it would return NUMERIC for a field that was a varchar. There is a method called guessColumnType that was probably used to determine it, it guessed wrong. 資料參考來源

sort query in coldfusion

當我們需要用 coldfusion 查詢資料庫時會使用 cfquery 執行SQL指令 <cfquery name="allEmployee" datasource="myDB">  Select employee_no,employee_name,employee.duty  From employee  Where employee_retired = 'N' </cfquery> 當然,資料排序可以直接下 SQL 的 ORDER BY 來完成 但是,如果有特殊需求需要在 coldfusion 內(in memory)才排序的話 有兩種方式可以完成: 1、使用 cfquery 對已經存在的 query 再處理 <cfquery name="sortedEmployee" dbtype="query">  Select *  From allEmployee  Order By employee_name ASC </cfquery> 2、使用query專用指令 <cfset allEmployee.sort(allEmployee.findColumn("employee_name"),true)> 對於第2種用法,可能要非常小心 因為,adobe的 coldfusion 服務器與 Railo 的服務器有不同的使用法 (注意,我測試的adobe coldfusion 是 MX7,可能新的版本有變) 指令 Adobe Coldfusion MX7 Railo QueryName.sort(QueryName.findColumn("ColumnName"),true) 可 不可 QueryName.sort(2,true) 可 不可 QueryName.sort("ColumnName",true) 不可 可 QueryName.sort("2",true) 不可 不可

Operating the HTML table like Powerbuilder's DataWindow chapter 0

圖片
發想來自我接觸最久的程式語言 Powerbuilder,說真的跳通到其他語言時,會非常懷念它的DataWindow 物件。原因不外乎,它讓資料操作變得很簡單,甚至讓程式設計師變懶了。 但如果開始使用其他語言時,例如現在幾乎都要用網頁來工作,就發現網頁要操作資料真的不是那麼容易,尤其使用AJAX技術時,針對頁面的操作,每個工程師寫出來的方式大相逕庭,閱讀理解就變得重重。 有鑑於此,只好將自己理解datawidnow的部份,將其方法(method)實現到javascript裡面來。 盡力讓畫面表單操作變得簡單一些。 這樣的好處是,使用相同套件,程式碼閱讀起來清爽也易懂,比較容易除錯。 下面簡單介紹一下操作原理,與表格架構,DataWindow會用DW簡稱: 1、原則上一個類DW的架構如下: <div id="objid">  <table width="100">   <tr>    <th width="48" cn="field1">欄1標題</th>    <th width="18" cn="field2">欄2標題</th>    <th width="28" cn="field3">欄3標題</th>   </tr>  <table> </div> 這是一個標準table外面包著一個div層,而這個div層的id就是這個datawindow的名稱(datawindow name),一個DW結構(div)裡面只能有一個table存在。 這個結構很重要,因為接下來所有的操作都會參考這個結構的定義。 2、TH屬性的定義: cn :欄位名稱,必要的,英數字,其值就是代表了這個欄位的column name。 edit :編輯模式,選擇性,此屬性表示生成的資料可以編輯,其值(編輯模式)有:text / password / date / ddw / lbox。 key :關鍵欄,選擇性,其值為yes / no,yes=開啟編

使用coldfusion將HTML表格輸出成EXCEL檔案(使用者下載)

Coldfusion 的檔案輸出控制,主要有下面兩個指令 <cfcontent><cfheader> cfcontent 用來告訴瀏覽器等一下要輸出的內容是甚麼格式 cfheader 用來宣告傳輸資料的相關資訊 簡單的輸出測試  saveFileTest.cfm: <cfsetting enablecfoutputonly= "Yes" > <cfcontent type= "application/vnd.ms-excel; charset=big5" > <cfheader name= "Content-Disposition" value= "attachment;filename=ODR10001234567.xls" > <!--- office Excel Format Structure---> <cfoutput> <html xmlns:x= "urn:schemas-microsoft-com:office:excel" > <head> <meta http-equiv= "Content-Type" content= "text/html;charset=big5" > <!--[if gte mso 9]> <xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <!--- this line names the worksheet ---> <x:Name>訂單狀態</x:Name> <x:WorksheetOptions> <!--- these 2 lines are what works the magic ---> <x:Panes> </x:Panes> </x:WorksheetOptions>

a problem Read & ReadEx in Powerbuilder 10

Powerbuilder 10 (含)以後的版本,檔案的讀取分為 Read 與 ReadEx 兩個指令,按照說明文件的用法 ReadEx 支援 StreamMode! 讀取每次可以超過 32767 個位元組,並且支援 TextMode! 的讀取模式,算是很好用的;但是這次的問題卻出在使用 LineMode! 開啟檔案 時 PB10 的 Read 這個指令上: 先看看這段程式碼哪裡出了問題,我有純文字一份文件 A.txt (ANSI編碼)內容為: 數據窗口揭秘:未公開的數據窗口事件 (作者:Mark Brown) 到目前為止,PB的數據窗口控件仍是PB眾多控件中功能最強大,最複雜的控件。 數據窗口固有的行為 然後利用下面這段程式碼讀取內容並顯示在 mle_1(MultiLine Editor)上面 integer li_fn string ls_str mle_1.text = "" li_fn = FileOpen("A.txt",LineMode!,Read!) if li_fn > 0 then //逐行讀取並顯示在mle_1上面 do while FileRead (li_fn , ls_str) >= 0 mle_1.text += ls_str +"~r~n" loop FileClose(li_fn) end if mle_1物件上的顯示內容: 數據窗口揭秘:未公開的數據窗口事件 的數據窗口事件 事件 (作者:Mark Brown) ) 到目前為止,PB的數據窗口控件仍是PB眾多控件中功能最強大,最複雜的控件。 件中功能最強大,最複雜的控件。 複雜的控件。 鞳C 數據窗口固有的行為 的行為 發現了嗎?讀取出的內容怪怪的,幾乎每一行後段文字都重複被讀出,導致整個內容大亂。 但是,這段程式碼如果放在 PB6、PB7、PB8、PB9 執行,卻一點問題就沒有。 整個詭異到不行。 但是如果是英數文內容的檔案,不管哪個版本 PB6 or PB10 就完全不會有問題,測試檔案內容如下: calculate the height of the element and divid