Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android内容提供商查询生成器_Android_Sqlite_Android Contentprovider - Fatal编程技术网

android内容提供商查询生成器

android内容提供商查询生成器,android,sqlite,android-contentprovider,Android,Sqlite,Android Contentprovider,我有变量,每个变量都有可能为空。我使用这些来创建我的参数: String[] arguments = {argClassOfExercise, argPeriodOfPeriodisation, argAgeGroup, argPrDistanceGroup, argVo2Max}; 并定义我使用的WHERE子句 String selection = "catalog.ex_class = ? AND catalog.period = ? AND catalog.age_group = ? A

我有变量,每个变量都有可能为空。我使用这些来创建我的参数:

String[] arguments = {argClassOfExercise, argPeriodOfPeriodisation, argAgeGroup, argPrDistanceGroup, argVo2Max};
并定义我使用的WHERE子句

String selection = "catalog.ex_class = ? AND catalog.period = ? AND catalog.age_group = ? AND catalog.pr_comp_grouping = ? AND catalog.vo2max = ?";
将其全部放在我的游标装入器中:

CursorLoader cursorLoader = new CursorLoader(getActivity(), CatalogProvider.CONTENT_URI_TRANSLATION, projection, selection, arguments, null);
现在,在其中一个变量为空之前,所有这些都可以正常工作。因为没有一个数据库值将等于或为空字符串。如果特定变量为空,是否有可能排除WHERE子句

我知道你可以写一堆IF语句,但那会导致我写11条,我认为这不是很有效


任何想法都是受欢迎的

可以使用SQL表达式,如
(ex_class=?1或?1='')和…
,但这将非常低效

您应该动态构造SQL选择字符串和参数数组,只需为空字符串保留任何条目