你如何从游标类型? [英] How do you get the type from a cursor?

查看:118
本文介绍了你如何从游标类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的javadoc表明android.database.Cursor具有的getType(int)方法。但是,当我尝试调用这个方法时,Eclipse给了我一个错误说没有一种方法存在。是什么给了?

The javadocs indicate that android.database.Cursor has a getType(int) method. However, when I try to call this method, Eclipse gives me an error saying no method exists. What gives?

推荐答案

您针对哪些版本的Andr​​oid?该的getType()方法仅适用于3.0及更高版本。

What version of Android are you targeting? The getType() method applies only to v3.0 and later.

编辑:假设你的目标的Andr​​oid pre V3.0版本,那么一个可能的黑客发现一个表中的每一列的类型将是查询SQLITE_MASTER表找到创建数据。

Assuming you're targeting pre v3.0 versions of Android then a possible 'hack' to discover the type of each column within a table would be to query the sqlite_master table to find the CREATE data.

SELECT sql FROM sqlite_master

这是pretty的讨厌的,但如果你真的需要找到的类型,那么你可以扩展SQLiteCursor并添加自己的的getType(INT参数:columnIndex)方法。

您可以执行一次性查询,当光标第一次访问表然后解析创建 SQLITE_MASTER 表C>从 SQL 列语句,并保存在'类型'的 INT []

You could perform a one-off query to the sqlite_master table when the cursor first accesses a table then parse the CREATE statement from the sql column and store the 'types' in an int[].

的getType(INT参数:columnIndex)您只需返回值的 INT [] 根据参数:columnIndex

In the getType(int columnIndex) you would simply return the value of your int[] based on columnindex.

正如我所说的,一个黑客位,但它的工作。

As I said, bit of a hack but it would work.

这篇关于你如何从游标类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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