<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>ThingsILearned &#187; sql</title>
	<atom:link href="http://thingsilearned.com/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://thingsilearned.com</link>
	<description>something new every day ... or so  By Dave Fowler</description>
	<lastBuildDate>Thu, 10 May 2012 17:32:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='thingsilearned.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>ThingsILearned &#187; sql</title>
		<link>http://thingsilearned.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://thingsilearned.com/osd.xml" title="ThingsILearned" />
	<atom:link rel='hub' href='http://thingsilearned.com/?pushpress=hub'/>
		<item>
		<title>Simple MySQLdb Example</title>
		<link>http://thingsilearned.com/2009/05/03/simple-mysqldb-example/</link>
		<comments>http://thingsilearned.com/2009/05/03/simple-mysqldb-example/#comments</comments>
		<pubDate>Mon, 04 May 2009 04:51:38 +0000</pubDate>
		<dc:creator>godavemon</dc:creator>
				<category><![CDATA[example]]></category>
		<category><![CDATA[mysqldb]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://thingsilearned.com/?p=371</guid>
		<description><![CDATA[MySQLdb is a python interface to MySQL.  I wrote the following simple script for some database tests and thought it might be handy to others looking for tutorials or examples. It simply connects to MySQL, drops and creates a database called &#8216;testdb&#8217;, makes a table called &#8216;waves&#8217; with columns &#8216;sin&#8217;, &#8216;cos&#8217;, &#8216;tan&#8217;, and &#8216;date&#8217; and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thingsilearned.com&#038;blog=1027874&#038;post=371&#038;subd=thingsilearned&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>MySQLdb is a python interface to MySQL.  I wrote the following simple script for some database tests and thought it might be handy to others looking for tutorials or examples.</p>
<p>It simply connects to MySQL, drops and creates a database called &#8216;testdb&#8217;, makes a table called &#8216;waves&#8217; with columns &#8216;sin&#8217;, &#8216;cos&#8217;, &#8216;tan&#8217;, and &#8216;date&#8217; and fills the table with a thousand data points of the trig functions performed on the date in 5 minute intervals leading up to the current date.</p>
<p>The code and comments I think are fairly straight forward, so I will just paste and link to the <a href="http://dpaste.com/hold/40714/">text version</a>.<br />
<pre class="brush: python;">
DATABASE_HOST = &quot;localhost&quot;
DATABASE_USER = &quot;root&quot;
DATABASE_NAME = &quot;testdb&quot;
DATABASE_PASSWD = &quot;YOUR PASSWORD HERE&quot;
DATABASE_PORT = 3306

import MySQLdb

# Connect to the Database
db=MySQLdb.connect(host=DATABASE_HOST,user=DATABASE_USER,
 passwd=DATABASE_PASSWD, port=int(DATABASE_PORT))

# Make the database cursor
cursor = db.cursor()

# Drop and create the database
cursor.execute(&quot;drop database %s; create database %s;&quot; % (DATABASE_NAME, DATABASE_NAME))

# Re connect to database using db=DATABASE_NAME
db=MySQLdb.connect(host=DATABASE_HOST,user=DATABASE_USER,
 passwd=DATABASE_PASSWD, db=DATABASE_NAME, port=int(DATABASE_PORT))
cursor = db.cursor()

# Create the table for the wave data
from math import sin, cos, tan
cursor.execute(&quot;&quot;&quot;CREATE TABLE waves (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
sin FLOAT,
cos FLOAT,
tan FLOAT,
date INT);
&quot;&quot;&quot;)

# Insert the sine wave data
from datetime import datetime

def STAMP( dt ):
 &quot;&quot;&quot; turns a python datetime object into a unix time stamp (seconds) &quot;&quot;&quot;
 import time
 return int(time.mktime( dt.timetuple() ))

now = STAMP( datetime.now() )
five_mins = 60*5

sql = &quot;INSERT INTO waves (sin, cos, tan, date) VALUES (%s, %s, %s, %s);&quot;

# Insert the data into the table
for i in range(1000):
 s = now - i*five_mins
 cursor.execute(sql % ( sin(s), cos(s), tan(s), s ))
</pre><br />
I really need to get some <a href="http://dpaste.com/hold/40714/">syntax highlighting</a>&#8230;  More documentation on MySQLdb can be found <a href="http://mysql-python.sourceforge.net/MySQLdb.html">here</a>.  If you have any questions leave them in the comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thingsilearned.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thingsilearned.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thingsilearned.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thingsilearned.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thingsilearned.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thingsilearned.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thingsilearned.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thingsilearned.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thingsilearned.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thingsilearned.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thingsilearned.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thingsilearned.wordpress.com/371/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thingsilearned.wordpress.com/371/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thingsilearned.wordpress.com/371/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thingsilearned.com&#038;blog=1027874&#038;post=371&#038;subd=thingsilearned&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thingsilearned.com/2009/05/03/simple-mysqldb-example/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4b0e75fea564a9693a4592692e6baeb9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">godavemon</media:title>
		</media:content>
	</item>
	</channel>
</rss>
