<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Agence de Développement Informatique du Nord &#187; MySQL</title>
	<atom:link href="http://blog.adin.pro/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adin.pro</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 26 Dec 2019 08:54:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</title>
		<link>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/</link>
		<comments>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/#comments</comments>
		<pubDate>Wed, 30 Apr 2014 07:42:04 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=381</guid>
		<description><![CDATA[<p>You can easily filter column in a magento grid (see my previous post) but customize a sort is a little bit more hand made. In this example in the order grid, I want to sort by increment_id, but this is &#8230; <a href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You can easily filter column in a magento grid (see my previous post) but customize a sort is a little bit more hand made.</p>
<p>In this example in the order grid, I want to sort by increment_id, but this is a text fields and I want to sort it by numeric.</p>
<p>default sort : 1, 10, 100, 2, 3 &#8230;<br />
numeric sort : 1, 2, 3, 10, 100 &#8230;</p>
<p>If you look the SQL request, you got this</p>
<pre class="brush: php; title: ; notranslate">
SELECT `main_table`.* FROM `sales_flat_order_grid` AS `main_table` ORDER BY increment_id DESC LIMIT 20
</pre>
<p>To tell MySQL to sort this text column by numeric, you can add &#8220;+ 0&#8243; to the ORDER BY clause, this will transform the text field into numeric field</p>
<pre class="brush: php; title: ; notranslate">
SELECT `main_table`.* FROM `sales_flat_order_grid` AS `main_table` ORDER BY increment_id + 0 DESC LIMIT 20
</pre>
<p>Now, how to tell Magento to add &#8220;+ 0&#8243; to this sort ?</p>
<p>Override your grid class and modify the &#8220;_setCollectionOrder($column)&#8221; function.</p>
<pre class="brush: php; title: ; notranslate">
class Adin_Sales_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {
    protected function _setCollectionOrder($column)
    {
        $collection = $this-&gt;getCollection();
        if ($collection) {
            $columnIndex = $column-&gt;getFilterIndex() ? $column-&gt;getFilterIndex() : $column-&gt;getIndex();
            if($columnIndex == 'increment_id')
            {
                $columnIndex = 'increment_id + 0';
            }
            $collection-&gt;setOrder($columnIndex, strtoupper($column-&gt;getDir()));
        }
        return $this;
    }
}
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/">Magento custom sort on grid &#8211; sort increment_id by numeric not alpha</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-04-30/magento-custom-sort-on-grid-sort-increment_id-by-numeric-not-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>doctrine2 random</title>
		<link>http://blog.adin.pro/2014-03-06/doctrine2-random/</link>
		<comments>http://blog.adin.pro/2014-03-06/doctrine2-random/#comments</comments>
		<pubDate>Thu, 06 Mar 2014 20:21:46 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine2]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rand]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[Symfony2]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=367</guid>
		<description><![CDATA[<p>For some really good reasons or, doctrine2 do not implement the RAND() fonction to sort randomly your query results. Here some dirty ways to do it. Don&#8217;t use them it&#8217;s bad. One solution is to shuffle your collection of rows &#8230; <a href="http://blog.adin.pro/2014-03-06/doctrine2-random/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-03-06/doctrine2-random/">doctrine2 random</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>For some really good reasons or, doctrine2 do not implement the RAND() fonction to sort randomly your query results. Here some dirty ways to do it. Don&#8217;t use them it&#8217;s bad.</p>
<p>One solution is to shuffle your collection of rows using php</p>
<pre class="brush: php; title: ; notranslate">
      public function getRandom($max = 10,$site) {
        $results = $this-&gt;createQueryBuilder('u')
                -&gt;where('u.site = :site')
                -&gt;setParameter('site', $site)
                -&gt;orderBy('u.sort', 'DESC')
                -&gt;setMaxResults($max)
                -&gt;getQuery()
                -&gt;getResult();
        shuffle($results);
        return $results;
    }
</pre>
<p>In this solution, you retrieve the last 10 rows and shuffle them after. Peformances are not too bad but you will always retrieves the same last rows from your table.</p>
<p>Another solution is to use the array_rand php fonction</p>
<pre class="brush: php; title: ; notranslate">
      public function getRandom($site) {
        $results = $this-&gt;createQueryBuilder('u')
                -&gt;where('u.site = :site')
                -&gt;setParameter('site', $site)
                -&gt;orderBy('u.sort', 'DESC')
                -&gt;getQuery()
                -&gt;getResult();
        $result2 = array_rand($results);
        return $result2;
    }
</pre>
<p>In this case you fetch all rows from your table, this could be slow and memory consuming&#8230;</p>
<p>If you need to retrieve only one row, you can use somethinfg like this</p>
<pre class="brush: php; title: ; notranslate">
 public function getOneRandom()
{
$em = $this-&gt;getEntityManager();
$max = $em-&gt;createQuery('
SELECT MAX(q.id) FROM questions q
')
-&gt;getSingleScalarResult();
return $em-&gt;createQuery('
SELECT q FROM questions q
WHERE q.id &gt;= :random
ORDER BY q.id ASC
')
-&gt;setParameter('random',rand(0,$max))
-&gt;setMaxResults(1)
-&gt;getSingleResult();
}
</pre>
<p>This solution can only be used if you want to retrieve any of the tables rows, if you add a filtrer you may return an empty result.</p>
<p>This solution is not dirty it just use 2 queries instead of one. the tips is to use the offset. And you can use a filter !!!</p>
<pre class="brush: php; title: ; notranslate">
$qCount = Doctrine::getTable('Questions')
     -&gt;createQuery()
     -&gt;select('count(*)')
     -&gt;where('site = :site')
     -&gt;setParameter('site', $site)
     -&gt;fetchOne(array(), Doctrine::HYDRATE_NONE);
$question = Doctrine::getTable('Questions')
     -&gt;createQuery()
     -&gt;select('*')
     -&gt;where('site = :site')
     -&gt;setParameter('site', $site)
     -&gt;limit(1)
     -&gt;offset(rand(0, $qCount[0] - 1))
     -&gt;fetchOne();
</pre>
<p>And you still can use native queries : http://docs.doctrine-project.org/en/latest/reference/native-sql.html</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-03-06/doctrine2-random/">doctrine2 random</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-03-06/doctrine2-random/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL custom sort</title>
		<link>http://blog.adin.pro/2013-06-13/mysql-custom-sort/</link>
		<comments>http://blog.adin.pro/2013-06-13/mysql-custom-sort/#comments</comments>
		<pubDate>Thu, 13 Jun 2013 08:51:14 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=232</guid>
		<description><![CDATA[<p>You are requesting some product on your database and you need to sort results by fixed column values ? You can use the ORDER BY FIELD() clause.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-06-13/mysql-custom-sort/">MySQL custom sort</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You are requesting some product on your database and you need to sort results by fixed column values ?<br />
You can use the ORDER BY FIELD() clause.</p>
<pre class="brush: php; title: ; notranslate">
SELECT * FROM product WHERE product_id IN (4, 2, 8, 9, 5) ORDER BY FIELD(product_id,4, 2, 8, 9, 5)
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-06-13/mysql-custom-sort/">MySQL custom sort</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-06-13/mysql-custom-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql INSERT &#8230; ON DUPLICATE KEY UPDATE</title>
		<link>http://blog.adin.pro/2013-03-27/mysql-insert-on-duplicate-key-update/</link>
		<comments>http://blog.adin.pro/2013-03-27/mysql-insert-on-duplicate-key-update/#comments</comments>
		<pubDate>Wed, 27 Mar 2013 22:37:01 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=160</guid>
		<description><![CDATA[<p>If you want to do some data loads in a Mysql DB regardless of insert or update statement you can use the INSERT &#8230; ON DUPLICATE KEY UPDATE request. In this example, if the key is composed by firstname and &#8230; <a href="http://blog.adin.pro/2013-03-27/mysql-insert-on-duplicate-key-update/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-03-27/mysql-insert-on-duplicate-key-update/">Mysql INSERT &#8230; ON DUPLICATE KEY UPDATE</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>If you want to do some data loads in a Mysql DB regardless of insert or update statement you can use the INSERT &#8230; ON DUPLICATE KEY UPDATE request.</p>
<pre class="brush: php; title: ; notranslate">
INSERT INTO test (firstname, lastname, skill)
      VALUES
      ('Alan', 'Cox', 98),
      ('Robert', 'Love', 85),
      ('Linus', 'Torvalds', 24),
      ('Rusty', 'Russell', 79)
ON DUPLICATE KEY UPDATE
     skill = VALUES(skill);
</pre>
<p>In this example, if the key is composed by firstname and lastname, when a duplicate key is detected, only the skill will be updated</p>
<p>You could find more informations on this statement <a title="Insert on duplicate key update" href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html" target="_blank">here</a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-03-27/mysql-insert-on-duplicate-key-update/">Mysql INSERT &#8230; ON DUPLICATE KEY UPDATE</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-03-27/mysql-insert-on-duplicate-key-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpMyAdmin change timeout &amp; other customizations</title>
		<link>http://blog.adin.pro/2013-03-06/phpmyadmin-change-timeout-other-customizations/</link>
		<comments>http://blog.adin.pro/2013-03-06/phpmyadmin-change-timeout-other-customizations/#comments</comments>
		<pubDate>Wed, 06 Mar 2013 09:45:45 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=123</guid>
		<description><![CDATA[<p>Tired to login again and again on your phpMyAdmin interface ? You can change the default timeout in your config.inc.php file. Add or edit this variable The config.inc.php file is in your /etc/phpmyadmin/ folder on debian. Some other options:</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-03-06/phpmyadmin-change-timeout-other-customizations/">phpMyAdmin change timeout &#038; other customizations</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Tired to login again and again on your phpMyAdmin interface ?<br />
You can change the default timeout in your config.inc.php file.</p>
<p>Add or edit this variable</p>
<pre class="brush: php; title: ; notranslate">
$cfg['LoginCookieValidity'] = 36000; //In seconds 
</pre>
<p>The config.inc.php file is in your /etc/phpmyadmin/ folder on debian.</p>
<p>Some other options:</p>
<pre class="brush: php; title: ; notranslate">
$cfg['MaxRows'] = 100; //change the number of line displayed by default
$cfg['AjaxEnable'] = false;  //enable or disable ajax 
$cfg['NavigationBarIconic'] = true;   //enable or diasable navigation icons
$cfg['PropertiesIconic'] = true;      //enable or disable properties icons
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-03-06/phpmyadmin-change-timeout-other-customizations/">phpMyAdmin change timeout &#038; other customizations</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-03-06/phpmyadmin-change-timeout-other-customizations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Save MySQL query results into a file</title>
		<link>http://blog.adin.pro/2013-02-06/save-mysql-query-results-into-a-file/</link>
		<comments>http://blog.adin.pro/2013-02-06/save-mysql-query-results-into-a-file/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 09:34:24 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=94</guid>
		<description><![CDATA[<p>Sometimes, phpMyAdmin doesn&#8217;t export queries properly. To get your file, you can add options to you query to save the result into a file.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-02-06/save-mysql-query-results-into-a-file/">Save MySQL query results into a file</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Sometimes, phpMyAdmin doesn&#8217;t export queries properly. To get your file, you can add options to you query to save the result into a file.</p>
<pre class="brush: bash; title: ; notranslate">
SELECT cotisation.date_creation
FROM cotisation
WHERE cotisation.code_suppression =0
INTO OUTFILE '/home/transfert/cotisations_201212.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY &quot;'&quot;
LINES TERMINATED BY '\n'
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-02-06/save-mysql-query-results-into-a-file/">Save MySQL query results into a file</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-02-06/save-mysql-query-results-into-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
