<?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://blog.dynom.nl/feeds/atom.xml" rel="self" title="D-talk" type="application/atom+xml" />
    <link href="http://blog.dynom.nl/"                        rel="alternate"    title="D-talk" type="text/html" />
    <link href="http://blog.dynom.nl/rss.php?version=2.0"     rel="alternate"    title="D-talk" type="application/rss+xml" />
    <title type="html">D-talk</title>
    <subtitle type="html">The little things that pop into mind</subtitle>
    
    <id>http://blog.dynom.nl/</id>
    <updated>2010-08-17T12:31:43Z</updated>
    <generator uri="http://www.s9y.org/" version="1.2-beta4">Serendipity 1.2-beta4 - http://www.s9y.org/</generator>
    <dc:language>en</dc:language>

    <entry>
        <link href="http://blog.dynom.nl/archives/Drop-empty-columns-with-dynamically-defined-columns-and-tables_20100817_58.html" rel="alternate" title="Drop empty columns with dynamically defined columns and tables" />
        <author>
            <name>Mark van der Velden</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2010-08-17T11:54:00Z</published>
        <updated>2010-08-17T12:31:43Z</updated>
        <wfw:comment>http://blog.dynom.nl/wfwcomment.php?cid=58</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://blog.dynom.nl/rss.php?version=atom1.0&amp;type=comments&amp;cid=58</wfw:commentRss>
    
            <category scheme="http://blog.dynom.nl/categories/MySQL_5" label="MySQL" term="MySQL" />
    
        <id>http://blog.dynom.nl/archives/guid_20100817_58.html</id>
        <title type="html">Drop empty columns with dynamically defined columns and tables</title>
        <content type="xhtml" xml:base="http://blog.dynom.nl/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>For a migration process I wanted to build in extra validation in some destructive MySQL queries, to eliminate the risk that data might be lost. Of course all data is back-upped, but I rather be safe then sorry. </p><p>This is fairly straight forward, create a stored procedure and perform an ALTER statement whenever the previously defined criteria have been met. But I wanted to define a single procedure rather then create one for every table I had to drop columns from. And since you can't simply use variables for column/table names, you have to improvise a little. I came up with the following:</p><p><div class="sql" style="text-align: left"><span style="color: #808080; font-style: italic;">-- Defining the &quot;drop empty column&quot; SP</span><br />DELIMITER @@<br /><span style="color: #993333; font-weight: bold;">DROP</span> PROCEDURE <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> drop_empty_column @@<br /><span style="color: #993333; font-weight: bold;">CREATE</span> PROCEDURE drop_empty_column<span style="color: #66cc66;">&#40;</span><br />&#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">IN</span> itable VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>,<br />&#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">IN</span> icolumn VARCHAR<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>,<br />&#160; &#160; &#160; &#160; OUT succeeded INT<br /><span style="color: #66cc66;">&#41;</span><br />BEGIN<br /><br />&#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">SET</span> @amount = -<span style="color: #cc66cc;">1</span>;<br />&#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">SET</span> @itable = itable;<br />&#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">SET</span> @icolumn = icolumn;<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; <span style="color: #808080; font-style: italic;">-- Build the query, with dynamic table and column. Store the result in @amount</span><br />&#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">SELECT</span> CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SELECT COUNT('</span>, @icolumn ,<span style="color: #ff0000;">') INTO @amount FROM '</span>, @itable ,<span style="color: #ff0000;">' WHERE('</span>, @icolumn ,<span style="color: #ff0000;">' IS NOT NULL OR '</span>, @icolumn ,<span style="color: #ff0000;">' != &quot;&quot;);'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> @testSql;<br />&#160; &#160; &#160; &#160; PREPARE testSqlStmt <span style="color: #993333; font-weight: bold;">FROM</span> @testSql;<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; <span style="color: #808080; font-style: italic;">-- Execute</span><br />&#160; &#160; &#160; &#160; EXECUTE testSqlStmt;<br /><br /><br /><br />&#160; &#160; &#160; &#160; <span style="color: #808080; font-style: italic;">-- Check if we have 0 rows, else we still have data and we can't drop.</span><br />&#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">IF</span> @amount = <span style="color: #cc66cc;">0</span> THEN<br />&#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #808080; font-style: italic;">-- Build the query</span><br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">SELECT</span> CONCAT<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ALTER TABLE '</span>, @itable ,<span style="color: #ff0000;">' DROP COLUMN '</span>, @icolumn ,<span style="color: #ff0000;">';'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">INTO</span> @alterSql;<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #808080; font-style: italic;">-- Execute</span><br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; PREPARE alterSqlStmt <span style="color: #993333; font-weight: bold;">FROM</span> @alterSql;<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; EXECUTE alterSqlStmt;<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #808080; font-style: italic;">-- Update the status</span><br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">1</span> <span style="color: #993333; font-weight: bold;">INTO</span> succeeded;<br />&#160; &#160; &#160; &#160; ELSE<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333; font-weight: bold;">INTO</span> succeeded;<br />&#160; &#160; &#160; &#160; END <span style="color: #993333; font-weight: bold;">IF</span>;<br /><br />END@@<br />DELIMITER ;<br /><br /><br /><span style="color: #808080; font-style: italic;">-- Conditionally drop the column &quot;deprecated_column&quot; from table &quot;some_table&quot;</span><br />CALL drop_empty_column<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'some_table'</span>, <span style="color: #ff0000;">'deprecated_column'</span>, @succeeded<span style="color: #66cc66;">&#41;</span>;<br /><br /><span style="color: #808080; font-style: italic;">-- Show the status</span><br /><span style="color: #993333; font-weight: bold;">SELECT</span> @succeeded;<br /><br /><span style="color: #808080; font-style: italic;">-- Cleanup</span><br /><span style="color: #993333; font-weight: bold;">DROP</span> PROCEDURE <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #993333; font-weight: bold;">EXISTS</span> drop_empty_column;</div></p><p>&#160;</p><p>I'm fairly positive that this could be done in a much better way then that I'm doing here, but this works too. Simply repeat the CALL drop_empty_column(..) for every table/column combination you want to DROP and update the definition of an "empty column" to what you want. Currently it drops the column only if the values contain nothing other then NULL or "" (empty string) values.</p><p><b>Further reading:</b> <br /></p><ul><li><a onclick="javascript: pageTracker._trackPageview('/extlink/dev.mysql.com/tech-resources/articles/mysql-storedproc.html%20');"  href="http://dev.mysql.com/tech-resources/articles/mysql-storedproc.html%20" mce_href="http://dev.mysql.com/tech-resources/articles/mysql-storedproc.html ">http://dev.mysql.com/tech-resources/articles/mysql-storedproc.html&#160;</a></li><li><a onclick="javascript: pageTracker._trackPageview('/extlink/dev.mysql.com/doc/refman/5.0/en/create-procedure.html');"  href="http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html" mce_href="http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html">http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html</a><br /></li></ul> 
            </div>
        </content>
        <dc:subject>mysql</dc:subject>
