简体   繁体   English

使用ContentProvider从第一个表到第二个表插入几行

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

I wonder how to implement this with ContentProvider? 我想知道如何用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.. 如果我应该使用插入方法,则无法获得这几个新的ID。

edit: If this is insert method what Uri I should return? 编辑:如果这是插入方法我应该返回什么Uri

Call execSql 调用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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在第二个活动通过ContentProvider插入数据库后,第一个活动的列表视图未更新; onLoadFinished不被调用 - 1st Activity's listview not updated after 2nd activity inserts into database via ContentProvider; onLoadFinished not called 从Android中的第一个应用程序开始第二个应用程序的活动 - Start Activity of 2nd app from 1st app in android 如何从第二活动到第一活动获取数据 - How to get data from 2nd Activity to 1st Activity 将第1个活动的值传递给android中的第2个活动 - Pass the value from 1st activity to 2nd activity in android 如何将代码从第二类添加到第一类 - How to add code from 2nd class to 1st class 从第一个活动转到第二个活动时出错 - error when going from 1st activity to 2nd activity 是否可以使用 navigator.pop 刷新或重新加载页面...例如第 1(nav.push=>2)页到第 2 页,然后从第 2(nav.pop,值)返回到第 1 页? - is it possible to refresh or reload page with navigator.pop... like 1st (nav.push=>2) page to 2nd page and back from 2nd (nav.pop, value) to 1st page? 如何从第一个和第二个 position 手动从 Kotlin ZE84E30B9390CDB4864DZDB6C - How to get object from 1st and 2nd position manually from LinkedHashMap in Kotlin Android? 将用户单击/滑动的项目从第一个片段的一个列表视图转移到第二个片段的另一个列表视图 - Transferring user clicked/swiped item from one listview in 1st fragment to another listview in 2nd fragment 从3rdfragment选项卡过渡到2nd / 1stfragment选项卡,中断了应用程序 - Transition from 3rd fragment tab to 2nd/1st fragment tab , breaks the app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM