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


Java SQLiteDatabase.insert方法代码示例

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


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

示例1: execute

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Override
public void execute(final Context context) {
    if (null == mWordList) { // This should never happen
        Log.e(TAG, "MakeAvailableAction with a null word list!");
        return;
    }
    final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId);
    if (null != MetadataDbHelper.getContentValuesByWordListId(db,
            mWordList.mId, mWordList.mVersion)) {
        Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' "
                + " for a makeavailable action. Marking as available anyway.");
    }
    DebugLogUtils.l("Making word list available : " + mWordList);
    // If mLocalFilename is null, then it's a remote file that hasn't been downloaded
    // yet, so we set the local filename to the empty string.
    final ContentValues values = MetadataDbHelper.makeContentValues(0,
            MetadataDbHelper.TYPE_BULK, MetadataDbHelper.STATUS_AVAILABLE,
            mWordList.mId, mWordList.mLocale, mWordList.mDescription,
            null == mWordList.mLocalFilename ? "" : mWordList.mLocalFilename,
            mWordList.mRemoteFilename, mWordList.mLastUpdate, mWordList.mRawChecksum,
            mWordList.mChecksum, mWordList.mRetryCount, mWordList.mFileSize,
            mWordList.mVersion, mWordList.mFormatVersion);
    PrivateLog.log("Insert 'available' record for " + mWordList.mDescription
            + " and locale " + mWordList.mLocale);
    db.insert(MetadataDbHelper.METADATA_TABLE_NAME, null, values);
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:27,代码来源:ActionBatch.java

示例2: saveMessage

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * save a message
 *
 * @param message
 * @return return cursor of the message
 */
public synchronized Integer saveMessage(InviteMessage message) {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    int id = -1;
    if (db.isOpen()) {
        ContentValues values = new ContentValues();
        values.put(InviteMessgeDao.COLUMN_NAME_FROM, message.getFrom());
        values.put(InviteMessgeDao.COLUMN_NAME_GROUP_ID, message.getGroupId());
        values.put(InviteMessgeDao.COLUMN_NAME_GROUP_Name, message.getGroupName());
        values.put(InviteMessgeDao.COLUMN_NAME_REASON, message.getReason());
        values.put(InviteMessgeDao.COLUMN_NAME_TIME, message.getTime());
        values.put(InviteMessgeDao.COLUMN_NAME_STATUS, message.getStatus().ordinal());
        values.put(InviteMessgeDao.COLUMN_NAME_GROUPINVITER, message.getGroupInviter());
        db.insert(InviteMessgeDao.TABLE_NAME, null, values);

        Cursor cursor = db.rawQuery("select last_insert_rowid() from " + InviteMessgeDao.TABLE_NAME, null);
        if (cursor.moveToFirst()) {
            id = cursor.getInt(0);
        }

        cursor.close();
    }
    return id;
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:30,代码来源:DemoDBManager.java

示例3: insertRandomNumbers

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void insertRandomNumbers(int id,int one , int two ,int three , int four , int five) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(ID,id);
    contentValues.put(ONE, one);
    contentValues.put(TWO, two);
    contentValues.put(THREE, three);
    contentValues.put(FOUR, four);
    contentValues.put(FIVE, five);

    SQLiteDatabase db = this.getWritableDatabase();
    db.beginTransaction();
    db.insert(TABLE_NAME4, null, contentValues);
    db.setTransactionSuccessful();
    db.endTransaction();
    db.close();
}
 
开发者ID:sarveshchavan7,项目名称:Trivia-Knowledge,代码行数:17,代码来源:DemoHelperClass.java

示例4: insertMedia

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public boolean insertMedia(Media media) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(Co_Media_Id,media.getId());
    contentValues.put(Co_Media_Title,media.getTitle());
    contentValues.put(Co_Media_Creator,media.getCreator());
    contentValues.put(Co_Media_Season,media.getSeason());
    contentValues.put(Co_Media_Episode,media.getEpisode());
    contentValues.put(Co_Media_Category,media.getCategory());
    contentValues.put(Co_Media_Description,media.getDescription());
    long result = db.insert(Tb_Media,null ,contentValues);
    if (result == -1)
        return false;

    int count = 0;
    for (Review review : media.getReviews())
        if (insertReview(review))
            count++;

    return true;
}
 
开发者ID:NonlinearFruit,项目名称:Retrospector-Android,代码行数:22,代码来源:RetroDbHelper.java