<dc:subject>prepared statement</dc:subject>
<dc:subject>variable table name</dc:subject>

    </entry>
    <entry>
        <link href="http://blog.dynom.nl/archives/What-do-you-get-when-you-mix;-MSSQL,-PDO-and-uniqueidentifier_20100608_57.html" rel="alternate" title="What do you get when you mix; MSSQL, PDO and uniqueidentifier?" />
        <author>
            <name>Mark van der Velden</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2010-06-08T19:58:00Z</published>
        <updated>2010-06-13T03:54:56Z</updated>
        <wfw:comment>http://blog.dynom.nl/wfwcomment.php?cid=57</wfw:comment>
    
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://blog.dynom.nl/rss.php?version=atom1.0&amp;type=comments&amp;cid=57</wfw:commentRss>
    
            <category scheme="http://blog.dynom.nl/categories/PHP_1" label="PHP" term="PHP" />
    
        <id>http://blog.dynom.nl/archives/guid_20100608_57.html</id>
        <title type="html">What do you get when you mix; MSSQL, PDO and uniqueidentifier?</title>
        <content type="xhtml" xml:base="http://blog.dynom.nl/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>You get NULL!</p><p>Well you get NULL when you don't cast. Say for example you do the following:<div class="php" style="text-align: left"><span style="color: #ff0000">$dbh</span> = <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>..<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #ff0000">$stmt</span> = <span style="color: #ff0000">$dbh</span>-&gt;prepare<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SELECT accountid FROM dbo.Account'</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #ff0000">$stmt</span>-&gt;execute<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /><br /><a onclick="javascript: pageTracker._trackPageview('/extlink/www.php.net/echo');"  href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000">$stmt</span>-&gt;fetchColumn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// NULL</span><br />&#160;</div>
