Example usage for android.database Cursor getColumnNames

List of usage examples for android.database Cursor getColumnNames

Introduction

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

Prototype

String[] getColumnNames();

Source Link

Document

Returns a string array holding the names of all of the columns in the result set in the order in which they were listed in the result.

Usage

From source file:Main.java

static ImmutableSet<String> getColumns(SQLiteDatabase db, String table) {
    Cursor cursor = db.query(table, null, null, null, null, null, null, "0");
    if (cursor != null) {
        try {/*  w w w  .j a  va  2 s. c om*/
            return ImmutableSet.copyOf(cursor.getColumnNames());
        } finally {
            cursor.close();
        }
    }
    return ImmutableSet.of();
}

From source file:Main.java

private static List<String> getTableColumns(final SQLiteDatabase database, final String tableName) {
    List<String> ret = null;
    try {/* w w  w . j  av  a  2  s. c  o m*/
        final Cursor cur = database.rawQuery("SELECT * FROM " + tableName + " LIMIT 1", null);
        if (cur != null) {
            ret = new ArrayList<String>(Arrays.asList(cur.getColumnNames()));
        }
        cur.close();
    } catch (final Exception exception) {
        exception.printStackTrace();
    }
    return ret;
}

From source file:Main.java

public static List<String> GetColumns(SQLiteDatabase db, String tableName) {
    List<String> ar = null;
    Cursor c = null;
    try {//from   w  w  w  .  j  a  v  a  2s  . c om
        c = db.rawQuery("select * from " + tableName + " limit 1", null);
        if (c != null) {
            ar = new ArrayList<String>(Arrays.asList(c.getColumnNames()));
        }
    } catch (Exception e) {
        Log.v(tableName, e.getMessage(), e);
        e.printStackTrace();
    } finally {
        if (c != null)
            c.close();
    }
    return ar;
}

From source file:Main.java

/**
 * Get columns for table// w w  w  .  j  a  va2s.c  o  m
 * @param db
 * @param tableName
 * @return
 */
public static List<String> getColumns(SQLiteDatabase db, String tableName) {
    List<String> ar = null;
    Cursor c = null;
    try {
        c = db.rawQuery("select * from " + tableName + " limit 1", null);
        if (c != null) {
            ar = new ArrayList<String>(Arrays.asList(c.getColumnNames()));
        }
    } catch (Exception e) {
        Log.v(tableName, e.getMessage(), e);
        e.printStackTrace();
    } finally {
        if (c != null)
            c.close();
    }
    return ar;
}

From source file:Main.java

private static List<String> getColumns(SQLiteDatabase db, String tableName) {
    List<String> columns = new ArrayList<>();
    Cursor cursor = null;
    try {/*from   w w w.j  a v a2 s. co m*/
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null);
        if (cursor != null) {
            columns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return columns;
}

From source file:Main.java

public static ArrayList<String> getColumns(ContentResolver resolver, String uri, String[] projectionArray) {
    //String returnValue = "";
    ArrayList<String> columns = new ArrayList<String>();

    try {// w w  w. j a va2 s .  c om
        //Issue query
        Cursor c = resolver.query(Uri.parse(uri), projectionArray, null, null, null);

        //Get all column names and display
        if (c != null) {
            String[] colNames = c.getColumnNames();

            //Close the cursor
            c.close();

            //String columnNamesOutput = "";
            for (int k = 0; k < colNames.length; k++)
                columns.add(colNames[k]);
        }
    } catch (Throwable t) {
    }

    return columns;

}

From source file:Main.java

private static List<String> getColumns(SQLiteDatabase db, String tableName) {
    List<String> columns = new ArrayList<>();
    Cursor cursor = null;
    try {/*from  w w  w .j  a  v  a2 s  .  com*/
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null);
        if (cursor != null) {
            columns = new ArrayList<>(Arrays.asList(cursor.getColumnNames()));
        }
    } catch (Exception e) {
        Log.v(tableName, e.getMessage(), e);
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return columns;
}

From source file:Main.java

private static List<String> getColumns(SQLiteDatabase db, String tableName) {
    List<String> columns = new ArrayList<String>();
    Cursor cursor = null;
    try {/*from   ww w .  j  a v a2  s.com*/
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 1", null);
        if (cursor != null) {
            columns = new ArrayList<String>(Arrays.asList(cursor.getColumnNames()));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return columns;
}

From source file:org.xbmc.kore.testhelpers.Utils.java

public static String cursorToString(Cursor cursor) {
    StringBuffer stringBuffer = new StringBuffer();
    for (String name : cursor.getColumnNames()) {
        int index = cursor.getColumnIndex(name);
        stringBuffer.append(name + "=" + cursor.getString(index) + "\n");
    }/*from   w  w w.  j a  v  a2s .c  o  m*/
    return stringBuffer.toString();
}

From source file:com.nerderylabs.android.nerdalert.util.ProfileUtil.java

public static Pair<String, Bitmap> getUserProfile(Context context) {
    String name = "";
    String photo = "";

    Cursor c = context.getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
    if (c != null && c.moveToFirst()) {
        String[] columnNames = c.getColumnNames();
        for (String columnName : columnNames) {
            String columnValue = c.getString(c.getColumnIndex(columnName));
            if (columnName.equals(ContactsContract.Profile.DISPLAY_NAME)) {
                if (columnValue != null) {
                    name = columnValue;/* w  w  w  . ja  v  a  2 s .  co m*/
                }
            } else if (columnName.equals(ContactsContract.Profile.PHOTO_URI)) {
                if (columnValue != null) {
                    photo = columnValue;
                }
            }
        }
        c.close();
    }

    Log.d(TAG, "name: " + name + " | photo: " + photo);

    Bitmap bitmap = loadBitmapFromUriString(context, photo);

    return new Pair<>(name, bitmap);
}