<?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>Kevin Bedell on Internet Tech &#187; programming</title>
	<atom:link href="http://www.kbedell.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kbedell.com</link>
	<description>Discussions on Ruby on Rails, the MySQL database, Social Media, Twitter, Wordpress and other tech issues</description>
	<lastBuildDate>Wed, 30 Jun 2010 20:08:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to create a TIMESTAMP/DATETIME column in MySQL to automatically be set with the current time</title>
		<link>http://www.kbedell.com/2009/03/07/how-to-create-a-timestampdatetime-column-in-mysql-to-automatically-be-set-with-the-current-time/</link>
		<comments>http://www.kbedell.com/2009/03/07/how-to-create-a-timestampdatetime-column-in-mysql-to-automatically-be-set-with-the-current-time/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 18:51:55 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.kbedell.com/?p=135</guid>
		<description><![CDATA[The TIMESTAMP data type is the only way to have MySQL automatically set the time when a row was inserted and/or updated. DATETIME columns can&#8217;t do this.
TIMESTAMP columns are identical to DATETIME columns with one important exception &#8212; they can be set to take the current time value when a row is created or updated.
You [...]]]></description>
			<content:encoded><![CDATA[<p>The TIMESTAMP data type is the only way to have MySQL automatically set the time when a row was inserted and/or updated. DATETIME columns can&#8217;t do this.</p>
<p>TIMESTAMP columns are identical to DATETIME columns with one important exception &#8212; they can be set to take the current time value when a row is created or updated.</p>
<p>You can define more than one TIMESTAMP colum in a table &#8212; however, <strong>only ONE TIMESTAMP column in a table can be configured for Auto-Update or Auto-Initialization</strong>.</p>
<p>(For that reason, I usually make a practice of setting other columns to &#8216;DATETIME&#8217; so there&#8217;s only one &#8216;TIMESTAMP&#8217; column per table.)</p>
<p>There are four options when using TIMESTAMP, they are:</p>
<ul>
<li>Auto-initialization and auto-update:</li>
</ul>
<pre>  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP</pre>
<ul>
<li>Auto-initialization only:</li>
</ul>
<pre>  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP</pre>
<ul>
<li>Auto-update only:</li>
</ul>
<pre>  ts TIMESTAMP DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP</pre>
<ul>
<li>Neither:</li>
</ul>
<pre>  ts TIMESTAMP DEFAULT 0</pre>
<p/>
Here&#8217;s an example of a complete &#8216;CREATE TABLE&#8217; statement that shows how it all works:</p>
<pre>
CREATE TABLE `foo`.`timestamp_example` (
`id`                  INTEGER(10) UNSIGNED AUTO_INCREMENT,
`some_text_field`     VARCHAR(20),
`updated_at`          TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created_at`          DATETIME DEFAULT NULL,
PRIMARY KEY (id)
);
</pre>
<p>Note that only one of the fields can be TIMESTAMP, that&#8217;s a limitation of MySQL. </p>
<p>
The choice to use the TIMESTAMP on the &#8216;updated_at&#8217; field was random in this example. Choose whatever makes sense for your application.
</p>
<p class="back_to_toc"><a href="http://www.kbedell.com/mysql-programming/">Click here to go to the table of contents for all MySQL Programming Example Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kbedell.com/2009/03/07/how-to-create-a-timestampdatetime-column-in-mysql-to-automatically-be-set-with-the-current-time/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL Integer sizes and ranges of values &#8211; How-To Create Table example</title>
		<link>http://www.kbedell.com/2009/03/07/mysql-integer-sizes-and-ranges-of-values-how-to-create/</link>
		<comments>http://www.kbedell.com/2009/03/07/mysql-integer-sizes-and-ranges-of-values-how-to-create/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 18:40:18 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.kbedell.com/?p=124</guid>
		<description><![CDATA[There are 5 different integer columns, each hold integer values of different sizes. 
Moreover, each can be signed or unsigned. If your value can&#8217;t ever be negative (for example, for an index), then you should probably make your values unsigned.

DROP TABLE `foo`.`example_03`;
CREATE TABLE IF NOT EXISTS `foo`.`example_03` (
 f_01  TINYINT,     [...]]]></description>
			<content:encoded><![CDATA[<p>There are 5 different integer columns, each hold integer values of different sizes. </p>
<p>Moreover, each can be signed or unsigned. If your value can&#8217;t ever be negative (for example, for an index), then you should probably make your values unsigned.</p>
<pre>
DROP TABLE `foo`.`example_03`;
CREATE TABLE IF NOT EXISTS `foo`.`example_03` (
 f_01  TINYINT,           -- from -128 to 127
 f_02  TINYINT UNSIGNED,  -- from 0 to 256
 f_03  SMALLINT,          -- from -32,768 to 32,767
 f_04  SMALLINT UNSIGNED, -- from 0 to 65,535
 f_05  MEDIUMINT,         -- from -8,388,608 to 8,388,607
 f_06  MEDIUMINT UNSIGNED, -- from 0 to 16,777,215
 f_07  INT,               -- from -2,147,483,648 to 2,147,483,647
 f_08  INT UNSIGNED,      -- from 0 to 4,294,967,295
 f_09  BIGINT,
              -- from -9,223,372,036,854,775,808
              -- to  9,223,372,036,854,775,807
 f_10  BIGINT UNSIGNED    -- from 0 to 18,446,744,073,709,551,615
);
</pre>
<h5><a href="http://www.kbedell.com/mysql-programming/">Click here to go to the table of contents for all MySQL Programming Example Code</a></h5>
]]></content:encoded>
			<wfw:commentRss>http://www.kbedell.com/2009/03/07/mysql-integer-sizes-and-ranges-of-values-how-to-create/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How-To MySQL CREATE TABLE Example showing default values, NULL values and comments</title>
		<link>http://www.kbedell.com/2009/03/07/how-to-mysql-example-showing-default-values-null-values-and-comments/</link>
		<comments>http://www.kbedell.com/2009/03/07/how-to-mysql-example-showing-default-values-null-values-and-comments/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 18:36:24 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.kbedell.com/?p=115</guid>
		<description><![CDATA[This example shows how to set default values for each column &#8212; as well as how to allow (or not allow) NULL values in the column. By default, any column can contain NULL values.
(Note that we&#8217;re also using &#8220;CREATE TABLE IF NOT EXISTS&#8221; so an error doesn&#8217;t get thrown if the table already exists when [...]]]></description>
			<content:encoded><![CDATA[<p>This example shows how to set default values for each column &#8212; as well as how to allow (or not allow) NULL values in the column. By default, any column can contain NULL values.</p>
<p>(Note that we&#8217;re also using &#8220;CREATE TABLE IF NOT EXISTS&#8221; so an error doesn&#8217;t get thrown if the table already exists when we try to create it.)</p>
<p>We&#8217;ve added comments as well, though we&#8217;ll explain those after.</p>
<pre>
/*
 Create the table foo.example_02 if it doesn't exist.
*/
CREATE TABLE IF NOT EXISTS `foo`.`example_02` (
 `field_1` VARCHAR(255) NOT NULL DEFAULT '',
 `field_2` CHAR(20) NOT NULL default 'default_text',
 `field_3` INT(10) DEFAULT NULL,
 `field_4` BIGINT(20),
 `field_5` DATETIME          -- embed a comment in the definition like this...
);
</pre>
<p>
Note that if you don&#8217;t specify NULL or NOT NULL, columns by default can contain NULL values. And not specifying a default is the same as specifying &#8216;DEFAULT NULL&#8217; since MySQL uses NULL as the default value in both cases.</p>
<p>Note also that I&#8217;ve added comments to the declaration. Comments come in two types &#8212; multi-line comments, and single-line comments. </p>
<pre>
/*
      This is a multi-line comment
*/

-- This is single-line comment 

select foo from bar;   -- This means the rest of this line is a comment
</pre>
<p />
<p />
<h5><a href="http://www.kbedell.com/mysql-programming/">Click here to go to the table of contents for all MySQL Programming Example Code</a></h5>
]]></content:encoded>
			<wfw:commentRss>http://www.kbedell.com/2009/03/07/how-to-mysql-example-showing-default-values-null-values-and-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic How-To Example of a MySQL CREATE TABLE command</title>
		<link>http://www.kbedell.com/2009/03/07/basic-how-to-example-of-a-mysql-create-table-command/</link>
		<comments>http://www.kbedell.com/2009/03/07/basic-how-to-example-of-a-mysql-create-table-command/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 18:29:41 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.kbedell.com/?p=110</guid>
		<description><![CDATA[Here&#8217;s a basic example of a MySQL CREATE TABLE command.

CREATE TABLE `foo`.`example_01` (
`field_1`         VARCHAR(255),
`field_2`         CHAR(10),
`field_3`         INT(10),
`field_4`         BIGINT(20),
`field_5`       [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a basic example of a MySQL CREATE TABLE command.</p>
<pre>
CREATE TABLE `foo`.`example_01` (
`field_1`         VARCHAR(255),
`field_2`         CHAR(10),
`field_3`         INT(10),
`field_4`         BIGINT(20),
`field_5`         DATETIME
);
</pre>
<p>
Notice that the &#8216;back tic&#8217;s on each column definition (the little ` characters) are optional in most cases. I use them for reasons I&#8217;ll discuss later on.</p>
<p />
Also, for most columns you see a number in parentheses after the name of the type &#8212; that is the default size for displaying that value in a select statement. </p>
<p>The actual size of the value you store in that column isn&#8217;t impacted by changing that number. Changing INT(10) to INT(12) won&#8217;t change the size of the data you can store in that column.</p>
<p/>
<h5><a href="http://www.kbedell.com/mysql-programming/">Click here to go to the table of contents for all MySQL Programming Example Code</a></h5>
]]></content:encoded>
			<wfw:commentRss>http://www.kbedell.com/2009/03/07/basic-how-to-example-of-a-mysql-create-table-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get the contents of the database.yml file from ActiveRecord</title>
		<link>http://www.kbedell.com/2009/03/06/how-to-get-the-contents-of-the-database-ml-file-from-activerecord-and-connect-to-two-databases-at-once/</link>
		<comments>http://www.kbedell.com/2009/03/06/how-to-get-the-contents-of-the-database-ml-file-from-activerecord-and-connect-to-two-databases-at-once/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 14:09:17 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.kbedell.com/?p=70</guid>
		<description><![CDATA[Save to delicious.
Sometimes when using Active Record you may want to create a database connection to a database other than the default database specified in your database.yml file.
When this happens, the easiest way to do it is to use the Class-level convenience method on ActiveRecord::Base. Like this:
Imagine your database.yml entry looks like this:
development_foo:
  adapter: [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://delicious.com/url/c5db65f90af6455a805484b6e7c67ccf">Save to delicious.</a></p>
<p>Sometimes when using Active Record you may want to create a database connection to a database other than the default database specified in your database.yml file.</p>
<p>When this happens, the easiest way to do it is to use the Class-level convenience method on ActiveRecord::Base. Like this:</p>
<p>Imagine your database.yml entry looks like this:</p>
<pre>development_foo:
  adapter: mysql
  encoding: utf8
  database: foo
  pool: 5
  username: my_user
  password: my_pass
  socket: /tmp/mysql.sock</pre>
<p>Now you want to create active record models that use that database connection. Here&#8217;s how:</p>
<pre># 'Bar' model points to the table 'bars' in the database 'foo'

class Bar &lt; ActiveRecord::Base

  # specify the database.yml entry
  $db_config = 'development_foo'

  # Fetch the database.yml configuration
  $config = ActiveRecord::Base.configurations[$db_config]

 # Now we can establish a connection to that database and
 # this ActiveRecord model class will point to that database.
  establish_connection $config

end</pre>
<p>It&#8217;s simple!</p>
<h6>Copyright Kevin Bedell, 2009<br />
All this code can be freely used under the terms of the MIT License.</h6>
]]></content:encoded>
			<wfw:commentRss>http://www.kbedell.com/2009/03/06/how-to-get-the-contents-of-the-database-ml-file-from-activerecord-and-connect-to-two-databases-at-once/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Redswingline twitter bot now active again</title>
		<link>http://www.kbedell.com/2009/02/20/redswingline-stapler-twitter-bot/</link>
		<comments>http://www.kbedell.com/2009/02/20/redswingline-stapler-twitter-bot/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 13:43:03 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[twitter]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.kbedell.com/?p=5</guid>
		<description><![CDATA[Yes, it was me.
I created the redswingline stapler twitter bot almost two years ago as a way of experimenting with Twitter and its API. I had been watching the movie Office Space a lot and thought it would be fun to create a twitter avatar of the red swingline stapler that was on Milton&#8217;s desk.
Anyway, [...]]]></description>
			<content:encoded><![CDATA[<p>Yes, it was me.</p>
<p>I created the <a href="http://twitter.com/redswingline" target="_blank">redswingline stapler twitter bot</a> almost two years ago as a way of experimenting with Twitter and its API. I had been watching the movie Office Space a lot and thought it would be fun to create a twitter avatar of the red swingline stapler that was on Milton&#8217;s desk.</p>
<p>Anyway, it was off-line for about a year but I recently started it up again.</p>
<p>I hate to admit, but that stapler has more twitter followers <a href="http://twitter.com/kbedell" target="_blank">than I do</a>&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kbedell.com/2009/02/20/redswingline-stapler-twitter-bot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
