当前位置: 首页>>代码示例>>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;未经允许,请勿转载。