{"id":279,"date":"2011-02-21T23:09:40","date_gmt":"2011-02-21T23:09:40","guid":{"rendered":"https:\/\/greladesign.co\/blog\/?p=279"},"modified":"2011-09-15T09:25:01","modified_gmt":"2011-09-15T08:25:01","slug":"sqlerror-error-3132-data-type-mismatchdetailsoperationexecute","status":"publish","type":"post","link":"https:\/\/greladesign.co\/blog\/2011\/02\/21\/sqlerror-error-3132-data-type-mismatchdetailsoperationexecute\/","title":{"rendered":"SQLError: &#8216;Error #3132: Data type mismatch&#8217;,details:&#8221;,operation:&#8217;execute&#8217;"},"content":{"rendered":"<p>Hi,<br \/>\nI have noticed weird error:<\/p>\n<blockquote><p>SQLError: &#8216;Error #3132: Data type mismatch&#8217;,details:&#8221;,operation:&#8217;execute&#8217;<\/p><\/blockquote>\n<p>this only happens in certain situations, this is how you can reproduce it:<br \/>\n<!--more--><br \/>\n<strong>Tables:<\/strong><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nCREATE TABLE [table_a] (\r\n[id] INTEGER  NOT NULL PRIMARY KEY,\r\n[name] VARCHAR(256)  NOT NULL,\r\n[address_id] INTEGER DEFAULT '-1' NULL\r\n);\r\n\r\nCREATE TABLE [table_b] (\r\n[id] INTEGER  NOT NULL PRIMARY KEY,\r\n[town] VARCHAR(256)  NOT NULL\r\n);\r\n\r\nCREATE TABLE [table_c] (\r\n[id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,\r\n[phone_number] VARCHAR(256) DEFAULT 'Not Set' NOT NULL,\r\n[person_id] INTEGER DEFAULT '-1' NOT NULL\r\n);\r\n<\/pre>\n<p><strong>Data:<\/strong><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nINSERT INTO table_b ('town') VALUES (&quot;buffalo&quot;);\r\nINSERT INTO table_b ('town') VALUES (&quot;ipswitch&quot;);\r\nINSERT INTO table_b ('town') VALUES (&quot;pcim&quot;);\r\n\r\nINSERT INTO table_a ('name','address_id') VALUES (&quot;john&quot;,1);\r\nINSERT INTO table_a ('name','address_id') VALUES (&quot;charles&quot;,2);\r\nINSERT INTO table_a ('name','address_id') VALUES (&quot;edek&quot;,3);\r\n\r\nINSERT INTO table_c ('phone_number','person_id') VALUES(&quot;+1 0123456789&quot;,1);\r\nINSERT INTO table_c ('phone_number','person_id') VALUES(&quot;+44 9876543210&quot;,2);\r\nINSERT INTO table_c ('phone_number','person_id') VALUES(&quot;+48 0011223344&quot;,3);\r\n<\/pre>\n<p>Code that works without the error first<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar query1:SQLStatement = new SQLStatement();\r\nquery1.sqlConnection = db;\r\n\r\nquery1.text = &quot;SELECT * FROM table_a AS a, table_b AS b, table_c AS c WHERE a.address_id=:add_id AND c.person_id=:per_id&quot;;\r\n\r\nquery1.parameters[&quot;:add_id&quot;] = &quot;b.id&quot;;\r\nquery1.parameters[&quot;:per_id&quot;] = &quot;a.id&quot;;\r\n\r\n\r\nquery1.addEventListener(SQLErrorEvent.ERROR, onQueryError, false, 0, true);\r\nquery1.addEventListener(SQLEvent.RESULT, onQueryResult, false, 0, true);\r\nquery1.execute();\r\n<\/pre>\n<p>Now code that generates aforementioned error (notice change in order of assignments) :<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar query1:SQLStatement = new SQLStatement();\r\nquery1.sqlConnection = db;\r\nquery1.text = &quot;SELECT * FROM table_a AS a, table_b AS b, table_c AS c WHERE a.address_id=:add_id AND a.id=:per_id&quot;;\r\n\r\nquery1.parameters[&quot;:add_id&quot;] = &quot;b.id&quot;;\r\nquery1.parameters[&quot;:per_id&quot;] = &quot;c.person_id&quot;;\r\n\r\n\r\nquery1.addEventListener(SQLErrorEvent.ERROR, onQueryError, false, 0, true);\r\nquery1.addEventListener(SQLEvent.RESULT, onQueryResult, false, 0, true);\r\nquery1.execute();\r\n<\/pre>\n<p>Now, this can be fixed either by reposition the column in WHERE clause or use OR instead! following is modified above code with OR instead of AND<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar query1:SQLStatement = new SQLStatement();\r\nquery1.sqlConnection = db;\r\nquery1.text = &quot;SELECT * FROM table_a AS a, table_b AS b, table_c AS c WHERE a.address_id=:add_id OR a.id=:per_id&quot;;\r\n\r\nquery1.parameters[&quot;:add_id&quot;] = &quot;b.id&quot;;\r\nquery1.parameters[&quot;:per_id&quot;] = &quot;c.person_id&quot;;\r\n\r\n\r\nquery1.addEventListener(SQLErrorEvent.ERROR, onQueryError, false, 0, true);\r\nquery1.addEventListener(SQLEvent.RESULT, onQueryResult, false, 0, true);\r\nquery1.execute();\r\n<\/pre>\n<p>the third method, to avoid this error, is actually to put it all in a string passed to <em>text<\/em> property of <em>SQLStatement<\/em>:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nquery1.text = &quot;SELECT * FROM table_a AS a, table_b AS b, table_c AS c WHERE a.address_id=b.id AND a.id=c.person_id&quot;;\r\n<\/pre>\n<p>of course by changing logical operator to OR we are changing results but no error is thrown.<\/p>\n<p>Now is it a bug or feature? If anyone has an answer please let me know.<\/p>\n<p>I have put this query on adobe forum: <a href=\"http:\/\/forums.adobe.com\/thread\/792102?tstart=0\">forums.adobe.com<\/a>, but still no answer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, I have noticed weird error: SQLError: &#8216;Error #3132: Data type mismatch&#8217;,details:&#8221;,operation:&#8217;execute&#8217; this only happens in certain situations, this is how you can reproduce it:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":""},"categories":[17,72,9,58],"tags":[12,85,84,51,54,86],"_links":{"self":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/279"}],"collection":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/comments?post=279"}],"version-history":[{"count":22,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":412,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/279\/revisions\/412"}],"wp:attachment":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/media?parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/categories?post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/tags?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}