Android SqliteDatabase Command getColumns(SQLiteDatabase db, String tableName)

Here you can find the source of getColumns(SQLiteDatabase db, String tableName)

Description

Get a list of column base_dictionary for the selected table

License

Open Source License

Parameter

Parameter Description
db Database that contains the table
tableName Table name to be used

Return

A List of column name

Declaration

public static List<String> getColumns(SQLiteDatabase db,
        String tableName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import android.util.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    /**//from w ww .j  a  v  a  2s. com
     * Get a list of column base_dictionary for the selected table
     *
     * @param db
     *    Database that contains the table
     * @param tableName
     *    Table name to be used
     * @return A List of column name
     */
    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;
    }
}

Related

  1. getNewTourPointPosition(SQLiteDatabase db, long tourId)
  2. getTourNames(SQLiteDatabase db)
  3. insertTour(SQLiteDatabase db, String tourName)
  4. isCompanyInTour(SQLiteDatabase db, long companyId, long tourId)
  5. tourNameExists(SQLiteDatabase db, String tourName)
  6. dropAllViews(SQLiteDatabase sqlitedatabase)
  7. getRowsCount(SQLiteDatabase sqlitedatabase, String s, String s1, String as[])
  8. formatCalendarForSQLite(Calendar calendar)
  9. getCalendarFromSqlite(String dateString)