Example usage for android.database Cursor getColumnCount

List of usage examples for android.database Cursor getColumnCount

Introduction

In this page you can find the example usage for android.database Cursor getColumnCount.

Prototype

int getColumnCount();

Source Link

Document

Return total number of columns

Usage

From source file:com.popumovies.DetailActivityFragment.java

private void updateMovieDetails(Cursor cursor) {
    if (cursor.moveToFirst()) {
        Bundle args = new Bundle();
        for (int i = 0; i < cursor.getColumnCount(); ++i) {
            args.putString(cursor.getColumnName(i), cursor.getString(i));
        }/*from   www.  j av  a  2  s  .c om*/
        fillForm(args);
    }
}

From source file:com.phonegap.Storage.java

/**
 * Process query results./*from  w  w  w .j  a  v  a  2  s.  co m*/
 * 
 * @param cur            Cursor into query results
 * @param tx_id            Transaction id
 */
public void processResults(Cursor cur, String tx_id) {

    String result = "[]";
    // If query result has rows

    if (cur.moveToFirst()) {
        JSONArray fullresult = new JSONArray();
        String key = "";
        String value = "";
        int colCount = cur.getColumnCount();

        // Build up JSON result object for each row
        do {
            JSONObject row = new JSONObject();
            try {
                for (int i = 0; i < colCount; ++i) {
                    key = cur.getColumnName(i);
                    value = cur.getString(i);
                    row.put(key, value);
                }
                fullresult.put(row);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        } while (cur.moveToNext());

        result = fullresult.toString();
    }

    // Let JavaScript know that there are no more rows
    this.sendJavascript("droiddb.completeQuery('" + tx_id + "', " + result + ");");

}

From source file:com.polyvi.xface.extension.XStorageExt.java

/**
 * ?.//from   ww  w .j  av a  2 s  . c  om
 *
 * @param cur
 *            
 * @param tx_id
 *             id
 * @param callbackCtx
 *            
 */
private void processResults(Cursor cur, String tx_id, XCallbackContext callbackCtx) {

    String result = "[]";

    if (cur.moveToFirst()) {
        JSONArray fullresult = new JSONArray();
        String key = "";
        String value = "";
        int colCount = cur.getColumnCount();

        do {
            JSONObject row = new JSONObject();
            try {
                for (int i = 0; i < colCount; ++i) {
                    key = cur.getColumnName(i);
                    value = cur.getString(i);
                    row.put(key, value);
                }
                fullresult.put(row);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        } while (cur.moveToNext());

        result = fullresult.toString();
    }

    String jsScript = "xFace.require('xFace/extension/android/storage').completeQuery('" + tx_id + "', "
            + result + ");";
    mWebContext.getApplication().loadJavascript(jsScript);
}

From source file:org.apache.cordova.legacywebsql.LegacyWebSql.java

/**
 * Process query results./*  w w  w  . j  av a  2 s  . co m*/
 *
 * @param cur
 *            Cursor into query results
 * @param tx_id
 *            Transaction id
 */
public void processResults(Cursor cur, String tx_id) {

    String result = "[]";
    // If query result has rows

    if (cur.moveToFirst()) {
        JSONArray fullresult = new JSONArray();
        String key = "";
        String value = "";
        int colCount = cur.getColumnCount();

        // Build up JSON result object for each row
        do {
            JSONObject row = new JSONObject();
            try {
                for (int i = 0; i < colCount; ++i) {
                    key = cur.getColumnName(i);
                    value = cur.getString(i);
                    row.put(key, value);
                }
                fullresult.put(row);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        } while (cur.moveToNext());

        result = fullresult.toString();
    }

    // Let JavaScript know that there are no more rows
    this.webView.sendJavascript("cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id
            + "', " + result + ");");
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

static void loadMeta(Context context) {
    MetaDBOpenHelper metaDB = new MetaDBOpenHelper(context);
    SQLiteDatabase metadb = metaDB.getReadableDatabase();

    Cursor cursor;
    try {/*  w  ww  . j av  a2s  .  co m*/
        cursor = metadb.query(MetasTable.NAME, MetaDBOpenHelper.allcolumns, null, null, null, null, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        metaDB.close();
        metadb.close();
        metadb = null;
        return;
    }

    MyApp.numdays = MetasTable.Defaults.NUM_DAYS_DEFAULT;
    ;
    MyApp.version = "";
    MyApp.title = "";
    MyApp.subtitle = "";
    MyApp.dayChangeHour = MetasTable.Defaults.DAY_CHANGE_HOUR_DEFAULT;
    MyApp.dayChangeMinute = MetasTable.Defaults.DAY_CHANGE_MINUTE_DEFAULT;
    MyApp.eTag = null;

    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        int columnIndexNumDays = cursor.getColumnIndex(MetasTable.Columns.NUM_DAYS);
        if (cursor.getColumnCount() > columnIndexNumDays) {
            MyApp.numdays = cursor.getInt(columnIndexNumDays);
        }
        int columIndexVersion = cursor.getColumnIndex(MetasTable.Columns.VERSION);
        if (cursor.getColumnCount() > columIndexVersion) {
            MyApp.version = cursor.getString(columIndexVersion);
        }
        int columnIndexTitle = cursor.getColumnIndex(MetasTable.Columns.TITLE);
        if (cursor.getColumnCount() > columnIndexTitle) {
            MyApp.title = cursor.getString(columnIndexTitle);
        }
        int columnIndexSubTitle = cursor.getColumnIndex(MetasTable.Columns.SUBTITLE);
        if (cursor.getColumnCount() > columnIndexSubTitle) {
            MyApp.subtitle = cursor.getString(columnIndexSubTitle);
        }
        int columnIndexDayChangeHour = cursor.getColumnIndex(MetasTable.Columns.DAY_CHANGE_HOUR);
        if (cursor.getColumnCount() > columnIndexDayChangeHour) {
            MyApp.dayChangeHour = cursor.getInt(columnIndexDayChangeHour);
        }
        int columnIndexDayChangeMinute = cursor.getColumnIndex(MetasTable.Columns.DAY_CHANGE_MINUTE);
        if (cursor.getColumnCount() > columnIndexDayChangeMinute) {
            MyApp.dayChangeMinute = cursor.getInt(columnIndexDayChangeMinute);
        }
        int columnIndexEtag = cursor.getColumnIndex(MetasTable.Columns.ETAG);
        if (cursor.getColumnCount() > columnIndexEtag) {
            MyApp.eTag = cursor.getString(columnIndexEtag);
        }
    }

    MyApp.LogDebug(LOG_TAG, "loadMeta: numdays=" + MyApp.numdays + " version:" + MyApp.version + " "
            + MyApp.title + " " + MyApp.eTag);
    cursor.close();

    metadb.close();
    metaDB.close();
}

From source file:org.skt.runtime.original.Storage.java

/**
 * Process query results.//from   w  w w. j ava2 s .  c o m
 * 
 * @param cur
 *            Cursor into query results
 * @param tx_id
 *            Transaction id
 */
public void processResults(Cursor cur, String tx_id) {

    String result = "[]";
    // If query result has rows

    if (cur.moveToFirst()) {
        JSONArray fullresult = new JSONArray();
        String key = "";
        String value = "";
        int colCount = cur.getColumnCount();

        // Build up JSON result object for each row
        do {
            JSONObject row = new JSONObject();
            try {
                for (int i = 0; i < colCount; ++i) {
                    key = cur.getColumnName(i);
                    value = cur.getString(i);
                    row.put(key, value);
                }
                fullresult.put(row);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        } while (cur.moveToNext());

        result = fullresult.toString();
    }

    // Let JavaScript know that there are no more rows
    this.sendJavascript(
            "srt.sktrequire('srt/plugin/android/storage').completeQuery('" + tx_id + "', " + result + ");");
}

From source file:com.android.contacts.list.MultiSelectContactsListFragment.java

private long getContactId(int position) {
    final int contactIdColumnIndex = getAdapter().getContactColumnIdIndex();

    final Cursor cursor = (Cursor) getAdapter().getItem(position);
    if (cursor != null) {
        if (cursor.getColumnCount() > contactIdColumnIndex) {
            return cursor.getLong(contactIdColumnIndex);
        }//from   w  ww .  j av  a  2s. c o m
    }

    Log.w(TAG, "Failed to get contact ID from cursor column " + contactIdColumnIndex);
    return -1;
}

From source file:it.bradipao.berengar.DbTool.java

public static JSONObject table2json(SQLiteDatabase mDB, String sTableName, String sTableSql) {
    // vars//from w ww.j  ava2 s  .  c  om
    JSONObject jsonTable = new JSONObject();
    JSONArray jsonRows = new JSONArray();
    JSONArray jsonColsName = new JSONArray();
    JSONArray jsonCols = null;

    // read table
    String sqlquery = "select * from " + sTableName;
    Cursor cur = mDB.rawQuery(sqlquery, null);
    // iteratew through rows
    int i = -1;
    while (cur.moveToNext()) {
        // at first element store column names
        if (i == -1)
            for (i = 0; i < cur.getColumnCount(); i++) {
                jsonColsName.put(cur.getColumnName(i));
            }
        // get values
        jsonCols = new JSONArray();
        for (i = 0; i < cur.getColumnCount(); i++) {
            jsonCols.put(cur.getString(i));
        }
        // add values to rows array
        jsonRows.put(jsonCols);
    }

    // final json building
    try {
        // table name
        jsonTable.put("table_name", sTableName);
        // code for create table
        if ((sTableSql != null) && (!sTableSql.isEmpty()))
            jsonTable.put("table_sql", sTableSql);
        // columns name
        jsonTable.put("cols_name", jsonColsName);
        // rows
        jsonTable.put("rows", jsonRows);
    } catch (JSONException e) {
        Log.e(LOGTAG, "error in table2json", e);
    }

    // return String
    return jsonTable;
}

From source file:com.phonegap.plugin.sqlitePlugin.SQLitePlugin.java

/**
 * Process query results./* w w  w  . j  a  v  a 2  s .  c o  m*/
 *
 * @param cur
 *            Cursor into query results
 * @param tx_id
 *            Transaction id
 */
public void processResults(Cursor cur, String tx_id) {

    String result = "[]";
    // If query result has rows

    if (cur.moveToFirst()) {
        JSONArray fullresult = new JSONArray();
        String key = "";
        String value = "";
        int colCount = cur.getColumnCount();

        // Build up JSON result object for each row
        do {
            JSONObject row = new JSONObject();
            try {
                for (int i = 0; i < colCount; ++i) {
                    key = cur.getColumnName(i);
                    value = cur.getString(i);
                    row.put(key, value);
                }
                fullresult.put(row);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        } while (cur.moveToNext());

        result = fullresult.toString();
    }

    // Let JavaScript know that there are no more rows
    this.sendJavascript("dddb.completeQuery('" + tx_id + "', " + result + ");");
}

From source file:com.phonegap.plugins.sqlitePlugin.SQLitePlugin.java

/**
 * Process query results./*from w w w .j  av a2  s  .  com*/
 *
 * @param cur
 *            Cursor into query results
 * @param tx_id
 *            Transaction id
 */
public void processResults(Cursor cur, String query_id, String tx_id) {

    String result = "[]";
    // If query result has rows

    if (cur.moveToFirst()) {
        JSONArray fullresult = new JSONArray();
        String key = "";
        int colCount = cur.getColumnCount();

        // Build up JSON result object for each row
        do {
            JSONObject row = new JSONObject();
            try {
                for (int i = 0; i < colCount; ++i) {
                    key = cur.getColumnName(i);
                    if (android.os.Build.VERSION.SDK_INT >= 11) {
                        switch (cur.getType(i)) {
                        case Cursor.FIELD_TYPE_NULL:
                            row.put(key, null);
                            break;
                        case Cursor.FIELD_TYPE_INTEGER:
                            row.put(key, cur.getInt(i));
                            break;
                        case Cursor.FIELD_TYPE_FLOAT:
                            row.put(key, cur.getFloat(i));
                            break;
                        case Cursor.FIELD_TYPE_STRING:
                            row.put(key, cur.getString(i));
                            break;
                        case Cursor.FIELD_TYPE_BLOB:
                            row.put(key, cur.getBlob(i));
                            break;
                        }
                    } else {
                        row.put(key, cur.getString(i));
                    }
                }
                fullresult.put(row);

            } catch (JSONException e) {
                e.printStackTrace();
            }

        } while (cur.moveToNext());

        result = fullresult.toString();
    }
    if (query_id.length() > 0)
        this.sendJavascript(" SQLitePluginTransaction.queryCompleteCallback('" + tx_id + "','" + query_id
                + "', " + result + ");");

}