<?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>SIMOTRONE WEB PAGE</title>
	<atom:link href="http://www.simotrone.it/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simotrone.it</link>
	<description>Simotrone is back!</description>
	<lastBuildDate>Wed, 10 Mar 2010 06:22:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ssh forwarding</title>
		<link>http://www.simotrone.it/2010/03/10/ssh-forwarding/</link>
		<comments>http://www.simotrone.it/2010/03/10/ssh-forwarding/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 06:22:46 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Binary People]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssh forwarding]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2727</guid>
		<description><![CDATA[Forse non tutti sanno che&#8230; ssh permette il forwarding.

$ man ssh
&#160; &#160; &#160;-L &#91;bind_address:&#93;port:host:hostport
&#160; &#160; &#160;Specifies that the given port on the local &#40;client&#41; host 
&#160; &#160; &#160;is to be forwarded to the given host and port on the 
&#160; &#160; &#160;remote side. &#160;This works by allocating a socket to listen 
&#160; &#160; &#160;to port [...]]]></description>
			<content:encoded><![CDATA[<p>Forse non tutti sanno che&#8230; <strong>ssh</strong> permette il <em>forwarding</em>.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">$ <span class="kw2">man</span> <span class="kw2">ssh</span><br />
&nbsp; &nbsp; &nbsp;-L <span class="br0">&#91;</span>bind_address:<span class="br0">&#93;</span>port:host:hostport<br />
&nbsp; &nbsp; &nbsp;Specifies that the given port on the <span class="kw3">local</span> <span class="br0">&#40;</span>client<span class="br0">&#41;</span> host <br />
&nbsp; &nbsp; &nbsp;is to be forwarded to the given host and port on the <br />
&nbsp; &nbsp; &nbsp;remote side. &nbsp;This works by allocating a socket to listen <br />
&nbsp; &nbsp; &nbsp;to port on the <span class="kw3">local</span> side, optionally bound to the <br />
&nbsp; &nbsp; &nbsp;specified bind_address. &nbsp;Whenever a connection is <br />
&nbsp; &nbsp; &nbsp;made to this port, the connection is forwarded over the <br />
&nbsp; &nbsp; &nbsp;secure channel, and a connection is made to host port <br />
&nbsp; &nbsp; &nbsp;hostport from the remote machine. &nbsp;Port forwardings <br />
&nbsp; &nbsp; &nbsp;can also be specified <span class="kw1">in</span> the configuration <span class="kw2">file</span>. <span class="br0">&#91;</span>&#8230;<span class="br0">&#93;</span> Only <br />
&nbsp; &nbsp; &nbsp;the superuser can forward privileged ports. &nbsp;By default, <br />
&nbsp; &nbsp; &nbsp;the <span class="kw3">local</span> port is bound <span class="kw1">in</span> accordance with the <br />
&nbsp; &nbsp; &nbsp;GatewayPorts setting. &nbsp;However, an explicit <br />
&nbsp; &nbsp; &nbsp;bind_address may be used to <span class="kw3">bind</span> the connection to <br />
&nbsp; &nbsp; &nbsp;a specific address. &nbsp;The bind_address of “localhost” <br />
&nbsp; &nbsp; &nbsp;indicates that the listening port be bound <span class="kw1">for</span> <span class="kw3">local</span> use <br />
&nbsp; &nbsp; &nbsp;only, <span class="kw1">while</span> an empty address or ‘*’ indicates that the <br />
&nbsp; &nbsp; &nbsp;port should be available from all interfaces.</div>
</div>
<p>Nel caso vi servisse ridirigere l&#8217;input in una porta locale verso un qualcosa di remoto, il gioco è fatto:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">$ <span class="kw2">ssh</span> -v -L <span class="nu0">9999</span>:<span class="nu0">209.85</span><span class="nu0">.135</span><span class="nu0">.105</span>:<span class="nu0">80</span> <span class="nu0">127.0</span><span class="nu0">.0</span><span class="nu0">.1</span></div>
</div>
<p>Questa riga permette di collegare la porta 9999 locale con la porta 80 dell&#8217;ip 209.85.135.105 &#8211; google (è necessario l&#8217;inserimento della password dell&#8217;utente@127.0.0.1)!</p>
<p>Se per caso doveste ridirigere il traffico da un server ad un altro o voleste un tunnel criptato per accedere a certi servizi (qualcuno ha detto mail?), potrebbe essere utile.</p>
<p>Altre info <a href="http://www.securityfocus.com/infocus/1816">qua</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/03/10/ssh-forwarding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firewall in cron</title>
		<link>http://www.simotrone.it/2010/03/04/firewall-in-cron/</link>
		<comments>http://www.simotrone.it/2010/03/04/firewall-in-cron/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 06:02:46 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Binary People]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2725</guid>
		<description><![CDATA[Ok, capita anche ai migliori.
A me però sta particolarmente sulle balle.
Così, visto che mi è già capitato due volte di chiudermi fuori da una box remota pistolando sul firewall a caso &#8211; ed è decisamente umilante rompere le balle al prossimo per il riavvio in loco del server &#8211; ho ben deciso di scrivere un [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, capita anche ai migliori.</p>
<p>A me però sta particolarmente sulle balle.<br />
Così, visto che mi è già capitato due volte di chiudermi fuori da una box remota <em>pistolando</em> sul firewall a caso &#8211; ed è decisamente umilante rompere le balle al prossimo per il riavvio in loco del server &#8211; ho ben deciso di scrivere un semplice scriptino in bas in cron.daily, che rilancia periodicamente il file con la configurazione del firewall &#8220;standard&#8221;.</p>
<p>Che odio.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/03/04/firewall-in-cron/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL e timestamp, la vendetta</title>
		<link>http://www.simotrone.it/2010/03/02/mysql-e-timestamp-la-vendetta/</link>
		<comments>http://www.simotrone.it/2010/03/02/mysql-e-timestamp-la-vendetta/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 06:25:24 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Binary People]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2691</guid>
		<description><![CDATA[Dopo gli accidenti tirati precedentemente, ho scoperto che dare un comando CHANGE su una colonna dichiarandola come TIMESTAMP ha il seguente effetto: il default diventa CURRENT_TIMESTAMP e l&#8217;extra è ON UPDATE CURRENT_TIMESTAMP.
Avevo letto che CHANGE e MODIFY cancellavano gli attributi (l&#8217;Extra) delle colonne cui cambiavano il tipo, e così mi sono messo ad assegnare TIMESTAMP [...]]]></description>
			<content:encoded><![CDATA[<p>Dopo gli accidenti tirati precedentemente, ho scoperto che dare un comando CHANGE su una colonna dichiarandola come TIMESTAMP ha il seguente effetto: il default diventa CURRENT_TIMESTAMP e l&#8217;extra è ON UPDATE CURRENT_TIMESTAMP.</p>
<p>Avevo letto che CHANGE e MODIFY cancellavano gli attributi (<em>l&#8217;Extra</em>) delle colonne cui cambiavano il tipo, e così mi sono messo ad assegnare TIMESTAMP e DATETIME ai due campi created/updated in modo da togliermi i dubbi.<br />
(dal man: &#8220;<em>When you use CHANGE or MODIFY, column_definition must include the data type and all attributes that should apply to the new column, other than index attributes such as PRIMARY KEY or UNIQUE. Attributes present in the original definition but not specified for the new definition are not carried forward.</em>&#8220;)</p>
<pre>sim:test> ALTER TABLE A CHANGE created created DATETIME;
sim:test> ALTER TABLE A CHANGE updated updated TIMESTAMP;
[...]
| created | datetime    | YES  | | NULL              |                             |
| updated | timestamp   | NO   | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |</pre>
<p>Alla fine mi sono un po&#8217; capito leggendo <a href="http://dev.mysql.com/doc/refman/5.1/en/timestamp.html">qua</a>.<br />
I dati di tipo <strong>timestamp</strong> dovrebbero essere dei <strong>datetime</strong> (e lo sono come formato), ma a differenza di questi ultimi si aggiornano con l&#8217;ora attuale.</p>
<p><em>The TIMESTAMP data type offers automatic initialization and updating.</em></p>
<p>Dopo aver reso la colonna updated CURRENT_TIMESTAMP con aggiornamento sull&#8217;UPDATE dei dati, ho potuto fare:</p>
<pre>ALTER TABLE A MODIFY created TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00';</pre>
<p>e inserire un paio di dati:</p>
<pre>sim:test> INSERT INTO A (word) VALUES ('gastone');
sim:test> INSERT INTO A (word,created) VALUES ('paperino',NULL);</pre>
<p>col risultato:</p>
<pre>|  5 | gastone  | 0000-00-00 00:00:00 | 2010-02-11 23:42:03 |
|  6 | paperino | 2010-02-11 23:42:23 | 2010-02-11 23:42:23 |</pre>
<p>Sul man c&#8217;è scritto pure questo, ma a me continua a sembrare un comportamento strano.<br />
<em>TIMESTAMP columns are NOT NULL by default, cannot contain NULL values, and assigning NULL assigns the current timestamp.</em></p>
<p>In conclusione, se volete avere dei campi con la creazione e l&#8217;aggiornamento automatico delle date incluso, leggetevi la <a href="http://dev.mysql.com/doc/refman/5.1/en/timestamp.html">pagina di Mysql sui timestamp</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/03/02/mysql-e-timestamp-la-vendetta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>E pure la Futa</title>
		<link>http://www.simotrone.it/2010/02/27/e-pure-la-futa/</link>
		<comments>http://www.simotrone.it/2010/02/27/e-pure-la-futa/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 12:29:54 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Pistons and Wings]]></category>
		<category><![CDATA[drosera]]></category>
		<category><![CDATA[Futa]]></category>
		<category><![CDATA[passo raticosa]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2722</guid>
		<description><![CDATA[E col sole di oggi, macinati altri 100 km abbondanti.  


]]></description>
			<content:encoded><![CDATA[<p>E col sole di oggi, macinati altri 100 km abbondanti. <img src='http://www.simotrone.it/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="/wp-content/drosera/raticosa2_100227.jpg"><img class="cornice" src="/wp-content/drosera/raticosa2_100227.th.jpg" alt="Drosera al Passo." /></a></p>
<p><a href="/wp-content/drosera/raticosa1_100227.jpg"><img class="cornice" src="/wp-content/drosera/raticosa1_100227.th.jpg" alt="Passo Raticosa" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/02/27/e-pure-la-futa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Primo giro 2010</title>
		<link>http://www.simotrone.it/2010/02/26/primo-giro-2010/</link>
		<comments>http://www.simotrone.it/2010/02/26/primo-giro-2010/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 20:09:19 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Pistons and Wings]]></category>
		<category><![CDATA[castelletto]]></category>
		<category><![CDATA[drosera]]></category>
		<category><![CDATA[monteveglio]]></category>
		<category><![CDATA[moto]]></category>
		<category><![CDATA[primo giro 2010]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2714</guid>
		<description><![CDATA[Finalmente ho fatto il mio primo giro del nuovo anno con la mia amata drosera.
81 chilometri da Bologna passando per Calderino, Badia , Savigno, l&#8217;abbazia di Monteveglio, Stiore, Monte San Pietro e ritorno.
Peccato gli ultimi 20 chilometri abbia piovuto, ma ai fini del giro è stato irrilevante.
Troppo bello.
Un paio di scatti col cellulare. Fanno veramente [...]]]></description>
			<content:encoded><![CDATA[<p>Finalmente ho fatto il mio primo giro del nuovo anno con la mia amata drosera.<br />
81 chilometri da Bologna passando per Calderino, Badia , Savigno, l&#8217;abbazia di Monteveglio, Stiore, Monte San Pietro e ritorno.<br />
Peccato gli ultimi 20 chilometri abbia piovuto, ma ai fini del giro è stato irrilevante.<br />
Troppo bello.</p>
<p>Un paio di scatti col cellulare. Fanno veramente schifo come taglio, ma almeno non sono venuti pessimi.</p>
<p>A Savigno.</p>
<p><a href="/wp-content/drosera/castelletto_20100226.jpg"><img class="cornice" src="/wp-content/drosera/castelletto_20100226.th.jpg" alt="Castelletto" /></a></p>
<p>Sotto l&#8217;abbazia di Monteveglio:</p>
<p><a href="/wp-content/drosera/monteveglio_20100226.jpg"><img class="cornice"  src="/wp-content/drosera/monteveglio_20100226.th.jpg" alt="Monteveglio" /></a></p>
<p>Il tragitto. <img src='http://www.simotrone.it/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><iframe width="500" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.it/maps?f=d&amp;source=s_d&amp;saddr=Via+Lodovico+Varthema,+40137+Bologna&amp;daddr=Via+Emilia+Ponente+to:Via+Nuova+Bazzanese%2FSP569+to:Via+Nuova+Bazzanese%2FSP569+to:Via+Lavino%2FSP26+to:Monte+san+giovanni+to:Badia+to:Via+dei+Mulini+to:Via+della+Pace+to:Via+San+Rocco,+15,+40050+Monteveglio,+Bologne+(Emilia+Romagna)+(Abbazia+S.Maria+Assunta+-+Fratelli+Di+S.Francesco)+to:Stiore+to:Monte+san+pietro+to:Rivabella&amp;hl=en&amp;geocode=FS6npgIdaGetACnzqgY8LCt-RzH7BBNJtfvKhQ%3BFX4ZpwIdJJOsAA%3BFYTbpgIdSWurAA%3BFYfbpgIdMmurAA%3BFXpgpgId1uWqAA%3BFcqwpQIdg16qACmvJ2Y_edIqEzHzwW3CutpyMA%3BFeydpQIdjM2pACntf6elus0qEzExEZgVDZsHJg%3BFSFTpQId2e6oAA%3BFSBRpQIdQvaoAA%3BFeGLpgIdAUCpACHaLCD5uFqyzClLNUimpNh_RzEndpbT0QnJwg%3BFS2epgId3qCpACm9I-4bi9h_RzGRjpcVDZsHJg%3BFdoRpgIdc9qpACkJYolzFc0qEzH3rNJf6Jir4Q%3B&amp;mra=ls&amp;via=2,3,7&amp;sll=44.462701,11.242104&amp;sspn=0.185489,0.317574&amp;ie=UTF8&amp;ll=44.461231,11.2397&amp;spn=0.11702,0.29305&amp;t=h&amp;output=embed"></iframe><br /><small><a href="http://maps.google.it/maps?f=d&amp;source=embed&amp;saddr=Via+Lodovico+Varthema,+40137+Bologna&amp;daddr=Via+Emilia+Ponente+to:Via+Nuova+Bazzanese%2FSP569+to:Via+Nuova+Bazzanese%2FSP569+to:Via+Lavino%2FSP26+to:Monte+san+giovanni+to:Badia+to:Via+dei+Mulini+to:Via+della+Pace+to:Via+San+Rocco,+15,+40050+Monteveglio,+Bologne+(Emilia+Romagna)+(Abbazia+S.Maria+Assunta+-+Fratelli+Di+S.Francesco)+to:Stiore+to:Monte+san+pietro+to:Rivabella&amp;hl=en&amp;geocode=FS6npgIdaGetACnzqgY8LCt-RzH7BBNJtfvKhQ%3BFX4ZpwIdJJOsAA%3BFYTbpgIdSWurAA%3BFYfbpgIdMmurAA%3BFXpgpgId1uWqAA%3BFcqwpQIdg16qACmvJ2Y_edIqEzHzwW3CutpyMA%3BFeydpQIdjM2pACntf6elus0qEzExEZgVDZsHJg%3BFSFTpQId2e6oAA%3BFSBRpQIdQvaoAA%3BFeGLpgIdAUCpACHaLCD5uFqyzClLNUimpNh_RzEndpbT0QnJwg%3BFS2epgId3qCpACm9I-4bi9h_RzGRjpcVDZsHJg%3BFdoRpgIdc9qpACkJYolzFc0qEzH3rNJf6Jir4Q%3B&amp;mra=ls&amp;via=2,3,7&amp;sll=44.462701,11.242104&amp;sspn=0.185489,0.317574&amp;ie=UTF8&amp;ll=44.461231,11.2397&amp;spn=0.11702,0.29305&amp;t=h" style="color:#0000FF;text-align:left">View Larger Map</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/02/26/primo-giro-2010/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Recuperare stringhe in un file</title>
		<link>http://www.simotrone.it/2010/02/25/recuperare-stringhe-in-un-file/</link>
		<comments>http://www.simotrone.it/2010/02/25/recuperare-stringhe-in-un-file/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 17:46:04 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Binary People]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2712</guid>
		<description><![CDATA[Oggi nel canale perl ci si è chiesto come individuare stringhe arbitrarie ricorrenti in un file (ie: query SQL in un file php).
La risposta di per se sarebbe semplice: si fa una regex che inizia con SELECT e finisce con qualcosa (ie:   e si è a cavallo.
Il grado di difficoltà però aumenta se [...]]]></description>
			<content:encoded><![CDATA[<p>Oggi nel canale perl ci si è chiesto come individuare stringhe arbitrarie ricorrenti in un file (ie: query SQL in un file php).<br />
La risposta di per se sarebbe semplice: si fa una regex che inizia con SELECT e finisce con qualcosa (ie: <img src='http://www.simotrone.it/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  e si è a cavallo.<br />
Il grado di difficoltà però aumenta se le stringhe sono su più righe&#8230;</p>
<p>Avendo trovato una soluzione che non richiede nemmeno un ciclo, la scrivo poichè ne sono orgoglioso e mi è valsa un <strong>++</strong>. <img src='http://www.simotrone.it/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">#!/usr/bin/perl -w</span><br />
<span class="kw2">use</span> strict;<br />
<span class="kw2">use</span> File::<span class="me2">Slurp</span>;<br />
<span class="kw1">my</span> <span class="re0">$text</span> = read_file<span class="br0">&#40;</span><span class="st0">&#8216;file.php&#8217;</span><span class="br0">&#41;</span>;<br />
<span class="kw1">my</span> <span class="re0">@queries</span> = <span class="re0">$text</span> =~ /<span class="br0">&#40;</span><span class="st0">&quot;SELECT.*?&quot;</span><span class="br0">&#41;</span>;/msg</div>
</div>
<p>Ogni valore di @queries conterrà uno dei SELECT nel file, siano essi su più righe o meno.</p>
<p>Più breve di così&#8230;</p>
<p>Segnalo anche un paio di letture sulle regex che potrebbero venire comode per capire i modificatori /m e /s, che si usano pochino.<br />
Regexp Power by Simon Cozens (<a href="http://www.perl.com/pub/a/2003/06/06/regexps.html">1</a> e <a href="http://www.perl.com/pub/a/2003/07/01/regexps.html">2</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/02/25/recuperare-stringhe-in-un-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acronimo</title>
		<link>http://www.simotrone.it/2010/02/24/acronimo/</link>
		<comments>http://www.simotrone.it/2010/02/24/acronimo/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 06:19:52 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Knowledge is that which, next to virtue, truly raises one person above another.]]></category>
		<category><![CDATA[acronimo]]></category>
		<category><![CDATA[etimologia]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2710</guid>
		<description><![CDATA[acronimo: dal greco akron (estremo) + onoma (nome). Indica una sigla composta dalle iniziali di piùparole.
]]></description>
			<content:encoded><![CDATA[<p><strong>acronimo</strong>: dal greco <em>akron</em> (estremo) + <em>onoma</em> (nome). Indica una sigla composta dalle iniziali di piùparole.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/02/24/acronimo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL e timestamp vanno sulla luna</title>
		<link>http://www.simotrone.it/2010/02/23/mysql-e-timestamp-vanno-sulla-luna/</link>
		<comments>http://www.simotrone.it/2010/02/23/mysql-e-timestamp-vanno-sulla-luna/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 06:10:55 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Binary People]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[timestamp]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2677</guid>
		<description><![CDATA[Qua c&#8217;è da uscire di senno. A me MySQL sta pure simpatico, ma fa veramente di tutto per farmi sentire male.
Parto proprio dall&#8217;inizio.
sim:none> CREATE DATABASE test CHARACTER SET = 'UTF8';
Query OK, 1 row affected (0.00 sec)

sim:none> CONNECT test;
Connection id:    230
Current database: test
Ammettiamo che io voglia creare una tabella canonica con vari campi, [...]]]></description>
			<content:encoded><![CDATA[<p>Qua c&#8217;è da uscire di senno. A me MySQL sta pure simpatico, ma fa veramente di tutto per farmi sentire male.</p>
<p>Parto proprio dall&#8217;inizio.</p>
<pre>sim:none> CREATE DATABASE test CHARACTER SET = 'UTF8';
Query OK, 1 row affected (0.00 sec)

sim:none> CONNECT test;
Connection id:    230
Current database: test</pre>
<p>Ammettiamo che io voglia creare una tabella canonica con vari campi, fra cui l&#8217;<strong>id</strong> come PK, un campo per segnare quando il record è stato creato (<strong>created</strong>) ed uno per segnarmi quando è stato aggiornato l&#8217;ultima volta (<strong>updated</strong>).</p>
<pre>sim:test> CREATE TABLE A (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    word VARCHAR(8) NOT NULL,
    created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated TIMESTAMP NOT NULL );
Query OK, 0 rows affected (0.00 sec)</pre>
<p>La situazione della mia tabella A per ora è chiara.</p>
<pre>sim:test> SHOW CREATE TABLE A \G;
*************************** 1. row ***************************
       Table: A
Create Table: CREATE TABLE `A` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `word` varchar(8) NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
</pre>
<p>Inserisco anche un paio di record che appaiono come ci si aspetta:</p>
<pre>sim:test> INSERT INTO A (word) VALUES ('pippo'),('pluto');
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

sim:test> SELECT * FROM A;
+----+-------+---------------------+---------------------+
| id | word  | created             | updated             |
+----+-------+---------------------+---------------------+
|  1 | pippo | 2010-02-11 22:23:41 | 0000-00-00 00:00:00 |
|  2 | pluto | 2010-02-11 22:23:41 | 0000-00-00 00:00:00 |
+----+-------+---------------------+---------------------+
2 rows in set (0.00 sec)
</pre>
<p>Nel caso si decida di aggiornare un record:</p>
<pre>sim:test> UPDATE A SET word = 'topolino' WHERE id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

sim:test> SELECT * FROM A;
+----+----------+---------------------+---------------------+
| id | word     | created             | updated             |
+----+----------+---------------------+---------------------+
|  1 | pippo    | 2010-02-11 22:23:41 | 0000-00-00 00:00:00 |
|  2 | topolino | 2010-02-11 22:23:41 | 0000-00-00 00:00:00 |
+----+----------+---------------------+---------------------+
2 rows in set (0.00 sec)</pre>
<p>A questo punto decido che questa disposizione dei dati non mi va più bene, che fare? <em>Semplice</em> (* le ultime parole famose <sup>TM</sup> ), leggo <a href="http://dev.mysql.com/doc/refman/5.1/en/alter-table.html">il manuale</a> e sistemo. Seee&#8230;</p>
<p>Un po&#8217; di pazzia MySQL:</p>
<pre>sim:test> SHOW COLUMNS FROM A;
+---------+------------------+------+-----+---------------------+----------------+
| Field   | Type             | Null | Key | Default             | Extra          |
+---------+------------------+------+-----+---------------------+----------------+
| id      | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| word    | varchar(8)       | NO   |     | NULL                |                |
| created | timestamp        | NO   |     | CURRENT_TIMESTAMP   |                |
| updated | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
+---------+------------------+------+-----+---------------------+----------------+
4 rows in set (0.00 sec)

sim:test> ALTER TABLE A ALTER created DROP DEFAULT;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

sim:test> SHOW COLUMNS FROM A;
+---------+------------------+------+-----+---------------------+----------------+
| Field   | Type             | Null | Key | Default             | Extra          |
+---------+------------------+------+-----+---------------------+----------------+
| id      | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
| word    | varchar(8)       | NO   |     | NULL                |                |
| created | timestamp        | NO   |     | NULL                |                |
| updated | timestamp        | NO   |     | 0000-00-00 00:00:00 |                |
+---------+------------------+------+-----+---------------------+----------------+
4 rows in set (0.00 sec)

sim:test> ALTER TABLE A CHANGE created creat TIMESTAMP;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

sim:test> SHOW COLUMNS FROM A;
+---------+------------------+------+-----+---------------------+-----------------------------+
| Field   | Type             | Null | Key | Default             | Extra                       |
+---------+------------------+------+-----+---------------------+-----------------------------+
| id      | int(10) unsigned | NO   | PRI | NULL                | auto_increment              |
| word    | varchar(8)       | NO   |     | NULL                |                             |
| creat   | timestamp        | NO   |     | CURRENT_TIMESTAMP   | on update CURRENT_TIMESTAMP |
| updated | timestamp        | NO   |     | 0000-00-00 00:00:00 |                             |
+---------+------------------+------+-----+---------------------+-----------------------------+
4 rows in set (0.00 sec)</pre>
<p>Con un magico DROP del DEFAULT di un campo ed un cambio nome ottengo di nuovo il CURRENT_TIMESTAMP come default, e pure l&#8217;update automatico sul campo.</p>
<p>Provare per credere:</p>
<pre>sim:test> INSERT INTO A (word) VALUES ('minnie');
Query OK, 1 row affected (0.00 sec)

sim:test> SELECT * FROM A;
+----+----------+---------------------+---------------------+
| id | word     | creat               | updated             |
+----+----------+---------------------+---------------------+
|  1 | pippo    | 2010-02-11 22:23:41 | 0000-00-00 00:00:00 |
|  2 | topolino | 2010-02-11 22:23:41 | 0000-00-00 00:00:00 |
|  3 | minnie   | 2010-02-11 23:02:36 | 0000-00-00 00:00:00 |
+----+----------+---------------------+---------------------+
3 rows in set (0.00 sec)

sim:test> UPDATE A  SET word = 'clarabella' WHERE id=3;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

sim:test> SELECT * FROM A;
+----+----------+---------------------+---------------------+
| id | word     | creat               | updated             |
+----+----------+---------------------+---------------------+
|  1 | pippo    | 2010-02-11 22:23:41 | 0000-00-00 00:00:00 |
|  2 | topolino | 2010-02-11 22:23:41 | 0000-00-00 00:00:00 |
|  3 | clarabel | 2010-02-11 23:03:35 | 0000-00-00 00:00:00 |
+----+----------+---------------------+---------------------+
3 rows in set (0.00 sec)</pre>
<p>Robe da pazzi.</p>
<hr/>
<strong>Note:</strong><br />
1) MySQL aggiunge alle funzionalità dell&#8217;SQL (che vorrebbe una sola query per riga) la possibilità di comandi multipli in un solo <em>statement</em>:  ALTER TABLE t2 DROP COLUMN c, DROP COLUMN d;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/02/23/mysql-e-timestamp-vanno-sulla-luna/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vecchie VHS :-/</title>
		<link>http://www.simotrone.it/2010/02/18/2646/</link>
		<comments>http://www.simotrone.it/2010/02/18/2646/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 06:27:17 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Sweet home, Chicago]]></category>
		<category><![CDATA[pattume]]></category>
		<category><![CDATA[riordino]]></category>
		<category><![CDATA[VHS vecchie]]></category>
		<category><![CDATA[videocassette]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2646</guid>
		<description><![CDATA[Ufff. E&#8217; ora di pensionare un centinaio di VHS che non ha senso tenere lì ad occupare spazio inutilmente.
C&#8217;è roba a cui sono veramente affezionato, e che mi ha seguito per più di ventanni attraverso innumerevoli traslochi e riordini.
Excalibur, la mia prima VHS. Poi Braveheart, Star Wars, il Lago dei Cigni, il Flauto Magico, Kenshiro [...]]]></description>
			<content:encoded><![CDATA[<p>Ufff. E&#8217; ora di pensionare un centinaio di VHS che non ha senso tenere lì ad occupare spazio inutilmente.</p>
<p>C&#8217;è roba a cui sono veramente affezionato, e che mi ha seguito per più di ventanni attraverso innumerevoli traslochi e riordini.</p>
<p>Excalibur, la mia prima VHS. Poi Braveheart, Star Wars, il Lago dei Cigni, il Flauto Magico, Kenshiro il film, Macross e la collezione completa di Robotech (oltre 40 videocassette). Ghost in the Shell&#8230; un sacco di roba.<br />
E non ho ovviamente ricomprato tutti i DVD&#8230; ammesso pure che si trovi.</p>
<p>Sic sic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/02/18/2646/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Conversione rapida</title>
		<link>http://www.simotrone.it/2010/02/16/conversione-rapida/</link>
		<comments>http://www.simotrone.it/2010/02/16/conversione-rapida/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 06:56:04 +0000</pubDate>
		<dc:creator>Simotrone</dc:creator>
				<category><![CDATA[Binary People]]></category>
		<category><![CDATA[conversione]]></category>
		<category><![CDATA[Mysql]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[tabelle]]></category>

		<guid isPermaLink="false">http://www.simotrone.it/?p=2675</guid>
		<description><![CDATA[Dovevo trasferire rapidamente i dati da una singola tabella in un db MySQL a quattro distinte &#8211; in modo da normalizzare un po&#8217; i dati.
Con perl e DBI la cosa viene facile.

#!/usr/bin/perl
use strict;
use DBI;
&#91;&#8230;&#93;
my $dsn = &#34;dbi:mysql:database=$db_name&#34;;
my $dbh = DBI-&#62;connect&#40; $dsn, $username, $password &#41; or die $DBI::errstr;
my $sth = $dbh-&#62;prepare&#40;
&#160; &#160; &#8216;SELECT name, surname, birth, [...]]]></description>
			<content:encoded><![CDATA[<p>Dovevo trasferire rapidamente i dati da una singola tabella in un db MySQL a quattro distinte &#8211; in modo da <a href="http://en.wikipedia.org/wiki/Database_normalization">normalizzare</a> un po&#8217; i dati.</p>
<p>Con perl e DBI la cosa viene facile.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;"><span class="co1">#!/usr/bin/perl</span></p>
<p><span class="kw2">use</span> strict;<br />
<span class="kw2">use</span> DBI;<br />
<span class="br0">&#91;</span>&#8230;<span class="br0">&#93;</span><br />
<span class="kw1">my</span> <span class="re0">$dsn</span> = <span class="st0">&quot;dbi:mysql:database=$db_name&quot;</span>;<br />
<span class="kw1">my</span> <span class="re0">$dbh</span> = DBI-&gt;<span class="me1">connect</span><span class="br0">&#40;</span> <span class="re0">$dsn</span>, <span class="re0">$username</span>, <span class="re0">$password</span> <span class="br0">&#41;</span> <span class="kw1">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span class="kw3">die</span></a> <span class="re0">$DBI</span>::<span class="me2">errstr</span>;</p>
<p><span class="kw1">my</span> <span class="re0">$sth</span> = <span class="re0">$dbh</span>-&gt;<span class="me1">prepare</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; <span class="st0">&#8216;SELECT name, surname, birth, address, cap, city, country, phone, email, notes FROM rubrica&#8217;</span><br />
<span class="br0">&#41;</span> <span class="kw1">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span class="kw3">die</span></a> <span class="re0">$dbh</span>-&gt;<span class="me1">errstr</span>;<br />
<span class="re0">$sth</span>-&gt;<span class="me1">execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p><span class="kw1">my</span> <span class="re0">$ins0</span> = <span class="re0">$dbh</span>-&gt;<span class="me1">prepare</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; <span class="st0">&#8216;INSERT INTO persone (nome,cognome) VALUES (?,?)&#8217;</span><br />
<span class="br0">&#41;</span> <span class="kw1">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span class="kw3">die</span></a> <span class="re0">$dbh</span>-&gt;<span class="me1">errstr</span>;<br />
<span class="kw1">my</span> <span class="re0">$ins1</span> = <span class="re0">$dbh</span>-&gt;<span class="me1">prepare</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; <span class="st0">&#8216;INSERT INTO indirizzi (id,via,cap,citta,paese) VALUES (?,?,?,?,?)&#8217;</span><br />
<span class="br0">&#41;</span> <span class="kw1">or</span> <a href="http://perldoc.perl.org/functions/die.html"><span class="kw3">die</span></a> <span class="re0">$dbh</span>-&gt;<span class="me1">errstr</span>;<br />
<span class="br0">&#91;</span>&#8230; ecc, seguono altri statement insert &#8230;<span class="br0">&#93;</span></p>
<p><span class="kw1">while</span> <span class="br0">&#40;</span> <span class="kw1">my</span> <span class="re0">$row</span> = <span class="re0">$sth</span>-&gt;<span class="me1">fetchrow_hashref</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$ins0</span>-&gt;<span class="me1">execute</span><span class="br0">&#40;</span> <span class="re0">$row</span>-&gt;<span class="br0">&#123;</span>name<span class="br0">&#125;</span>, <span class="re0">$row</span>-&gt;<span class="br0">&#123;</span>surname<span class="br0">&#125;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">my</span> <span class="re0">$rv</span> = <span class="re0">$dbh</span>-&gt;<span class="me1">last_insert_id</span><span class="br0">&#40;</span><a href="http://perldoc.perl.org/functions/undef.html"><span class="kw3">undef</span></a>, <a href="http://perldoc.perl.org/functions/undef.html"><span class="kw3">undef</span></a>, <span class="st0">&#8216;persone&#8217;</span>, <span class="st0">&#8216;id&#8217;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$ins1</span>-&gt;<span class="me1">execute</span><span class="br0">&#40;</span> <span class="re0">$rv</span>, <span class="re0">$row</span>-&gt;<span class="br0">&#123;</span>address<span class="br0">&#125;</span>, <span class="re0">$row</span>-&gt;<span class="br0">&#123;</span>cap<span class="br0">&#125;</span>, <span class="re0">$row</span>-&gt;<span class="br0">&#123;</span>city<span class="br0">&#125;</span>, <span class="re0">$row</span>-&gt;<span class="br0">&#123;</span>country<span class="br0">&#125;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#91;</span>&#8230;<span class="br0">&#93;</span><br />
&nbsp;<span class="br0">&#125;</span></div>
</div>
<p>La cosa interessante sta in quel <a href="http://search.cpan.org/~timb/DBI-1.609/DBI.pm#last_insert_id">last_insert_id</a> che raccatta l&#8217;ultimo valore auto incrementato e lo mette in uno scalare, riutilizzabile poi in altri insert per avere le foreign key allineate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.simotrone.it/2010/02/16/conversione-rapida/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
