Skip to content Skip to sidebar Skip to footer

To Get Resultset From Pre-complie Statement In Android

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.

Solution 1:

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.

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) ;

See http://www.sqlite.org/pragma.html#pragma_table_info for more information.

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

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 = newString[numberOfColumns];
            String []colTypes = newString[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 rowsfor(int iCol=1; iCol<=numberOfColumns; iCol++) {
                    String colName = colNames[iCol-1];
                    String colType = colTypes[iCol-1];
                    if(colType==null) {
                        // determine column typetry {
                            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);
                    } elseif("real".equals(colType)) {
                        ... curs.getDouble(iCol-1);
                    } elseif("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.

Post a Comment for "To Get Resultset From Pre-complie Statement In Android"