2016-06-16 22 views
0

我有一個sqlite數據庫包含「筆記」的客戶。數據庫設計非常簡單,包含一張表格用於記錄,一個「鏈接」表格,將客戶和名爲customer_note的筆記與客戶表相關聯。 notes表有一個id字段,customer_note有customer_id和note_id(一對多),而customers表也有一個id。TSQLQuery和數據感知組件的更新

的查詢,以獲取筆記選定的客戶是:

SELECT * FROM note n 
INNER JOIN customer_note cn 
ON (cn.note_id = n.id) 
WHERE customer_id = :customerID 
ORDER BY created_on ASC 

查詢是在客戶端數據集被滾動的情況下執行,即

customersCDSAfterScroll() 
{ 
int cID = customerCDS->FieldByName("id")->AsInteger; 
customerNotesQ->Params->ParamByName("customerID")->AsInteger = bID; 
customerNotesQ->Open(); 

//Get notes 
string note = stdstr(customerNotesQ->FieldByName("note")->AsString); 
Log(lInfo) << "Note is: "<<note; 
customerNotesQ->Close(); 

}

該查詢由DataSetProvider,ClientDataSet和DataSource組件引用。在UI上,TDBLookupListbox正在接收數據。

問題是,TDBLookpListbox顯示所有客戶的所有筆記。 在日誌消息中,從上面的代碼中,我可以看到查詢似乎正確地完成了它的工作。

有什麼想法出錯了?

回答

0

由於查詢的結果只包含param正確過濾的註釋,因此該查詢不可能是向列表框提供數據的註釋。

因此,答案可能是您錯誤地配置了DBLookupListBox併爲其指定了另一個數據源,一個指向不過濾查詢的查詢。

此外,當您分配參數值並打開查詢時,我們無法看到customerNotesQ是否確實關閉。但是,如果不是,該參數將不起作用。