如何使用SQLite批量插入?
我查了一下,似乎我做了一个带有select语句的插入.我用Google搜索,看了一下示例,他们看起来都像是将数据从一个表复制到另一个表,或者与SQLite不兼容.我想做点什么
"INSERT INTO user_msg_media (recipientId, mediaId, catagory, current_media_date) " + "VALUES(@mediaId, @catagory, @current_media_date)"; where the value of recipientId is the watcher from each of "SELECT watcher FROM userwatch WHERE watched=@watched";
我尝试了下面的代码,我得到错误"SQLite错误没有这样的列:观察者"
command.CommandText = "CREATE TABLE if not exists user_msg_media( " + "msgId INTEGER PRIMARY KEY, " + "recipientId INTEGER, " + "mediaId INTEGER, " + "catagory INTEGER, " + "current_date DATE);"; command.ExecuteNonQuery(); //user media command.CommandText = "CREATE TABLE if not exists user_watch( " + "indx INTEGER PRIMARY KEY, " + "watcher INTEGER, " + "watched INTEGER);"; command.ExecuteNonQuery(); //... command.CommandText = "SELECT watcher FROM user_watch WHERE watched=:watched;"; command.Parameters.Add(":watched", DbType.Int64).Value = 1; command.ExecuteNonQuery(); //is ok command.CommandText = "INSERT INTO user_msg_media (recipientId, mediaId, catagory, current_media_date) " + "SELECT watcher, :mediaId, :category, :current_media_date" + "FROM user_watch WHERE watched=:watched;"; command.Parameters.Add(":mediaId", DbType.Int64).Value = 0; command.Parameters.Add(":category", DbType.Int64).Value = 0; command.Parameters.Add(":current_media_date", DbType.Int64).Value = 0; command.Parameters.Add(":watched", DbType.Int64).Value = 1; command.ExecuteNonQuery();
JP Richardso.. 8
我编写了一个类来帮助在SQLite中实现批量插入.希望它有用:
http://procbits.com/2009/09/08/sqlite-bulk-insert/
-J.P
我编写了一个类来帮助在SQLite中实现批量插入.希望它有用:
http://procbits.com/2009/09/08/sqlite-bulk-insert/
-J.P