2015年12月7日 星期一

DataSource->Where

DataSource->Where Run-Time Property (PHP)

Syntax

object->DataSource->Where [=value]

This property stores all conditions that are eventually used in the WHERE clause of a query that selects, updates or deletes data from the database. Programmers can add their own conditions (preserving the SQL syntax) in one of the events triggered before the final query is built and executed (i.e. BeforeBuildSelect, BeforeBuildDelete, BeforeBuildUpdate).

在CodeCharge 的 help 裡面有這一段,他說設定了DataSource->Where 是儲存了  Select, update, delete  的 WHERE 子句。
程式設計師可以分別在 BeforeBuildSelect, BeforeBuildDelete, BeforeBuildUpdate 裡面,去設定 WHERE 子句。

結果,我一開始以為,只要在 BeforeBuildSelect 中設定了 WHERE 子句,就已經設定了所有的 WHERE 子句,結果一執行的結果,Select 出來的是我要的結果沒錯,但是,一執行 Update 就整個資料庫都被 Update ,就相當於沒有 Where 一樣。(  我在 Record 的定義中,並沒有設定 WHERE)。這並不是我要的結果。

後來經過測試的結果是:原來,我必須個別去設定 BeforeBuildUpdate  的 Where,以及 BeforeBuildDelete 的 Where 才會被正確的執行。

 CodeCharge的SELECT, UPDATE, DELETE 的 WHERE 子句是個別設定的!

沒有留言:

張貼留言

如何判斷現在FORM是在 insert mode? 還是 update mode?

只要用  if (empty({primary_key})) 就可以知道是否為新增模式了。 如果 {promary_key} 是空白的,那麼就是在新增模式;反之,就是更新模式。 以上。