</p><p>But when you do the following:<div class="php" style="text-align: left"><br /><span style="color: #ff0000">$stmt</span> = <span style="color: #ff0000">$dbh</span>-&gt;prepare<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SELECT CAST(accountid AS varchar(36)) accountid FROM dbo.Account'</span><span style="color: #66cc66;">&#41;</span>;<br /><span style="color: #ff0000">$stmt</span>-&gt;execute<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br /><br /><a onclick="javascript: pageTracker._trackPageview('/extlink/www.php.net/echo');"  href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000">$stmt</span>-&gt;fetchColumn<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// &quot;F05C92A1-3119-4206-A123-49A759AC99FB&quot;</span><br /><br />&#160;</div></p><p>I didn't think the casting would be necessary, since according to the manual: <a onclick="javascript: pageTracker._trackPageview('/extlink/msdn.microsoft.com/en-us/library/aa226054%28SQL.80%29.aspx');"  href="http://msdn.microsoft.com/en-us/library/aa226054%28SQL.80%29.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa226054%28SQL.80%29.aspx">http://msdn.microsoft.com/en-us/library/aa226054(SQL.80).aspx</a> the datatype 'uniqueidentifier' has implicit casts with multiple data-types. But I guess it's just one of those things...<br /></p> 
            </div>
        </content>
        <dc:subject>cast</dc:subject>
<dc:subject>mssql</dc:subject>
<dc:subject>pdo</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>uniqueidentifier</dc:subject>

    </entry>
    <entry>
        <link href="http://blog.dynom.nl/archives/Connecting-from-PHP-on-a-non-Microsoft-OS-to-MSSQL-with-a-domain-account_20100604_56.html" rel="alternate" title="Connecting from PHP on a non Microsoft OS to MSSQL with a domain account" />
        <author>
            <name>Mark van der Velden</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2010-06-04T05:24:00Z</published>
        <updated>2010-06-05T19:18:13Z</updated>
        <wfw:comment>http://blog.dynom.nl/wfwcomment.php?cid=56</wfw:comment>
    
        <slash:comments>3</slash:comments>
        <wfw:commentRss>http://blog.dynom.nl/rss.php?version=atom1.0&amp;type=comments&amp;cid=56</wfw:commentRss>
    
            <category scheme="http://blog.dynom.nl/categories/PHP_1" label="PHP" term="PHP" />
            <category scheme="http://blog.dynom.nl/categories/PlanetPHP_8" label="PlanetPHP" term="PlanetPHP" />
    
        <id>http://blog.dynom.nl/archives/guid_20100604_56.html</id>
        <title type="html">Connecting from PHP on a non Microsoft OS to MSSQL with a domain account</title>
        <content type="xhtml" xml:base="http://blog.dynom.nl/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <div>I was asked to create a web interface front-end with Microsoft Dynamics CRM as back-end. But I had some troubles setting up the connection, since it has to be done using a domain logon. This doesn't have to be a problem at all, unless your configuration is wrong! In this article I'll explain a few things and point you in the right direction when you have login problems.</div><div><br /></div><div>As stated earlier, the server running the PHP installation is not Microsoft. In this case a AS400 installation, but it could've been a Linux installation also. I'm using PDO for this article and PHP version 5.2.11. Even if you don't want to use PDO, I recommend using it only for debugging (if possible) since that will give you *most likely* more debug information then the mssql_* family. </div><div><br /></div><div>When using PDO with a MS-SQL database, you'll need to supply "dblib" as driver and DBLib uses FreeTDS as underlaying library. FreeTDS can be a source of troubles when you're trying to connect, if not configured properly. So I'll kick-off with a little information about it. Don't skip it if you have login problems!</div> <br /><a href="http://blog.dynom.nl/archives/Connecting-from-PHP-on-a-non-Microsoft-OS-to-MSSQL-with-a-domain-account_20100604_56.html#extended">Continue reading "Connecting from PHP on a non Microsoft OS to MSSQL with a domain account"</a>
            </div>
        </content>
        <dc:subject>active directory</dc:subject>
