确定SQLite中列的数据类型 [英] Determine data type of a column in SQLite

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

问题描述

我工作的一个Android应用程序,用户有不同的选项进行排序来自数据库中显示的数据。我传递给机器人query()方法是这样的,目前我的排序依据的字符串:

I'm working on an Android App where the user has different options for sorting the displayed data that comes from the database. Currently my orderBy string that I pass to Androids query() method looks like this:

"LOWER("+columnName+") ASC"

这里的问题是,如果由COLUMNNAME指定的列的数据类型为整数,调用LOWER(),它会导致它被按照字母顺序排序,即只根据最左边的数字,这当然不任何意义的数字数据。因此,我只是想申请LOWER()如果列的数据类型不是整数。我已经记如下语句:

The problem with this is that if the data type in the column specified by columnName is integer, calling LOWER() on it will cause it to be sorted alphabetically, i.e. based only on the leftmost digit, which of course doesn't make any sense for numeric data. Hence I only want to apply LOWER() if the data type of the column is not integer. What I have in mind is a statement like this:

"CASE WHEN [data type of columnName is integer] THEN "+columnName+" ASC ELSE LOWER("+columName+") ASC END"

在括号中的部分是什么,我不知道该怎么办。 SQLite的是否提供了一个函数来确定列的数据类型?

The part in the brackets is what I don't know how to do. Does SQLite provide a function to determine a column's data type?

推荐答案

难道你真的想要的的,或者是类型的类型值的? ( SQLite是动态类型,所以区别是很重要的。)

Do you really want the type of the column, or the type of the value? (SQLite is dynamically-typed, so the distinction is important.)

如果您希望是后者,你可以使用的typeof(COLUMNNAME)

If you want the latter, you can use typeof(columnName).

这篇关于确定SQLite中列的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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