<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/templates/default/atom.css" type="text/css" ?>

<feed 
   xmlns="http://www.w3.org/2005/Atom"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    <link href="http://www.kevinwoolley.com/index.php?/feeds/atom10.xml" rel="self" title="Eclectic Programming" type="application/atom+xml" />
    <link href="http://www.kevinwoolley.com/"                        rel="alternate"    title="Eclectic Programming" type="text/html" />
    <link href="http://www.kevinwoolley.com/rss.php?version=2.0"     rel="alternate"    title="Eclectic Programming" type="application/rss+xml" />
    <title type="html">Eclectic Programming</title>
    <subtitle type="html">Coding in the Hills</subtitle>
    <icon>http://www.kevinwoolley.com/templates/bulletproof/img/s9y_banner_small.png</icon>
    <id>http://www.kevinwoolley.com/</id>
    <updated>2010-03-26T22:34:12Z</updated>
    <generator uri="http://www.s9y.org/" version="1.5.1">Serendipity 1.5.1 - http://www.s9y.org/</generator>
    <dc:language>en</dc:language>

    <entry>
        <link href="http://www.kevinwoolley.com/index.php?/archives/2-Access-and-MySql-the-auto-increment-saga.html" rel="alternate" title="Access and MySql - the auto-increment saga" />
        <author>
            <name>Kevin</name>
                    </author>
    
        <published>2010-02-09T22:55:26Z</published>
        <updated>2010-03-26T22:34:12Z</updated>
        <wfw:comment>http://www.kevinwoolley.com/wfwcomment.php?cid=2</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.kevinwoolley.com/rss.php?version=atom1.0&amp;type=comments&amp;cid=2</wfw:commentRss>
    
    
        <id>http://www.kevinwoolley.com/index.php?/archives/2-guid.html</id>
        <title type="html">Access and MySql - the auto-increment saga</title>
        <content type="xhtml" xml:base="http://www.kevinwoolley.com/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>I've been implementing an upgrade for a set of Access databases to replace the Access file database with MySQL linked by ODBC. &#160;Everything seems to be going remarkably smoothly except for the common concept of inserting a record into a table with an auto-increment id column and retrieving the value of the id just created. &#160;Of course on PHP or the like one would just use the </p> <br />
<pre>  SELECT LAST_INSERT_ID()<br />
</pre> <br />
<p>Function &#160;to retrieve the ID. However the <a href="http://dev.mysql.com/doc/refman/5.1/en/connector-odbc-usagenotes-functionality.html#connector-odbc-usagenotes-functionality-last-insert-id">MySQL documentation itself</a> says that this doesn't work for certain ODBC applications such as Delphi or Access and suggests using&#160;</p> <br />
<pre>  SELECT * FROM tbl WHERE auto IS NULL;<br />
</pre> <br />
<p>Unfortunately&#160;this simply didn't work for me when called from inside the Access application I was working with, and there seems to be several comments around the web that indeed this is unreliable as Access may drop the data connection and reconnect behind the scenes - thus invalidating the call.</p> <br />
<p>As an alternative I decided to use a MySQL function to add a blank record to the table, returning the id which Access would then use to update the record (which fits well with the code-style of the existing application). &#160;Unfortunately&#160;this apparently straightforward work-around fails to be simple either as long-standing bugs in MySQL make finding valid code that can both send and return a variable something of a challenge. &#160;Several examples on the web will work within the limited domain of using either just IN or OUT variables but fail to work with both.</p> <br />
<p>My final solution, which works on the MySQL 5.1 and Access 2003 combination I am deploying, is as follows</p> <br />
<p>MySQL procedure</p> <br />
<pre>DELIMITER $$<br />
CREATE<br />
    PROCEDURE `alicedata`.`sp_ins_identity`(IN tablename VARCHAR(50))<br />
    BEGIN<br />
    SET @result = 0;<br />
    SET @sqlproc = CONCAT("INSERT INTO ",tablename," () VALUES ();");<br />
    PREPARE s1 FROM @sqlproc;<br />
    EXECUTE s1;<br />
    DEALLOCATE PREPARE s1;<br />
    SELECT LAST_INSERT_ID();<br />
    END$$<br />
</pre> <br />
<p>This procedure is useful in that it will insert a row and return the id for any table where a row contains all null fields or non-null fields with defaults defined.</p> <br />
<pre>Public Function InsertMySQLIdentityRow(DSN As String, Tablename As String) As Integer<br />
On Error GoTo Err_InsertMySQLIdentity<br />
<br />
Dim cnnSQL As New ADODB.Connection<br />
Dim cmdSQL As ADODB.Command<br />
Dim pid As Integer<br />
Dim rs<br />
Dim strSQL As String<br />
<br />
    ' initialize<br />
    pid = 0<br />
