Android的SQLite的查询与整型参数 [英] Android SQLite query with integer parameter

查看:192
本文介绍了Android的SQLite的查询与整型参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的<一个href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#query%28java.lang.String,%20java.lang.String%5B%5D,%20java.lang.String,%20java.lang.String%5B%5D,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%29\"相对=nofollow>为SQLiteDatabase.query文档说,selectionArgs两个将被绑定为字符串。

The documentation for SQLiteDatabase.query says that the selectionArgs will be bound as strings.

什么是一个整数参数执行查询的推荐方式?

What is the recommended way to perform a query with an integer parameter?

它是这样的:

int value = 10;
Cursor cursor = database.query(
    "TABLE_X", 
    new String[] { "COLUMN_A", "COLUMN_B" },
    "COLUMN_C = " + value,
    null,
    null,
    null,
    null);

或者是这样的:

int value = 10;
Cursor cursor = database.query(
    "TABLE_X", 
    new String[] { "COLUMN_A", "COLUMN_B" },
    "COLUMN_C = ?",
    new String[] { Integer.toString(value) },
    null,
    null,
    null);

或者其他什么东西?

Or something else?

感谢。

推荐答案

第二个选项是使用的查询方式的建议方式。

Second option with ? is the suggested way of using query method.

selectionArgs两个:您可以包括S IN的选择,将由值替换?
  从selectionArgs两个,以使他们出现在选择。该
  值将被绑定为字符串。

selectionArgs: You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.

这篇关于Android的SQLite的查询与整型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