我想使用多个where条件从Firebase实时数据库中获取数据。
databaseReference = FirebaseDatabase.getInstance().getReference("tblSalesDetails");
Query query = databaseReference.child("authenticationId").child("9591290928").orderByChild("invoiceNo").equalTo(str_invoice_no);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int i=0;
for(DataSnapshot snap : dataSnapshot.getChildren()) {
Log.d("tag","item ID:");
TableRow tr = new TableRow(AddItemToSale.this);
CheckBox Box = new CheckBox(AddItemToSale.this);
tr.setLayoutParams(getLayoutParams());
Log.d("tag","item ID:"+snap.child("itemId").getValue(String.class));
tr.addView(getTextView("0", String.valueOf(i + 1), ContextCompat.getColor(AddItemToSale.this, R.color.colorPrimary), Typeface.NORMAL, R.drawable.high));
tr.addView(getTextView((snap.child("sdId").getValue(String.class)),snap.child("itemId").getValue(String.class), ContextCompat.getColor(AddItemToSale.this, R.color.colorPrimary), Typeface.NORMAL,R.drawable.high));
tr.addView(getTextView((snap.child("sdId").getValue(String.class)),snap.child("amount").getValue(String.class), ContextCompat.getColor(AddItemToSale.this, R.color.colorPrimary), Typeface.NORMAL,R.drawable.high));
tr.addView(getTextView((snap.child("sdId").getValue(String.class)),snap.child("discAmount").getValue(String.class), ContextCompat.getColor(AddItemToSale.this, R.color.colorPrimary), Typeface.NORMAL, R.drawable.high));
tr.addView(getTextView((snap.child("sdId").getValue(String.class)),snap.child("taxName").getValue(String.class), ContextCompat.getColor(AddItemToSale.this, R.color.colorPrimary), Typeface.NORMAL, R.drawable.high));
tbl_sales.addView(tr, getTblLayoutParams());
i++;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 0 :(得分:0)
您所使用的查询仅给您一张invoiceNo
属性等于str_invoice_no
的发票。您无法在Firebase实时数据库中使用多个“ WHERE”子句。您可以在Firebase实时数据库中的多个值上过滤属性的唯一解决方案是,如果这些发票号在一定范围内。例如,您可以使用以下查询获取与某些发票编号匹配的所有发票:
databaseReference = FirebaseDatabase.getInstance().getReference("tblSalesDetails");
Query query = databaseReference.child("authenticationId").child("9591290928")
.orderByChild("invoiceNo")
.startAt("startInvoiceNo")
.endAt("endInvoiceNo");
请注意,Firebase实时数据库或新的Cloud Firestore数据库中都无法将多个单独的值传递到查询中。您将必须为每个值执行一个单独的查询,然后在客户端将它们合并。
还请检查以下帖子中弗兰克·范·普菲伦的回答:
对于Firestore,也请检查我从这篇文章中得到的答案: