简体   繁体   中英

Insert several rows from 1st table to the 2nd with ContentProvider

I wonder how to implement this with ContentProvider? I insert several rows from table to another with single select statment:

insert into table1 (field1, field2,...) 
     select field1, field2... from table2 where ...

If I should use insert method, I cannot get this several new id..

edit: If this is insert method what Uri I should return?

Call execSql

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
  switch (sUriMatcher.match(uri)){
    case URI_1:
     SQLiteDatabase db = mOpenHelper.getWritableDatabase();
     db.execSql("insert into table1 (field1, field2,...) 
     select field1, field2... from table2 where ...");
     return uri;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM