获得从安卓pre-complie声明结果集 [英] to get resultset from pre-complie statement in android

查看:178
本文介绍了获得从安卓pre-complie声明结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了下面给出编译过的语句。现在的问题是如何得到的查询结果集。 这是我的code:

I have created complied statement given below. Now my question is how to get resultset of the query. Here is my code:

DataBaseHelper dbHelper=new DataBaseHelper(context);
dbHelper.createDataBase();
dbHelper.openDataBase();
SQLiteDatabase db = dbHelper.getWritableDatabase();
SQLiteStatement st=db.compileStatement("select taskid from task where taskdate=?");
st.bindString(1,"2011/09/05");
st.execute();

这工作没有任何错误。但我想给定查询的结果集。请帮助..

This works without any error. But I want the result set of the given query. Please help..

推荐答案

结果集是不可用的,至少就目前而言,sqlite的。这一切都取决于你想从ResultSet或ResultSetMetaData的,等什么信息,但也有获得几乎相同信息的其他方式。

The result set isn't available, at least for now, in sqlite. It all depends on exactly what information you want from the ResultSet or ResultSetMetaData, etc, but there are other means of obtaining almost the same information.

可以得到有关的列与下面的一个表,用来就好像它是一个SELECT的详细信息,和有关的列中的信息将presented:

You can get detailed information about the columns in a table with the following, used as if it were a SELECT, and the information about the columns will be presented:

pragma table_info(myTable) ;

请参阅 http://www.sqlite.org/pragma.html#pragma_table_info 了解更多信息。

如果您希望与某个选择的信息,您可以从游标的最终信息。请参见 http://developer.android.com/reference/android/database/Cursor。 HTML

If you want the information concerning a specific SELECT, you can get information from the resulting Cursor. See http://developer.android.com/reference/android/database/Cursor.html

例如,如果你想要的数据类型为列,可以在较新版本的Andr​​oid使用的getType()方法,或者使用了一系列的获取功能,以确定至少什么类型是可读的,这个可怕的code:

For example, if you want the type of data for a column, you can use the getType() method in the newer versions of Android, or use a series of "get" functions to determine at least what type is readable, with this horrible code:

            Cursor curs = db.rawQuery(sqlStr, null);
            int numberOfColumns = curs.getColumnCount();
            String []colNames = new String[numberOfColumns];
            String []colTypes = new String[numberOfColumns];
            for(int iCol=1; iCol<=numberOfColumns; iCol++) {
                colNames[iCol-1] = curs.getColumnName(iCol-1);
                colTypes[iCol-1] = null; //curs.getType(iCol);
            }
            while(curs.moveToNext()) {
                // this code assumes that the first row has the same data types
                // as the rest of the rows
                for(int iCol=1; iCol<=numberOfColumns; iCol++) {
                    String colName = colNames[iCol-1];
                    String colType = colTypes[iCol-1];
                    if(colType==null) {
                        // determine column type
                        try {
                            curs.getString(iCol-1);
                            colType = colTypes[iCol-1] = "text";
                        } catch (Exception ignore) {
                            try {
                                curs.getLong(iCol-1);
                                colType = colTypes[iCol-1] = "integer";
                            } catch (Exception ignore1) {
                                try {
                                    curs.getFloat(iCol-1);
                                    colType = colTypes[iCol-1] = "real";
                                } catch (Exception ignore2) {
                                    try {
                                        curs.getBlob(iCol-1);
                                        colType = colTypes[iCol-1] = "blob";
                                    } catch (Exception ignore3) {
                                        colType = colTypes[iCol-1] = "other";
                                    }
                                }
                            }
                        }
                    }
                    if("text".equals(colType)) {
                        ... curs.getString(iCol-1);
                    } else
                    if("real".equals(colType)) {
                        ... curs.getDouble(iCol-1);
                    } else
                    if("integer".equals(colType)) {
                        ... curs.getInt(iCol-1);
                    } else { // unknown type
                        ... colType+"-"+curs.getString(iCol-1);
                    }
                }
            }

其他信息,请以类似的方式,根据您的需要。

Other information is available in a similar manner, depending on your need.

这篇关于获得从安卓pre-complie声明结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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