<legend id='1MWVp'><style id='1MWVp'><dir id='1MWVp'><q id='1MWVp'></q></dir></style></legend>
    • <bdo id='1MWVp'></bdo><ul id='1MWVp'></ul>
  • <tfoot id='1MWVp'></tfoot>

        <i id='1MWVp'><tr id='1MWVp'><dt id='1MWVp'><q id='1MWVp'><span id='1MWVp'><b id='1MWVp'><form id='1MWVp'><ins id='1MWVp'></ins><ul id='1MWVp'></ul><sub id='1MWVp'></sub></form><legend id='1MWVp'></legend><bdo id='1MWVp'><pre id='1MWVp'><center id='1MWVp'></center></pre></bdo></b><th id='1MWVp'></th></span></q></dt></tr></i><div id='1MWVp'><tfoot id='1MWVp'></tfoot><dl id='1MWVp'><fieldset id='1MWVp'></fieldset></dl></div>

        <small id='1MWVp'></small><noframes id='1MWVp'>

        “如果不存在则插入"SQLite 中的语句

        时间:2023-09-18
        1. <legend id='tbfv6'><style id='tbfv6'><dir id='tbfv6'><q id='tbfv6'></q></dir></style></legend>
          • <tfoot id='tbfv6'></tfoot>

              <small id='tbfv6'></small><noframes id='tbfv6'>

                  <tbody id='tbfv6'></tbody>

                  <bdo id='tbfv6'></bdo><ul id='tbfv6'></ul>
                • <i id='tbfv6'><tr id='tbfv6'><dt id='tbfv6'><q id='tbfv6'><span id='tbfv6'><b id='tbfv6'><form id='tbfv6'><ins id='tbfv6'></ins><ul id='tbfv6'></ul><sub id='tbfv6'></sub></form><legend id='tbfv6'></legend><bdo id='tbfv6'><pre id='tbfv6'><center id='tbfv6'></center></pre></bdo></b><th id='tbfv6'></th></span></q></dt></tr></i><div id='tbfv6'><tfoot id='tbfv6'></tfoot><dl id='tbfv6'><fieldset id='tbfv6'></fieldset></dl></div>
                  本文介绍了“如果不存在则插入"SQLite 中的语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 SQLite 数据库.我正在尝试在表 bookmarks 中插入值(users_idlessoninfo_id),前提是两者之前连续不存在.

                  I have an SQLite database. I am trying to insert values (users_id, lessoninfo_id) in table bookmarks, only if both do not exist before in a row.

                  INSERT INTO bookmarks(users_id,lessoninfo_id) 
                  VALUES(
                      (SELECT _id FROM Users WHERE User='"+$('#user_lesson').html()+"'),
                          (SELECT _id FROM lessoninfo 
                          WHERE Lesson="+lesson_no+" AND cast(starttime AS int)="+Math.floor(result_set.rows.item(markerCount-1).starttime)+") 
                          WHERE NOT EXISTS (
                              SELECT users_id,lessoninfo_id from bookmarks 
                              WHERE users_id=(SELECT _id FROM Users 
                              WHERE User='"+$('#user_lesson').html()+"') AND lessoninfo_id=(
                                  SELECT _id FROM lessoninfo
                                  WHERE Lesson="+lesson_no+")))
                  

                  这给出了一个错误说:

                  靠近 where 语法的数据库错误.

                  db error near where syntax.

                  推荐答案

                  如果你有一个名为 memos 的表格,它有两列 idtext 你应该能够这样做:

                  If you have a table called memos that has two columns id and text you should be able to do like this:

                  INSERT INTO memos(id,text) 
                  SELECT 5, 'text to insert' 
                  WHERE NOT EXISTS(SELECT 1 FROM memos WHERE id = 5 AND text = 'text to insert');
                  

                  如果记录已经包含一行,其中 text 等于 'text to insert' 并且 id 等于 5,那么插入操作将被忽略.

                  If a record already contains a row where text is equal to 'text to insert' and id is equal to 5, then the insert operation will be ignored.

                  我不知道这是否适用于您的特定查询,但也许它可以为您提供有关如何进行的提示.

                  I don't know if this will work for your particular query, but perhaps it give you a hint on how to proceed.

                  我建议您改为设计表格,以便按照 @CLs answer 下面.

                  I would advice that you instead design your table so that no duplicates are allowed as explained in @CLs answer below.

                  这篇关于“如果不存在则插入"SQLite 中的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带有加密/密码保护的 SQLite 下一篇:在 SQLite 上加入表时如何进行更新?

                  相关文章

                  <i id='KPSEs'><tr id='KPSEs'><dt id='KPSEs'><q id='KPSEs'><span id='KPSEs'><b id='KPSEs'><form id='KPSEs'><ins id='KPSEs'></ins><ul id='KPSEs'></ul><sub id='KPSEs'></sub></form><legend id='KPSEs'></legend><bdo id='KPSEs'><pre id='KPSEs'><center id='KPSEs'></center></pre></bdo></b><th id='KPSEs'></th></span></q></dt></tr></i><div id='KPSEs'><tfoot id='KPSEs'></tfoot><dl id='KPSEs'><fieldset id='KPSEs'></fieldset></dl></div>

                    <small id='KPSEs'></small><noframes id='KPSEs'>

                    1. <legend id='KPSEs'><style id='KPSEs'><dir id='KPSEs'><q id='KPSEs'></q></dir></style></legend>
                        <bdo id='KPSEs'></bdo><ul id='KPSEs'></ul>
                    2. <tfoot id='KPSEs'></tfoot>