{"id":57,"date":"2012-05-14T16:34:46","date_gmt":"2012-05-14T16:34:46","guid":{"rendered":"http:\/\/blog.mozilla.org\/nfroyd\/?p=57"},"modified":"2012-05-14T16:34:46","modified_gmt":"2012-05-14T16:34:46","slug":"statement-wrappers-have-been-deprecated","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nfroyd\/2012\/05\/14\/statement-wrappers-have-been-deprecated\/","title":{"rendered":"statement wrappers have been deprecated"},"content":{"rendered":"<p>It&#8217;s a lot of fun removing old code; it&#8217;s less fun when removing that old code breaks lots of things.\u00a0 That&#8217;s what happened when <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=589032\">bug 589032<\/a> was checked in to mozilla-central last week.  We had deprecated <code>mozIStorageStatementWrapper<\/code> over a year ago; bug 589032 removed <code>mozIStorageStatementWrapper<\/code> in favor of using <code>mozIStorageStatement<\/code> directly.<\/p>\n<p>As there have been a couple reports of breakage (which likely means there&#8217;s a lot more breakage pending), and I have claimed in the bug that fixing said breakage is a straightforward process, here&#8217;s the quick-n-dirty guide to doing so.  (Warning: may contain bugs or be incomplete.  Please note any oversights in the comments.)<\/p>\n<p>Code that created wrappers:<\/p>\n<pre>\r\nvar wrapper = new Components.Constructor(\"@mozilla.org\/storage\/statement-wrapper;1\",\r\n                                         Ci.mozIStorageStatementWrapper,\r\n                                         \"initialize\");\r\nfunction createStatement(db, aSQL) {\r\n  return new wrapper(db.createStatement(aSQL));\r\n}\r\n<\/pre>\n<p>or perhaps:<\/p>\n<pre>\r\nvar wrapper = Cc[\"@mozilla.org\/storage\/statement-wrapper;1\"]\r\n                .createInstance(Ci.mozIStorageStatementWrapper);\r\nwrapper.initialize(statement);\r\n<\/pre>\n<p>should be replaced with:<\/p>\n<pre>function createStatement(db, aSQL) {\r\n  return db.createStatement(aSQL);\r\n}\r\n<\/pre>\n<p>Of course, that&#8217;s almost not worth having a separate function for. \ud83d\ude42<\/p>\n<p>Nearly all of the methods that you were calling on the wrapper remain unchanged, with the exception of:<\/p>\n<pre>foo = wrapped_stmt.execute();<\/pre>\n<p>That should be replaced with:<\/p>\n<pre>foo = stmt.executeStep();<\/pre>\n<p>Statements have an <code>execute()<\/code> method, but it does something slightly different than the wrapper&#8217;s <code>execute()<\/code> method.<\/p>\n<p>Finally, where you finalize your statements (you are finalizing your statements, right?):<\/p>\n<pre>wrapped_stmt.statement.finalize();<\/pre>\n<p>is now simply:<\/p>\n<pre>statement.finalize();<\/pre>\n<p>As I said earlier, please note any omissions or errors in the comments!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s a lot of fun removing old code; it&#8217;s less fun when removing that old code breaks lots of things.\u00a0 That&#8217;s what happened when bug 589032 was checked in to mozilla-central last week. We had deprecated mozIStorageStatementWrapper over a year ago; bug 589032 removed mozIStorageStatementWrapper in favor of using mozIStorageStatement directly. As there have been [&hellip;]<\/p>\n","protected":false},"author":320,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/posts\/57"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/users\/320"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nfroyd\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}