<br />
    ' set up ADO connection<br />
    Set cnnSQL = New ADODB.Connection<br />
    cnnSQL.Open DSN<br />
    <br />
    ' execute the procedure - note that assembling by parameter fails to handle IN or OUT correctly<br />
    Set cmdSQL = New ADODB.Command<br />
    cmdSQL.ActiveConnection = cnnSQL<br />
    strSQL = "call sp_ins_identity('" &amp; Tablename &amp; "');"<br />
    Set rs = CreateObject("ADODB.Recordset")<br />
    Set rs = cnnSQL.Execute(strSQL)<br />
    If Not rs.EOF Then<br />
      pid = rs(0)<br />
    End If<br />
    <br />
    ' clean up<br />
    Set rs = Nothing<br />
    Set cmdSQL = Nothing<br />
    cnnSQL.Close<br />
    Set cnnSQL = Nothing<br />
   <br />
Exit_InsertMySQLIdentity:<br />
    InsertMySQLIdentityRow = pid<br />
    Exit Function<br />
Err_InsertMySQLIdentity:<br />
    MsgBox Err.Number &amp; Err.Description<br />
    Resume Exit_InsertMySQLIdentity<br />
End Function<br />
</pre>This code is somewhat unusual in that normally, on MSSQL, you would use a parametrized  &#160;procedure call, but due to bugs in the MySQL ODBC (or at least&#160;incompatibilities&#160;with Access) the above seems to be the only way that allows both data to be passed and returned.<br />
<br />
<p> </p> 
            </div>
        </content>
        
    </entry>
    <entry>
        <link href="http://www.kevinwoolley.com/index.php?/archives/1-Firefox-behaving-badly-with-iframes-and-wirefusion-applet.html" rel="alternate" title="Firefox behaving badly with iframes and wirefusion applet" />
        <author>
            <name>Kevin</name>
                    </author>
    
        <published>2010-01-20T08:54:07Z</published>
        <updated>2010-01-21T21:13:49Z</updated>
        <wfw:comment>http://www.kevinwoolley.com/wfwcomment.php?cid=1</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://www.kevinwoolley.com/rss.php?version=atom1.0&amp;type=comments&amp;cid=1</wfw:commentRss>
    
    
        <id>http://www.kevinwoolley.com/index.php?/archives/1-guid.html</id>
        <title type="html">Firefox behaving badly with iframes and wirefusion applet</title>
        <content type="xhtml" xml:base="http://www.kevinwoolley.com/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>It's unusual to find Firefox (3.5) misbehaving - usually it's my default standards-compliant&#160;browser - but I recently posted a question to Stackoverflow as a direct result of Firefox behaving very strangely indeed.</p> <br />
<p>I've been developing various bits of eyecandy for one of my clients who owns the <a href="www.tartanweb.com">Tartanweb </a>website, one of which is a 3D model of a man in Highland Dress who can be interactively rotated and dressed in different tartans, jacket styles and so forth. &#160;The applet was coded up using <a href="http://www.demicron.com/wirefusion/">Wirefusion</a>, and previously we've always displayed it in it's own browser window.</p> <br />
<p>As part of developing a redesign of the site we decided to display the applet in a Lightbox type popup - actually using Kevin Millar's excellent <a href="http://www.stickmanlabs.com/lightwindow/">Lightwindow</a> implementation. &#160;I used an embedded iframe for this, so the lightbox popup is displaying a simple web page which consists almost&#160;completely&#160;of an iframe, within which is the actual web page containing the Wirefusion applet. &#160;So far so good, and the lightbox popped up, initialized and displayed the applet just fine in all versions of IE, Chrome and Safari. &#160;Firefox however refused to work, giving me a javascript error whenever I tried to call any of the exposed functions</p> <br />
<p><span style="color: #000000; font-family: Consolas, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New'; font-size: 14px; border-collapse: collapse; line-height: 18px; white-space: pre; "><span class="typ" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: #2b91af; ">Error</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: black; ">:</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: black; "> document</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: black; ">.</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: black; ">appletname</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: black; ">.</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: black; ">send </span><span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: #00008b; ">is</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: black; "> </span><span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: #00008b; ">not</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: black; "> a </span><span class="kwd" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: #00008b; ">function</span></span></p> <br />
<p>Investigation by inserting diagnostic Javascript (being in an iframe it was difficult to get to the raw code generated directly and the page works just fine if not executed via the lightbox) revealed no oddities about the page - there was indeed just one embedded applet with the correct name, Firefox just couldn't see the exposed send function.</p> <br />
<p>Closer investigation of the javascript generated by Wirefusion to load the applet (launcher.js) revealed that this functions by dynamically writing the applet code to the page on load, which suggests a timing bug. &#160;Firefox also behaves strangely in that when the applet page loads the applet appears to initialize twice - a behaviour not seen with other browsers. &#160;To fix this I amended the launcher code to encapsulate the javascript writing out the applet code in a function which returns the code in a string, and used this to set the innerHTML property of a dummy div called from the window.onLoad event. &#160;Which worked - although only in Firefox. &#160;To include IE and Safari I needed to add some browser detect code and write out the applet directly as before for these two.</p> <br />
<p>So decidedly strange, although with the trail of main page -&gt; lightbox -&gt; iframe -&gt; java applet perhaps understandable, it must be an unusual combination. &#160;That it happens with Firefox only is the real surprise and I'll make a note to retest it on each significant Firefox update. </p> <br />
<p> </p> 
            </div>
        </content>
        
    </entry>

</feed>