Database 我必须能够根据用户在edittext上输入查询并单击查询按钮,从sqlite输出和显示数据
以下是我应该能够检索并显示相应数据的所有查询。我需要有关sytax和代码的帮助。当用户进入查询按钮时,所有这些都应该显示在另一个xml中Database 我必须能够根据用户在edittext上输入查询并单击查询按钮,从sqlite输出和显示数据,database,sqlite,android-studio,android-sqlite,Database,Sqlite,Android Studio,Android Sqlite,以下是我应该能够检索并显示相应数据的所有查询。我需要有关sytax和代码的帮助。当用户进入查询按钮时,所有这些都应该显示在另一个xml中 /*1a. Retrieve full details of all suppliers; that is, make a list of all attributes used to describe each supplier for every supplier in s. SELECT * FROM s; 1b. Retrieve full de
/*1a. Retrieve full details of all suppliers; that is, make a list of all attributes used to describe each supplier for every supplier in s.
SELECT * FROM s;
1b. Retrieve full details of all parts.
SELECT * FROM p;
1c. Retrieve full details of all suppliers-of-parts. (Hint This query should test the vertical and horizontal scrolling capabilities of your app!)
SELECT * FROM sp;
2. Retrieve sno and sname for all suppliers based in "London".
SELECT sno,s.sname FROM s WHERE ( city = 'London' );
3. Is part "P07" still manufactured in "London"?
SELECT pno,city FROM p WHERE pno = 'P07';
4. What is the pno and pname of all parts that cost more than $1.00?
SELECT pno,pname FROM p
WHERE ( cost > 1.00 );
5. Retrieve full details for parts supplied by supplier "S01".
SELECT p.pno,p.pname,p.cost,p.city FROM p,sp
WHERE ( (p.pno = sp.pno) AND (sp.sno = 'S01') );
6. Retrieve a list of each distinct part city. Does this eliminate duplicate cities from the list?
SELECT DISTINCT city FROM p;
7. Retrieve the pno, pname, and city of parts manufactured in "Dallas", "Paris", or "London".
SELECT pno,pname,city FROM p WHERE ( city IN ('Dallas','Paris','London') );
8. Retrieve the pno and pname of each part and sno and sname of all suppliers who supply qty ≥ 100 (100 or more) of any one part.
SELECT DISTINCT p.pno,p.pname,s.sno,s.sname FROM s,p,sp
WHERE ( (s.sno = sp.sno) AND (p.pno = sp.pno) AND (sp.qty >= 100) );
9. Retrieve sname of all suppliers who supply less than 400 of pno = "P02", but only if the part and the supplier have identical city attributes.
SELECT s.sname FROM s,p,sp
WHERE ( (s.sno = sp.sno) AND (p.pno = sp.pno) AND
(sp.pno = 'P02') AND (sp.qty < 400) AND (p.city = s.city)
);
10. What is the pno of parts with pname = "Nut" or pname = "Screw"?
SELECT pno FROM p WHERE ( pname IN ('Nut','Screw') ); */
我将通过以下组合确定语法:-
query
进行选择,如果合适(有时方便方法可能无法处理,在这种情况下,您可能很少需要使用rawQuery
方法))- 2将是一个sinlge元素字符串数组,该元素作为字符串s.sname
String table = "s,p,sp";
String[] columns = new String[]{"s.sname"};
String whereclause = "( (s.sno = sp.sno) AND (p.pno = sp.pno) AND (sp.pno = '?') AND (sp.qty < ?) AND (p.city = s.city));
- 3将是
减去WHERE子句,参数为?标记,其中((s.sno=sp.sno)和(p.pno=sp.pno)和 (sp.pno='P02')和(sp.qty<400)和(p.city=s.city) )
String table = "s,p,sp";
String[] columns = new String[]{"s.sname"};
String whereclause = "( (s.sno = sp.sno) AND (p.pno = sp.pno) AND (sp.pno = '?') AND (sp.qty < ?) AND (p.city = s.city));
然后,您可以在列表视图中显示供应商名称列表(请注意,在完成活动时,您应该关闭mCursor,例如,通过跳过onDestroy方法以包括mCursor.close()
)。
注意这个例子假设
mCursor
被定义为一个类变量,因此有足够的范围。)@MikeT你知道吗?我知道并且已经回答了。然而,StackOverflow是关于回答特定问题,而不是提供代码编写服务。因此,答案指向了解决您提出的众多问题的方法。
String[] columns = new String[]{"s.sname"};
String whereclause = "( (s.sno = sp.sno) AND (p.pno = sp.pno) AND (sp.pno = '?') AND (sp.qty < ?) AND (p.city = s.city));
public Cursor getLowUsageSupplierNamesForAPart(String partno, int Quantity) {
String table = "s,p,sp";
String[] columns = new String[]{"s.sname"};
String whereclause = "( (s.sno = sp.sno) AND (p.pno = sp.pno) AND (sp.pno = '?') AND (sp.qty < ?) AND (p.city = s.city));
String[] whereargs = new String[]{partno,String.valueOf(quantity};
SQLiteDatbase db = this.getWriteableDatabase();
return db.query(
table,
columns.
whereclause,
whereargs,
null,null,null
);
}
mCursor = MyDB.getLowUsageSupplierNamesForAPart("p02",400);