示例5: addLog

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
void addLog(String userPhoneNumber, String category, String log, String meta, String localDate, String localTime, String utcDate, String utcTime, int logImage) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues contentValues = new ContentValues();
    contentValues.put(USER_PHONE_NUMBER, userPhoneNumber);
    contentValues.put(CATEGORY, category);
    contentValues.put(LOG, log);
    contentValues.put(META, meta);
    contentValues.put(LOCAL_DATE, localDate);
    contentValues.put(LOCAL_TIME, localTime);
    contentValues.put(UTC_DATE, utcDate);
    contentValues.put(UTC_TIME, utcTime);
    contentValues.put(LOG_IMAGE, logImage);

    db.insert(TABLE_ACTIVITIES, null, contentValues);
    db.close();
}
 
开发者ID:kunalrmhatre,项目名称:fussroll,代码行数:18,代码来源:DatabaseHandler.java

示例6: InsertQid

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void InsertQid(int id) {
    ContentValues contentValues = new ContentValues();
    contentValues.put(CORRECTNO, id);
    SQLiteDatabase db = this.getWritableDatabase();
    db.beginTransaction();
    db.insert(TABLE_NAME2, null, contentValues);
    db.setTransactionSuccessful();
    db.endTransaction();
   /* Toast.makeText(context,"the answer was correct"+id+"was added",Toast.LENGTH_SHORT).show();*/
    db.close();
}
 
开发者ID:sarveshchavan7,项目名称:Trivia-Knowledge,代码行数:12,代码来源:DemoHelperClass.java

示例7: addCPubMeHelp

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addCPubMeHelp(MyPubMeHelp msg) {
	SQLiteDatabase db = this.getWritableDatabase();
	ContentValues cv = new ContentValues();
	cv.put("id", getCount());
	cv.put("reqItemName", msg.getReqItemName());
	cv.put("helpUserID", msg.getHelpUserID());
	cv.put("reqItemID", msg.getReqItemID());
	cv.put("startTime", msg.getStartTime());
	cv.put("endTime", msg.getEndTime());
	db.insert(TABLE_NAME, null, cv);

}
 
开发者ID:qizhenghao,项目名称:HiBangClient,代码行数:13,代码来源:PubMeHelpDB.java

示例8: insertBook

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public long insertBook(String title, String author, String subject,
                          String dateRead, int status) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(BOOK_COLUMN_TITLE, title);
    contentValues.put(BOOK_COLUMN_AUTHOR, author);
    contentValues.put(BOOK_COLUMN_SUBJECT, subject);
    contentValues.put(BOOK_COLUMN_DATE_READ, dateRead);
    contentValues.put(BOOK_COLUMN_STATUS, status);
    return db.insert("BOOK", null, contentValues);

}
 
开发者ID:teodorakostova,项目名称:BookWorldClient,代码行数:13,代码来源:BookManager.java

示例9: insert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
@Nullable
@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
    DebugLog.logMethod();
    DebugLog.logMessage("Uri " + uri.toString());

    Uri returnUri;
    SQLiteDatabase writableDatabase = couponDbHelper.getWritableDatabase();
    switch (uriMatcher.match(uri)) {
        case COUPON: {
            DebugLog.logMessage("COUPON");
            long rowId = writableDatabase.insert(
                    CouponContract.CouponTable.TABLE_NAME,
                    null,
                    values
            );
            returnUri = CouponContract.CouponTable.makeUriForCoupon(rowId);
            break;
        }

        default: {
            throw new UnsupportedOperationException("Unknown URI:" + uri);
        }
    }

    notifyDataChange(uri);
    return returnUri;
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:29,代码来源:CouponProvider.java

示例10: saveUser

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void saveUser(QBUser qbUser) {
    ContentValues cv = new ContentValues();
    DbHelper dbHelper = new DbHelper(mContext);
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    cv.put(DbHelper.DB_COLUMN_USER_FULL_NAME, qbUser.getFullName());
    cv.put(DbHelper.DB_COLUMN_USER_LOGIN, qbUser.getLogin());
    cv.put(DbHelper.DB_COLUMN_USER_ID, qbUser.getId());
    cv.put(DbHelper.DB_COLUMN_USER_PASSWORD, qbUser.getPassword());
    cv.put(DbHelper.DB_COLUMN_USER_TAG, qbUser.getTags().getItemsAsString());

    db.insert(DbHelper.DB_TABLE_NAME, null, cv);
    dbHelper.close();
}
 
开发者ID:mobilemaster128,项目名称:quickblox-android,代码行数:14,代码来源:QbUsersDbManager.java

示例11: addProduct

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addProduct (Products product){
    ContentValues values=new ContentValues();
    values.put(COLUMN_PRODUCTNAME,product.get_productname());
    SQLiteDatabase db=getWritableDatabase();
    db.insert(TABLE_PRODUCTS,null,values);
    db.close();

}
 
开发者ID:hacktoberfest17,项目名称:programming,代码行数:9,代码来源:MyDBHandler.java

示例12: columnsTest

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Test columns order.
 */
@Test
public void columnsTest() {
    final SQLiteDatabase db = this.sqlite.getWritableDatabase();
    try {
        db.insert(TABLE, null, values("Jimmy"));
        final Cursor cursor = new TableSqlite(TABLE, db).cursor(
            Arrays.asList(COL_NAME, COL_ID),
            Collections.<WhereArg>emptyList(),
            Collections.<String>emptyList(),
            -1
        );
        try {
            MatcherAssert.assertThat(
                COL_NAME,
                cursor.getColumnName(0),
                Matchers.equalTo(COL_NAME)
            );
            MatcherAssert.assertThat(
                COL_ID,
                cursor.getColumnName(1),
                Matchers.equalTo(COL_ID)
            );
        } finally {
            cursor.close();
        }
    } finally {
        db.close();
    }
}
 
开发者ID:g4s8,项目名称:QueryLite,代码行数:33,代码来源:TableSqliteTest.java

示例13: bulkInsert

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
/**
 * Handles requests to insert a set of new rows. In Sunshine, we are only going to be
 * inserting multiple rows of data at a time from a weather forecast. There is no use case
 * for inserting a single row of data into our ContentProvider, and so we are only going to
 * implement bulkInsert. In a normal ContentProvider's implementation, you will probably want
 * to provide proper functionality for the insert method as well.
 *
 * @param uri    The content:// URI of the insertion request.
 * @param values An array of sets of column_name/value pairs to add to the database.
 *               This must not be {@code null}.
 *
 * @return The number of values that were inserted.
 */
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
    final SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    switch (sUriMatcher.match(uri)) {

        case CODE_WEATHER:
            db.beginTransaction();
            int rowsInserted = 0;
            try {
                for (ContentValues value : values) {
                    long weatherDate =
                            value.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE);
                    if (!SunshineDateUtils.isDateNormalized(weatherDate)) {
                        throw new IllegalArgumentException("Date must be normalized to insert");
                    }

                    long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value);
                    if (_id != -1) {
                        rowsInserted++;
                    }
                }
                db.setTransactionSuccessful();
            } finally {
                db.endTransaction();
            }

            if (rowsInserted > 0) {
                getContext().getContentResolver().notifyChange(uri, null);
            }

            return rowsInserted;

        default:
            return super.bulkInsert(uri, values);
    }
}
 
开发者ID:fjoglar,项目名称:android-dev-challenge,代码行数:51,代码来源:WeatherProvider.java

示例14: addTask

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public void addTask(DayTask task){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(VARS.TITLE, task.getTitle());
    values.put(VARS.DESCRIPTION, task.getDescription());
    values.put(VARS.DATE, task.getDate());
    values.put(VARS.STATUS, "false");
    values.put(VARS.TIME, task.getTime());

    db.insert(VARS.TABLE_NAME, null, values);
    Toast.makeText(context, "Task Added Successfully", Toast.LENGTH_SHORT).show();
    db.close();
}
 
开发者ID:mehedi-shafi,项目名称:My-Day,代码行数:15,代码来源:DatabaseHandler.java

示例15: insertVideoPosition

import android.database.sqlite.SQLiteDatabase; //导入方法依赖的package包/类
public static void insertVideoPosition(String videoId, int position) {
	
	SQLiteDatabase database = sqLiteOpenHelper.getWritableDatabase();
	if (database.isOpen()) {
		ContentValues values = new ContentValues();
		values.put("videoId", videoId);
		values.put("position", position);
		database.insert(VIDEOPOSITION, null, values);
		database.close();
	}
}
 
开发者ID:lbbniu,项目名称:CCDownload,代码行数:12,代码来源:DataSet.java


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