{"id":4782,"date":"2024-12-11T15:26:05","date_gmt":"2024-12-11T15:26:05","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4782"},"modified":"2024-12-11T15:26:16","modified_gmt":"2024-12-11T15:26:16","slug":"insert-or-update","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/database\/sqlite\/queries\/insert-or-update","title":{"rendered":"INSERT or UPDATE"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">INSERT or UPDATE Example<\/h4>\n\n\n\n<p>What we actually do in SQLite is somehing they call UPSERT<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    #Strings should be added as parameters to avoid sanatisation risks unless you know they are safe.\n    #Other values can be added as parameters too or inline in the INSERT text.    \n    db1cursor.execute(\"\"\"INSERT INTO my_table (\n                        some_string_column,\n                        some_value_column\n                    ) VALUES (\n                        ?,\n                        ?\n                    )\n                      ON CONFLICT(some_string_column) DO UPDATE SET some_value_column=?;\n                    \"\"\",\n                    (my_string1, my_value1, my_value1));\n    db1.commit()\n    #if db1cursor.rowcount &lt; 0:\n    #    print(\"FAILED\");<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>INSERT or UPDATE Example What we actually do in SQLite is somehing they call UPSERT<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[355],"tags":[],"class_list":["post-4782","post","type-post","status-publish","format-standard","hentry","category-queries"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4782"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4782\/revisions"}],"predecessor-version":[{"id":4783,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4782\/revisions\/4783"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}