当前位置: 首页>>代码示例>>Java>>正文


Java InsertHelper.bind方法代码示例

本文整理汇总了Java中android.database.DatabaseUtils.InsertHelper.bind方法的典型用法代码示例。如果您正苦于以下问题:Java InsertHelper.bind方法的具体用法?Java InsertHelper.bind怎么用?Java InsertHelper.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.database.DatabaseUtils.InsertHelper的用法示例。


在下文中一共展示了InsertHelper.bind方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertBulkItems

import android.database.DatabaseUtils.InsertHelper; //导入方法依赖的package包/类
public boolean insertBulkItems(ArrayList<FeedObject> feedList) 
{
	long start = System.currentTimeMillis();
	int time = (int)(start / 1000);
	if(feedList==null || feedList.size()<1) 
		return false;
	
	Logs.d(TAG, "# Insert bulk : type="+feedList.get(0).mType+", item count = "+feedList.size());

	InsertHelper iHelp = new InsertHelper(mDb, TABLE_NAME_FEED_ITEM);
	int ktype 		= iHelp.getColumnIndex(KEY_FEED_TYPE);
	int kstatus 	= iHelp.getColumnIndex(KEY_FEED_STATUS);
	int kid 			= iHelp.getColumnIndex(KEY_FEED_IDSTRING);
	int kname 			= iHelp.getColumnIndex(KEY_FEED_NAME);
	int klink 		= iHelp.getColumnIndex(KEY_FEED_LINK);
	int kkeyword 	= iHelp.getColumnIndex(KEY_FEED_KEYWORD);
	int kcontent 	= iHelp.getColumnIndex(KEY_FEED_CONTENT);
	int kthumbnail 	= iHelp.getColumnIndex(KEY_FEED_THUMBNAILURL);
	int kdate 			= iHelp.getColumnIndex(KEY_FEED_DATE);
	int krank 			= iHelp.getColumnIndex(KEY_FEED_RANK);
	int kclick 			= iHelp.getColumnIndex(KEY_FEED_CLICK);
	int kranktype	= iHelp.getColumnIndex(KEY_FEED_ARG0);
	int kversion	= iHelp.getColumnIndex(KEY_FEED_ARG1);
	int kfullimage	= iHelp.getColumnIndex(KEY_FEED_ARG2);
	
	synchronized (mDb) {
		if(mDb == null) return false;
		try
		{
			mDb.beginTransaction();
			// First one is recent one. So insert oldest first.
			for(int i = feedList.size()-1 ; -1<i ; i--)
			{
				FeedObject feed = feedList.get(i);
				// need to tell the helper you are inserting (rather than replacing)
				iHelp.prepareForInsert();

				// do the equivalent of ContentValues.put("field","value") here
				iHelp.bind(ktype, feed.mType);
				iHelp.bind(kstatus, feed.mDownloadStatus);
				iHelp.bind(kid, feed.mId);
				if(feed.mName != null)
					iHelp.bind(kname, feed.mName);
				if(feed.mLink != null)
					iHelp.bind(klink, feed.mLink);
				if(feed.mKeyword != null)
					iHelp.bind(kkeyword, feed.mKeyword);
				if(feed.mContent != null)
					iHelp.bind(kcontent, feed.mContent);
				if(feed.mThumbnailUrl != null)
					iHelp.bind(kthumbnail, feed.mThumbnailUrl);
				if(feed.mDate != null)
					iHelp.bind(kdate, feed.mDate);
				else
					iHelp.bind(kdate, time);

				iHelp.bind(krank, feed.mRankUpAndDown);
				iHelp.bind(kclick, feed.mCommentCount);
				iHelp.bind(kranktype, feed.mRankType);
				iHelp.bind(kversion, feed.mVersion);

				if(feed.mFullSizeImageURL != null)
					iHelp.bind(kfullimage, feed.mFullSizeImageURL);
				
				//the db.insert() equilvalent
				iHelp.execute();
			}
			mDb.setTransactionSuccessful();
		}
		catch(Exception e) {
		}
		finally	{
			mDb.endTransaction();
		}
	}

	return true;
}
 
开发者ID:godstale,项目名称:retrowatch,代码行数:79,代码来源:DBHelper.java

示例2: bulkInsertUsers

