在SQLite和Android中使用列作为选择参数
如何使用列作为查询的一部分 我在SQliteStudio中使用原始SQLite命令完成了这项工作在SQLite和Android中使用列作为选择参数,android,sqlite,Android,Sqlite,如何使用列作为查询的一部分 我在SQliteStudio中使用原始SQLite命令完成了这项工作 select _id, docholder, notes, docnumber, validto, doctype from documentslist where replaced <> 1 and validto < (((strftime('%s', 'now')*1000)) + (86400000 * warningin)) 从文档列表中选择_id、docholder、
select _id, docholder, notes, docnumber, validto, doctype from documentslist where replaced <> 1 and validto < (((strftime('%s', 'now')*1000)) + (86400000 * warningin))
从文档列表中选择_id、docholder、notes、docnumber、validto、doctype,其中替换了1和validto<((strftime(“%s”,“now”)*1000))+(86400000*warningin))
但Android Studio中的以下一项不起作用
private void showList(){
mDbHelper = new DocumentsDbHelper(this);
db = mDbHelper.getReadableDatabase();
String[] projection = {
DocumentEntry._ID,
DocumentEntry.COLUMN_DOC_HOLDER,
DocumentEntry.COLUMN_NOTES,
DocumentEntry.COLUMN_DOC_NUMBER,
DocumentEntry.COLUMN_VALID_TO,
DocumentEntry.COLUMN_DOC_TYPE
};
String selection = DocumentEntry.COLUMN_EXPIRED + " <> ? AND " + DocumentEntry.COLUMN_VALID_TO + " < ";
String[] selectionArg = {"1", String.valueOf(((System.currentTimeMillis()) + (86400000 * Integer.parseInt(DocumentEntry.COLUMN_WARN_IN))))};
String setOrder = DocumentEntry.COLUMN_VALID_TO + " ASC";
Cursor cursor = db.query(
DocumentEntry.TABLE_NAME,
projection,
selection,
selectionArg,
null,
null,
setOrder
);
private void showList(){
mDbHelper=新文件SDBHELPER(本文件);
db=mDbHelper.getReadableDatabase();
字符串[]投影={
文档输入。\u ID,
DocumentEntry.COLUMN\u DOC\u持有者,
DocumentEntry.COLUMN_注释,
DocumentEntry.COLUMN\u DOC\u编号,
DocumentEntry.COLUMN\u有效\u至,
DocumentEntry.COLUMN\u DOC\u类型
};
字符串选择=DocumentEntry.COLUMN_EXPIRED+”?和“+DocumentEntry.COLUMN_VALID_TO+”<”;
String[]selectionArg={“1”,String.valueOf(((System.currentTimeMillis())+(86400000*Integer.parseInt(DocumentEntry.COLUMN\u WARN\u IN))));
字符串setOrder=DocumentEntry.COLUMN\u有效\u至+“ASC”;
Cursor=db.query(
DocumentEntry.TABLE_名称,
投影,
选择,
选择G,
无效的
无效的
设定顺序
);
我认为您的问题很可能是,您可能试图将字符串转换为整数,其中指定了integer.parseInt(DocumentEntry.COLUMN\u WARN\u IN)
(也就是说,除非DocumentEntry.COLUMN\u WARN\u IN解析为整数,否则它可能解析为warning)
此外,您还忽略了包含第2个参数,因此无法包含该参数,并且可能会导致参数不匹配问题,因为您提供了两个参数,但只要求使用一个参数
我建议使用:-
String selection = DocumentEntry.COLUMN_EXPIRED + " <> ? AND " + DocumentEntry.COLUMN_VALID_TO + " < (((strftime('%s', 'now')*1000)) + (86400000 * warningin))";
String[] selectionArg = {"1"};
- 注意这是原则代码,尚未测试,因此可能存在键入错误
String selection = DocumentEntry.COLUMN_EXPIRED +
" <> ? AND " +
DocumentEntry.COLUMN_VALID_TO +
" < (((strftime('%s', 'now')*1000)) + (86400000 * " +
DocumentEntry.COLUMN_WARN_IN +
"))";
String[] selectionArg = {"1"};