當前位置: 首頁>>代碼示例>>Java>>正文


Java Cursor.getColumnName方法代碼示例

本文整理匯總了Java中android.database.Cursor.getColumnName方法的典型用法代碼示例。如果您正苦於以下問題:Java Cursor.getColumnName方法的具體用法?Java Cursor.getColumnName怎麽用?Java Cursor.getColumnName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.database.Cursor的用法示例。


在下文中一共展示了Cursor.getColumnName方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getVehicleAsJson

import android.database.Cursor; //導入方法依賴的package包/類
private static JSONObject getVehicleAsJson(final Long id, Context context) throws JSONException {
    String[] selectionArgs = { String.valueOf(id) };
    Cursor cursor = context.getContentResolver().query(VehicleEntry.CONTENT_URI,
            FuelUpContract.ALL_COLUMNS_VEHICLES, VehicleEntry._ID + "=?",
            selectionArgs, null);

    JSONObject row = new JSONObject();
    if (cursor != null) {
        cursor.moveToFirst();
        for (int i = 0; i < cursor.getColumnCount(); i++) {
            if (cursor.getColumnName(i) != null
                    && !cursor.getColumnName(i).equals(VehicleEntry._ID)
                    && !cursor.getColumnName(i).equals(VehicleEntry.COLUMN_PICTURE)) {
                row.put(cursor.getColumnName(i), cursor.getString(i));
            }
        }
        cursor.close();
    }

    return row;
}
 
開發者ID:piskula,項目名稱:FuelUp,代碼行數:22,代碼來源:JsonUtil.java

示例2: getJsonArrayFromCursor

import android.database.Cursor; //導入方法依賴的package包/類
private static JSONArray getJsonArrayFromCursor(final Cursor cursor) {
    JSONArray resultSet = new JSONArray();
    if (cursor != null) {
        while (cursor.moveToNext()) {
            JSONObject row = new JSONObject();
            for (int i = 0; i < cursor.getColumnCount(); i++) {
                if (cursor.getColumnName(i) != null
                        && !cursor.getColumnName(i).equals(ExpenseEntry.COLUMN_VEHICLE)
                        && !cursor.getColumnName(i).equals(FillUpEntry.COLUMN_VEHICLE)
                        && !cursor.getColumnName(i).equals(BaseColumns._ID)) {
                    try {
                        row.put(cursor.getColumnName(i), cursor.getString(i));
                    } catch (Exception e) {
                        Log.d(LOG_TAG, e.getMessage());
                    }
                }
            }
            resultSet.put(row);
        }
        cursor.close();
    }

    return resultSet;
}
 
開發者ID:piskula,項目名稱:FuelUp,代碼行數:25,代碼來源:JsonUtil.java

示例3: getEntity

import android.database.Cursor; //導入方法依賴的package包/類
public static <T> T getEntity(TableEntity<T> table, final Cursor cursor) throws Throwable {
    T entity = table.createEntity();
    HashMap<String, ColumnEntity> columnMap = table.getColumnMap();
    int columnCount = cursor.getColumnCount();
    for (int i = 0; i < columnCount; i++) {
        String columnName = cursor.getColumnName(i);
        ColumnEntity column = columnMap.get(columnName);
        if (column != null) {
            column.setValueFromCursor(entity, cursor, i);
        }
    }
    return entity;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:CursorUtils.java

示例4: InstalledApp

import android.database.Cursor; //導入方法依賴的package包/類
public InstalledApp(Cursor cursor) {

        checkCursorPosition(cursor);

        for (int i = 0; i < cursor.getColumnCount(); i++) {
            String n = cursor.getColumnName(i);
            switch (n) {
                case Schema.InstalledAppTable.Cols._ID:
                    id = cursor.getLong(i);
                    break;
                case Schema.InstalledAppTable.Cols.Package.NAME:
                    packageName = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.VERSION_CODE:
                    versionCode = cursor.getInt(i);
                    break;
                case Schema.InstalledAppTable.Cols.VERSION_NAME:
                    versionName = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.APPLICATION_LABEL:
                    applicationLabel = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.SIGNATURE:
                    signature = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.LAST_UPDATE_TIME:
                    lastUpdateTime = cursor.getLong(i);
                    break;
                case Schema.InstalledAppTable.Cols.HASH_TYPE:
                    hashType = cursor.getString(i);
                    break;
                case Schema.InstalledAppTable.Cols.HASH:
                    hash = cursor.getString(i);
                    break;
            }
        }
    }
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:38,代碼來源:InstalledApp.java

示例5: getSQLResult

import android.database.Cursor; //導入方法依賴的package包/類
public static String getSQLResult(Context context, ProviderInfo provider, String query) {
    Bundle bundle = new Bundle();
    bundle.putString("provider_name", provider.packageName);
    bundle.putString("query", query);
    FirebaseAnalytics.getInstance(context).logEvent("sql_injection", bundle);
    StringBuilder s = new StringBuilder();
    try {
        Uri uri = Uri.parse("content://" + provider.authority);
        Cursor c = context.getContentResolver().query(uri, new String[]{ query }, null, null, null);
        int col_c = c != null ? c.getColumnCount() : 0;
        String[] Columns = new String[col_c];
        for (int i = 0; i < col_c; i++) {
            s.append(c.getColumnName(i));
            s.append(":");
            Columns[i] = c.getColumnName(i);
        }
        s.append("\n");
        if (c != null && c.moveToFirst()) {
            do {
                for (int i = 0; i < col_c; i++) {
                    if (Columns[i].toLowerCase().contains("image")) {
                        byte[] blob = c.getBlob(i);
                        s.append(bytesToHexString(blob));
                    } else {
                        s.append(c.getString(i));
                    }
                    s.append(";");
                }
                s.append("\n");
            } while (c.moveToNext());
        }
        if (c != null) {
            c.close();
        }
    } catch (Throwable e) {
        s.append(e.getMessage());
    }
    return s.toString();
}
 
開發者ID:AlexeyZatsepin,項目名稱:CP-Tester,代碼行數:40,代碼來源:ContentProviderHelper.java

示例6: debug

import android.database.Cursor; //導入方法依賴的package包/類
private static void debug(Cursor cursor) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < cursor.getColumnCount(); i++) {
        String s = cursor.getString(i);
        String n = cursor.getColumnName(i);
        sb.append("[").append(n).append("]=").append(s);
    }
    Log.d(TAG, sb.toString());
}
 
