正确的语法从一个表行复制到另一个(sqlite的机器人) [英] correct syntax to copy from one table row to another (sqlite android)

查看:147
本文介绍了正确的语法从一个表行复制到另一个(sqlite的机器人)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请,这是复制从一个表中的特定行到另一个正确的语法?

please, is this the correct syntax for copying a particular row from one table to another?

db.execSQL("insert into Route select * from " + DATABASE_TABLE + " WHERE _id = rowId");

因为某种原因,当我调用执行该语句的方法,一切从第一个表中的项目被复制到第二个表,而不是特定行我想要的。谢谢。

because for some reason, when i call the method that executes this statement, all the items from the first table are copied into the second table and not the specific row i want. thanks.

这是方法调用的复制:

public void copyData(long rowId){
db.execSQL("insert into Route select * from " + DATABASE_TABLE + " WHERE _id = rowId"); 
}

如果没有

,请你告诉我怎么样?..

if not, could you please show me how?..

推荐答案

我看到一对夫妇的问题:

I see a couple of problems:

首先,你没有通过 ROWID 参数传送给了CopyData()方法为部分查询时,您使用的字符串 ROWID

First, you're not passing the rowId argument to your copyData() method in as part of the query, you're using the string literal rowID.

二, ROWID 具有特殊的意义 SQLite中。这是一个伪列唯一标识表的每一行,通常是被分配到 INTEGER PRIMARY KEY 列,这是我猜相同的值是如何你有 _id 声明。其结果是,当 WHERE _id = ROWID 进行评估时,这两个值总是匹配,因此所有行被选中。

Second, ROWID has special meaning in SQLite. It's a pseudo-column that uniquely identifies each row in a table and is usually the same value that gets assigned to an INTEGER PRIMARY KEY column, which I'm guessing is how you have _id declared. The result is that when WHERE _id = ROWID is evaluated, the two values always match and therefore all rows are selected.

这篇关于正确的语法从一个表行复制到另一个(sqlite的机器人)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