Android的SQLite的插入或更换(Android SQLite INSERT or REPL

2019-09-22 01:05发布

我尝试插入或因为没有行插入的SQLite没有成功REPLACE语法为止。

我创建表查询

 create table providers (provider_id text not null, provider_name text not null,  provider_channel_id text not null, channel_name text not null);CREATE UNIQUE INDEX channel_id ON providers (provider_channel_id);

我的插入或更换查询

INSERT OR REPLACE INTO providers (provider_channel_id, channel_name, provider_id, provider_name) VALUES ('1', '2', '3', '4')

谢谢

Answer 1:

我发现.replace而不是插入的解决方案,你也应该有一个行ID在表中,并将其设置为PRIMARY KEY

 bdd.replace(table,null, contentValues);


文章来源: Android SQLite INSERT or REPLACE