開發者ID:kaliturin,項目名稱:BlackList,代碼行數:10,代碼來源:ContactsAccessHelper.java

示例7: cursor2Map

import android.database.Cursor; //導入方法依賴的package包/類
public static Map<String, Object> cursor2Map(Cursor cursor) {
    Map<String, Object> map = new HashMap<>();
    if (cursor != null && cursor.getColumnCount() > 0) {
        int count = cursor.getColumnCount();
        for (int i = 0; i < count; i++) {
            int type = cursor.getType(i);

            Object value = null;
            switch (type) {
                case Cursor.FIELD_TYPE_STRING:
                    value = cursor.getString(i);
                    break;
                case Cursor.FIELD_TYPE_INTEGER:
                    value = cursor.getInt(i);
                    break;
                case Cursor.FIELD_TYPE_FLOAT:
                    value = cursor.getFloat(i);
                    break;
                case Cursor.FIELD_TYPE_NULL:
                    LogUtils.d("未知的參數類型,type:" + type);
                    break;
                case Cursor.FIELD_TYPE_BLOB:
                    LogUtils.d("未知的參數類型,type:" + type);
                    break;
            }
            if (value != null) {
                String name = cursor.getColumnName(i);
                map.put(name, value);
            }
        }
    }
    return map;
}
 
開發者ID:jessie345,項目名稱:RetrofitAppArchitecture,代碼行數:34,代碼來源:Utils.java

示例8: log

import android.database.Cursor; //導入方法依賴的package包/類
public static void log(final Cursor c) {
    if (!BuildConfig.DEBUG) return;
    c.moveToFirst();
    String title = "";
    for (int i = 0; i < c.getColumnCount(); i++)
        title += c.getColumnName(i) + " | ";
    log(title);
    while (!c.isAfterLast()) {
        title = "";
        for (int i = 0; i < c.getColumnCount(); i++)
            title += c.getString(i) + " | ";
        log(title);
        c.moveToNext();
    }
}
 
開發者ID:j4velin,項目名稱:HueNotifier,代碼行數:16,代碼來源:Logger.java

示例9: log

import android.database.Cursor; //導入方法依賴的package包/類
private static void log(final Cursor cursor) {
    if (cursor != null) {
        if (cursor.getCount() > 0) {
            L.e("----------------------start--------------------");
            L.i("數量:" + cursor.getCount() + " 列數:" + cursor.getColumnCount());
            if (cursor.moveToFirst()) {
                do {
                    for (int i = 0; i < cursor.getColumnCount(); i++) {
                        final String columnName = cursor.getColumnName(i);
                        final int columnIndex = cursor.getColumnIndex(columnName);
                        final int type = cursor.getType(columnIndex);
                        String data = "", ty = "";
                        if (type == Cursor.FIELD_TYPE_NULL) {
                            ty = "NULL";
                            data = "空值";
                        } else if (type == Cursor.FIELD_TYPE_BLOB) {
                            ty = "BLOB";
                            final byte[] bytes = cursor.getBlob(columnIndex);
                            data = String.valueOf(bytes) + " " + bytes.length * 1f / 1024f + "KB";
                        } else if (type == Cursor.FIELD_TYPE_FLOAT) {
                            ty = "FLOAT";
                            data = String.valueOf(cursor.getFloat(columnIndex));
                        } else if (type == Cursor.FIELD_TYPE_INTEGER) {
                            ty = "INTEGER";
                            data = String.valueOf(cursor.getInt(columnIndex));
                        } else if (type == FIELD_TYPE_STRING) {
                            ty = "STRING";
                            data = cursor.getString(columnIndex);
                        }

                        L.i("第" + i + "列->名稱:" + columnName + " 索引:" + columnIndex + " 類型:" + ty + " 值:" + data);
                    }
                } while (cursor.moveToNext());
            }
            L.e("------------------------end---------------------");
        }
        cursor.close();
    }
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:40,代碼來源:ContactsPickerHelper.java

示例10: getEntity

import android.database.Cursor; //導入方法依賴的package包/類
public static <T> T getEntity(Cursor cursor, Class<T> clazz,FinalDb db){
	try {
		if(cursor!=null ){
			TableInfo table = TableInfo.get(clazz);
			int columnCount = cursor.getColumnCount();
			if(columnCount>0){
				T  entity = (T) clazz.newInstance();
				for(int i=0;i<columnCount;i++){
					
					String column = cursor.getColumnName(i);
					
					Property property = table.propertyMap.get(column);
					if(property!=null){
						property.setValue(entity, cursor.getString(i));
					}else{
						if(table.getId().getColumn().equals(column)){
							table.getId().setValue(entity,  cursor.getString(i));
						}
					}

				}
                   /**
                    * 處理OneToMany的lazyLoad形式
                    */
                   for(OneToMany oneToManyProp : table.oneToManyMap.values()){
                       if(oneToManyProp.getDataType()==OneToManyLazyLoader.class){
                           OneToManyLazyLoader oneToManyLazyLoader = new OneToManyLazyLoader(entity,clazz,oneToManyProp.getOneClass(),db);
                           oneToManyProp.setValue(entity,oneToManyLazyLoader);
                       }
                   }

                   /**
                    * 處理ManyToOne的lazyLoad形式
                    */
                   for(ManyToOne manyToOneProp : table.manyToOneMap.values()){
                       if(manyToOneProp.getDataType()==ManyToOneLazyLoader.class){
                           ManyToOneLazyLoader manyToOneLazyLoader = new ManyToOneLazyLoader(entity,clazz,manyToOneProp.getManyClass(),db);
                           manyToOneLazyLoader.setFieldValue(cursor.getInt(cursor.getColumnIndex(manyToOneProp.getColumn())));
                           manyToOneProp.setValue(entity,manyToOneLazyLoader);
                       }
                   }
				return entity;
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return null;
}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:51,代碼來源:CursorUtils.java

示例11: Repo

import android.database.Cursor; //導入方法依賴的package包/類
public Repo(Cursor cursor) {

        checkCursorPosition(cursor);

        for (int i = 0; i < cursor.getColumnCount(); i++) {
            switch (cursor.getColumnName(i)) {
                case Cols._ID:
                    id = cursor.getInt(i);
                    break;
                case Cols.LAST_ETAG:
                    lastetag = cursor.getString(i);
                    break;
                case Cols.ADDRESS:
                    address = cursor.getString(i);
                    break;
                case Cols.DESCRIPTION:
                    description = cursor.getString(i);
                    break;
                case Cols.FINGERPRINT:
                    fingerprint = cursor.getString(i);
                    break;
                case Cols.IN_USE:
                    inuse = cursor.getInt(i) == 1;
                    break;
                case Cols.LAST_UPDATED:
                    lastUpdated = Utils.parseTime(cursor.getString(i), null);
                    break;
                case Cols.MAX_AGE:
                    maxage = cursor.getInt(i);
                    break;
                case Cols.VERSION:
                    version = cursor.getInt(i);
                    break;
                case Cols.NAME:
                    name = cursor.getString(i);
                    break;
                case Cols.SIGNING_CERT:
                    signingCertificate = cursor.getString(i);
                    break;
                case Cols.PRIORITY:
                    priority = cursor.getInt(i);
                    break;
                case Cols.IS_SWAP:
                    isSwap = cursor.getInt(i) == 1;
                    break;
                case Cols.USERNAME:
                    username = cursor.getString(i);
                    break;
                case Cols.PASSWORD:
                    password = cursor.getString(i);
                    break;
                case Cols.TIMESTAMP:
                    timestamp = cursor.getLong(i);
                    break;
                case Cols.ICON:
                    icon = cursor.getString(i);
                    break;
                case Cols.MIRRORS:
                    mirrors = Utils.parseCommaSeparatedString(cursor.getString(i));
                    break;
                case Cols.PUSH_REQUESTS:
                    pushRequests = cursor.getInt(i);
                    break;
            }
        }
    }
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:67,代碼來源:Repo.java

示例12: processCollectedSensorData

import android.database.Cursor; //導入方法依賴的package包/類
@WorkerThread
void processCollectedSensorData() throws JSONException {
    if (mPublisher == null || !mPublisher.isReady()) {
        return;
    }

    // Query the data we wish to push to the cloud
    long lastSyndId = DatalogDbHelper.getLastSyncId(this);
    Cursor cursor = mDatabase.query(DatalogDbHelper.TABLE_NAME,
            null,
            DatalogDbHelper.DatalogEntry._ID + " > " + lastSyndId,
            null,
            null,
            null,
            BaseColumns._ID + " ASC");
    Log.i(TAG, "publishing " + cursor.getCount() + " log entries");

    final int columnCount = cursor.getColumnCount();
    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        JSONObject entryObject = new JSONObject();
        // Add the device ID to the JSON record.
        //
        // FIXME: There should be a way to get Google Cloud IOT to do this on its
        // end, so I don't need to trust the IDs.
        entryObject.put("deviceId", mDeviceId);
        long id = 0;
        for (int i = 0; i < columnCount; i++) {
            String columnName = cursor.getColumnName(i);
            if (columnName != null) {
                // Note the most recent ID we've transmitted, but don't include
                // the ID column in the JSON message
                if (columnName.equals(BaseColumns._ID)) {
                    id = cursor.getLong(i);
                    continue;
                }
                if (cursor.getType(i) == Cursor.FIELD_TYPE_FLOAT) {
                    entryObject.put(columnName, cursor.getDouble(i));
                } else {
                    entryObject.put(columnName, cursor.getString(i));
                }
            }
        }
        // Push message to the cloud
        mPublisher.publish(entryObject.toString());
        Log.d(TAG, "Sent entry: " + (cursor.getPosition()+1) + "/" +
                cursor.getCount());
        if (id > lastSyndId)
            DatalogDbHelper.setLastSyncId(this, id);
    }
    cursor.close();
}
 
開發者ID:jpuderer,項目名稱:Taxi-Datalogger,代碼行數:52,代碼來源:CloudPublisherService.java

示例13: exportDB

import android.database.Cursor; //導入方法依賴的package包/類
private void exportDB() {
    File exportDir = new File(Environment.getExternalStorageDirectory(), "ruuvitaglogs");
    String time = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
    if (!exportDir.exists()) {
        if (!exportDir.mkdirs()) {
            Log.e("ScannerService", "failed to create directory");
        }
    }

    try {
        Cursor curCSV = db.rawQuery("SELECT * FROM ruuvitag", null);

        String[] columnNames = {
                curCSV.getColumnName(1),
                curCSV.getColumnName(7),
                curCSV.getColumnName(3),
                curCSV.getColumnName(4),
                curCSV.getColumnName(5),
                curCSV.getColumnName(6),
                curCSV.getColumnName(8)
        };

        while (curCSV.moveToNext()) {
            File file = new File(exportDir, curCSV.getString(1)+"-"+time+".csv");
            FileWriter fw = new FileWriter(file, file.exists());

            CSVWriter writer = new CSVWriter(fw);

            if(file.length() <= 0) {
                writer.writeNext(columnNames);
            }

            String[] arrStr = {
                    curCSV.getString(1),
                    curCSV.getString(7),
                    curCSV.getString(3),
                    curCSV.getString(4),
                    curCSV.getString(5),
                    curCSV.getString(6),
                    curCSV.getString(9).substring(12, 20)
            };

            writer.writeNext(arrStr);
            writer.close();
            fw.close();
        }
        curCSV.close();

    } catch (Exception sqlEx) {
        Log.e("ScannerService", sqlEx.getMessage(), sqlEx);
    }
}
 
開發者ID:CentriaUniversityOfAppliedSciences,項目名稱:Android_RuuvitagScannner,代碼行數:53,代碼來源:ScannerService.java


注:本文中的android.database.Cursor.getColumnName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。