当前位置:  开发笔记 > 编程语言 > 正文

如何使用SQLite批量插入?

如何解决《如何使用SQLite批量插入?》经验,为你挑选了1个好方法。

如何使用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



1> JP Richardso..:

我编写了一个类来帮助在SQLite中实现批量插入.希望它有用:

http://procbits.com/2009/09/08/sqlite-bulk-insert/

-J.P

推荐阅读
勤奋的瞌睡猪_715
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有