import android.database.DatabaseUtils.InsertHelper; //导入方法依赖的package包/类
private int bulkInsertUsers(final ContentValues[] values) {
    int numInserted = 0;
    final SQLiteDatabase db = this.dbHelper.getWritableDatabase();
    final InsertHelper ih = new InsertHelper(db, UserInfo.TABLE_NAME);

    final int id = ih.getColumnIndex(BasicColumns.ID);
    final int ownerId = ih.getColumnIndex(BasicColumns.OWNER_ID);

    final int screenName = ih.getColumnIndex(UserInfo.SCREEN_NAME);
    final int location = ih.getColumnIndex(UserInfo.LOCATION);
    final int gender = ih.getColumnIndex(UserInfo.GENDER);
    final int birthday = ih.getColumnIndex(UserInfo.BIRTHDAY);

    final int description = ih.getColumnIndex(UserInfo.DESCRIPTION);
    final int profileImageUrl = ih
            .getColumnIndex(UserInfo.PROFILE_IMAGE_URL);
    final int url = ih.getColumnIndex(UserInfo.URL);
    final int protect = ih.getColumnIndex(UserInfo.PROTECTED);

    final int followersCount = ih.getColumnIndex(UserInfo.FOLLOWERS_COUNT);
    final int friendsCount = ih.getColumnIndex(UserInfo.FRIENDS_COUNT);
    final int favoritesCount = ih.getColumnIndex(UserInfo.FAVORITES_COUNT);
    final int statusesCount = ih.getColumnIndex(UserInfo.STATUSES_COUNT);

    final int following = ih.getColumnIndex(UserInfo.FOLLOWING);
    final int createdAt = ih.getColumnIndex(BasicColumns.CREATED_AT);

    final int type = ih.getColumnIndex(BasicColumns.TYPE);

    try {
        db.beginTransaction();
        for (final ContentValues value : values) {
            ih.prepareForInsert();

            ih.bind(id, value.getAsString(BasicColumns.ID));
            ih.bind(ownerId, value.getAsString(BasicColumns.OWNER_ID));

            ih.bind(screenName, value.getAsString(UserInfo.SCREEN_NAME));
            ih.bind(location, value.getAsString(UserInfo.LOCATION));
            ih.bind(gender, value.getAsString(UserInfo.GENDER));
            ih.bind(birthday, value.getAsString(UserInfo.BIRTHDAY));

            ih.bind(description, value.getAsString(UserInfo.DESCRIPTION));
            ih.bind(profileImageUrl,
                    value.getAsString(UserInfo.PROFILE_IMAGE_URL));
            ih.bind(url, value.getAsString(UserInfo.URL));
            ih.bind(protect, value.getAsBoolean(UserInfo.PROTECTED));

            ih.bind(followersCount,
                    value.getAsInteger(UserInfo.FOLLOWERS_COUNT));
            ih.bind(friendsCount,
                    value.getAsInteger(UserInfo.FRIENDS_COUNT));
            ih.bind(favoritesCount,
                    value.getAsInteger(UserInfo.FAVORITES_COUNT));
            ih.bind(statusesCount,
                    value.getAsInteger(UserInfo.STATUSES_COUNT));

            ih.bind(following, value.getAsBoolean(UserInfo.FOLLOWING));
            ih.bind(createdAt, value.getAsLong(BasicColumns.CREATED_AT));
            ih.bind(type, value.getAsInteger(BasicColumns.TYPE));

            final long result = ih.execute();
            if (result > -1) {
                numInserted++;
            }
        }
        if (AppContext.DEBUG) {
            log("bulkInsertUsers insert rows=" + numInserted);
        }
        db.setTransactionSuccessful();
    } catch (final Exception e) {
        if (AppContext.DEBUG) {
            e.printStackTrace();
        }
    } finally {
        ih.close();
        db.endTransaction();
    }
    return numInserted;
}
 
开发者ID:mcxiaoke,项目名称:fanfouapp-opensource,代码行数:81,代码来源:FanFouProvider.java

示例3: insertBulkCallList

import android.database.DatabaseUtils.InsertHelper; //导入方法依赖的package包/类
public void insertBulkCallList(ArrayList<SMSMessage> smsList){
	SQLiteDatabase db = this.getWritableDatabase();
	try{
		// Create a single InsertHelper to handle this set of insertions.
		InsertHelper ih = new InsertHelper(db, SMSListTable.TABLE_NAME);

		// Get the numeric indexes for each of the columns that we're updating
		final int smsIdColumn = ih.getColumnIndex(SMSListTable.smsId);
		final int phoneColumn = ih.getColumnIndex(SMSListTable.phoneNumber);
		final int threadIDColumn = ih.getColumnIndex(SMSListTable.threadID);
		final int typeColumn = ih.getColumnIndex(SMSListTable.type);
		final int dateColumn = ih.getColumnIndex(SMSListTable.date);
		final int smsPartsColumn = ih.getColumnIndex(SMSListTable.smsParts);
		try {
			for (SMSMessage smsMessage : smsList) {
				if(smsMessage!=null){
					// ... Create the data for this row (not shown) ...

					// Get the InsertHelper ready to insert a single row
					ih.prepareForInsert();

					// Add the data for each column
					ih.bind(smsIdColumn, smsMessage.getId());
					ih.bind(phoneColumn, smsMessage.getNumber());
					ih.bind(threadIDColumn, smsMessage.getThreadID());
					ih.bind(typeColumn, smsMessage.getType());
					ih.bind(dateColumn, smsMessage.getDate());
					ih.bind(smsPartsColumn, smsMessage.getSmsParts());

					// Insert the row into the database.
					ih.execute();		
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally {
			if(ih!=null )
				ih.close();  // See comment below from Stefan Anca
		}
	}finally{
		closeDatabase(db);
	}
}
 
开发者ID:noundla,项目名称:SMSListTracker,代码行数:44,代码来源:SMSListDBHelper.java


注:本文中的android.database.DatabaseUtils.InsertHelper.bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。