<dc:subject>freetds</dc:subject>
<dc:subject>mssql</dc:subject>
<dc:subject>pdo</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>planetphp</dc:subject>
<dc:subject>sspi</dc:subject>

    </entry>
    <entry>
        <link href="http://blog.dynom.nl/archives/PHPUnit-conditional-test-based-on-a-PHP-version_20100419_55.html" rel="alternate" title="PHPUnit conditional test based on a PHP version" />
        <author>
            <name>Mark van der Velden</name>
            <email>nospam@example.com</email>
        </author>
    
        <published>2010-04-19T14:47:00Z</published>
        <updated>2010-04-20T02:04:59Z</updated>
        <wfw:comment>http://blog.dynom.nl/wfwcomment.php?cid=55</wfw:comment>
    
        <slash:comments>2</slash:comments>
        <wfw:commentRss>http://blog.dynom.nl/rss.php?version=atom1.0&amp;type=comments&amp;cid=55</wfw:commentRss>
    
            <category scheme="http://blog.dynom.nl/categories/PHP_1" label="PHP" term="PHP" />
            <category scheme="http://blog.dynom.nl/categories/PlanetPHP_8" label="PlanetPHP" term="PlanetPHP" />
    
        <id>http://blog.dynom.nl/archives/guid_20100419_55.html</id>
        <title type="html">PHPUnit conditional test based on a PHP version</title>
        <content type="xhtml" xml:base="http://blog.dynom.nl/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>I had a problem with running test cases on multiple CI environments, where one of the two runs on PHP 5.2 and the other on PHP 5.3. This basically meant that all our pretty PHP 5.3 code caused the builds to fail on the 5.2 only machine. To solve this problem I needed a way to skip tests when the PHP version was less then 5.3.0. Besides the reason I needed this for a -less then ideal- setup. This can also be a generic way to skip certain tests, based on a PHP version. </p><p><div class="php" style="text-align: left"><span style="color: #000000; font-weight: bold;">class</span> someTest <span style="color: #000000; font-weight: bold;">extends</span> PHPUnit_Framework_TestCase<br /><span style="color: #66cc66;">&#123;</span><br />&#160; &#160; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setUp<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />&#160; &#160; <span style="color: #66cc66;">&#123;</span><br />&#160; &#160; &#160; &#160; <span style="color: #808080; font-style: italic;">// Testing if we are dealing with version 5.3.0 or higher</span><br />&#160; &#160; &#160; &#160; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<a onclick="javascript: pageTracker._trackPageview('/extlink/www.php.net/version_compare');"  href="http://www.php.net/version_compare"><span style="color: #000066;">version_compare</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">PHP_VERSION</span>, <span style="color: #ff0000;">'5.3.0'</span>, <span style="color: #ff0000;">'&gt;='</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />&#160; &#160; &#160; &#160; &#160; &#160; <span style="color: #ff0000">$this</span>-&gt;markTestSkipped<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Invalid PHP version, unable to run tests.'</span><span style="color: #66cc66;">&#41;</span>;<br />&#160; &#160; &#160; &#160; <span style="color: #66cc66;">&#125;</span><br />&#160; &#160; <span style="color: #66cc66;">&#125;</span><br /><br />&#160; &#160; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> test_testFoo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />&#160; &#160; <span style="color: #66cc66;">&#123;</span><br />&#160; &#160; &#160; <span style="color: #808080; font-style: italic;">// .. some awesum test case .. \\</span><br />&#160; &#160; <span style="color: #66cc66;">&#125;</span><br /><span style="color: #66cc66;">&#125;</span><br />&#160;</div></p><p>You can also use the cool <a onclick="javascript: pageTracker._trackPageview('/extlink/www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.examples.StackTest2.php');"  href="http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.examples.StackTest2.php" title="@annotation example" mce_href="http://www.phpunit.de/manual/3.4/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.examples.StackTest2.php">@depends</a> annotation of <a onclick="javascript: pageTracker._trackPageview('/extlink/www.phpunit.de');"  href="http://www.phpunit.de" title="PHPUnit website" mce_href="http://www.phpunit.de">PHPUnit</a> and put the version logic in a test. This has my preference, but it's not always possible. In case you have some code that simply can't be parsed by the older PHP engines.</p><p>If you know a better way to do this, please share! <br /></p> 
            </div>
        </content>
        
    </entry>

</feed>