<?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>Procbits</title>
	<atom:link href="http://procbits.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://procbits.com</link>
	<description>source code snippets and other random musings about software</description>
	<lastBuildDate>Fri, 15 Jan 2010 21:59:56 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='procbits.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/6dad4ae480a90a3903741f18af1ec27f?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>Procbits</title>
		<link>http://procbits.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://procbits.com/osd.xml" title="Procbits" />
	<atom:link rel='hub' href='http://procbits.com/?pushpress=hub'/>
		<item>
		<title>Handy C# XML Serialization Methods</title>
		<link>http://procbits.com/2010/01/15/handy-c-xml-serialization-methods/</link>
		<comments>http://procbits.com/2010/01/15/handy-c-xml-serialization-methods/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 21:59:56 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=35</guid>
		<description><![CDATA[I have been hacking away on WPF/MVVM, GWT/MVP, and Rails for the last six months and haven&#8217;t found much time to update. But I wrote some handy C# XML serialization methods. They are very straightforward.
Deserialize:

public static T ReadFromFile(string file) {
	XmlSerializer xs = new XmlSerializer(typeof(T));
	StreamReader sr = new StreamReader(file);
	T ret = (T)xs.Deserialize(sr);
	sr.Close();
	return ret;
}

Serialize:

public static void WriteToFile(T [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=35&subd=procbits&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I have been hacking away on WPF/MVVM, GWT/MVP, and Rails for the last six months and haven&#8217;t found much time to update. But I wrote some handy C# XML serialization methods. They are very straightforward.</p>
<p>Deserialize:<br />
<code><br />
public static T ReadFromFile(string file) {<br />
	XmlSerializer xs = new XmlSerializer(typeof(T));<br />
	StreamReader sr = new StreamReader(file);<br />
	T ret = (T)xs.Deserialize(sr);<br />
	sr.Close();<br />
	return ret;<br />
}<br />
</code></p>
<p>Serialize:<br />
<code><br />
public static void WriteToFile(T obj, string file) {<br />
	XmlSerializer xs = new XmlSerializer(typeof(T));<br />
	StreamWriter sw = new StreamWriter(file);<br />
	xs.Serialize(sw, obj);<br />
	sw.Close();<br />
}<br />
</code></p>
<p>Enjoy.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=35&subd=procbits&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2010/01/15/handy-c-xml-serialization-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4ecadec0193bc16860cf20d02204ce3d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>SQLite Bulk Insert In C#/.NET</title>
		<link>http://procbits.com/2009/09/08/sqlite-bulk-insert/</link>
		<comments>http://procbits.com/2009/09/08/sqlite-bulk-insert/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 19:39:44 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SQLite]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=30</guid>
		<description><![CDATA[Recently, I had a project where I needed to load 1 million+ records into a SQLite database. I downloaded the SQLite ADO.NET adapter and setup the Entity framework to map to my SQLite database. All was simple and all was well!
I started inserting the data into my database; lo and behold, it was taking forever! [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=30&subd=procbits&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I had a project where I needed to load 1 million+ records into a SQLite database. I downloaded the <a href="http://sqlite.phxsoftware.com/">SQLite ADO.NET adapter</a> and setup the Entity framework to map to my SQLite database. All was simple and all was well!</p>
<p>I started inserting the data into my database; lo and behold, it was taking forever! In fact, it took most of a full working day to insert my data. I knew something wasn&#8217;t right. A simple Google search pointed me to the <a href="http://www.sqlite.org/faq.html#q19">SQLite FAQ</a>. It turns out that SQLite wraps every INSERT into a transaction. Simple solution: start a transaction and perform multiple INSERTs. I needed my inserts to be fast, so I just had to write a class to encapsulate this.</p>
<p>It&#8217;s very simple to use. Make sure that your SQLite database file has been created and your table has been created as well.</p>
<p>Let&#8217;s assume your database schema looks like the following:<br />
Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,<br />
LastName VARCHAR(16) NOT NULL,<br />
Height REAL NOT NULL</p>
<p>You would then use SQLiteBulkInsert as follows:</p>
<pre>SQLiteBulkInsert sbi = new SQLiteBulkInsert(yourDatabaseConnectionObject, "yourTableName");
sbi.AddParameter("LastName", DbType.String);
sbi.AddParameter("Height", DbType.Single);</pre>
<p>You can then insert records:</p>
<pre>for (int x = 0; x &lt; 10000; x++)
	sbi.Insert(new object[]{someString, someFloat});
sbi.Flush();</pre>
<p>That&#8217;s it! You should look at the file SQLiteBulkInsertTest.cs for more details.</p>
<p>SQLiteBulkInsert.cs:</p>
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;

namespace YourProject.Data.SQLite
{
	public class SQLiteBulkInsert
	{
		private SQLiteConnection m_dbCon;
		private SQLiteCommand m_cmd;
		private SQLiteTransaction m_trans;

		private Dictionary m_parameters = new Dictionary();

		private uint m_counter = 0;

		private string m_beginInsertText;

		public SQLiteBulkInsert(SQLiteConnection dbConnection, string tableName) {
			m_dbCon = dbConnection;
			m_tableName = tableName;

			StringBuilder query = new StringBuilder(255);
			query.Append("INSERT INTO ["); query.Append(tableName); query.Append("] (");
			m_beginInsertText = query.ToString();
		}

		private bool m_allowBulkInsert = true;
		public bool AllowBulkInsert { get { return m_allowBulkInsert; } set { m_allowBulkInsert = value; } }

		public string CommandText {
			get {
				if (m_parameters.Count &lt; 1)
					throw new SQLiteException("You must add at least one parameter.");

				StringBuilder sb = new StringBuilder(255);
				sb.Append(m_beginInsertText);

				foreach (string param in m_parameters.Keys) {
					sb.Append('[');
					sb.Append(param);
					sb.Append(']');
					sb.Append(", ");
				}
				sb.Remove(sb.Length - 2, 2);

				sb.Append(") VALUES (");

				foreach (string param in m_parameters.Keys) {
					sb.Append(m_paramDelim);
					sb.Append(param);
					sb.Append(", ");
				}
				sb.Remove(sb.Length - 2, 2);

				sb.Append(")");

				return sb.ToString();
			}
		}

		private uint m_commitMax = 10000;
		public uint CommitMax { get { return m_commitMax; } set { m_commitMax = value; } }

		private string m_tableName;
		public string TableName { get { return m_tableName; } }

		private string m_paramDelim = ":";
		public string ParamDelimiter { get { return m_paramDelim; } }

		public void AddParameter(string name, DbType dbType) {
			SQLiteParameter param = new SQLiteParameter(m_paramDelim + name, dbType);
			m_parameters.Add(name, param);
		}

		public void Flush() {
			try {
				if (m_trans != null)
					m_trans.Commit();
			}
			catch (Exception ex) { throw new Exception("Could not commit transaction. See InnerException for more details", ex); }
			finally {
				if (m_trans != null)
					m_trans.Dispose();

				m_trans = null;
				m_counter = 0;
			}
		}

		public void Insert(object[] paramValues) {
			if (paramValues.Length != m_parameters.Count)
				throw new Exception("The values array count must be equal to the count of the number of parameters.");

			m_counter++;

			if (m_counter == 1) {
				if (m_allowBulkInsert)
					m_trans = m_dbCon.BeginTransaction();

				m_cmd = m_dbCon.CreateCommand();
				foreach (SQLiteParameter par in m_parameters.Values)
					m_cmd.Parameters.Add(par);

				m_cmd.CommandText = this.CommandText;
			}

			int i = 0;
			foreach (SQLiteParameter par in m_parameters.Values) {
				par.Value = paramValues[i];
				i++;
			}

			m_cmd.ExecuteNonQuery();

			if (m_counter == m_commitMax) {
				try {
					if (m_trans != null)
						m_trans.Commit();
				}
				catch (Exception ex) { }
				finally {
					if (m_trans != null) {
						m_trans.Dispose();
						m_trans = null;
					}

					m_counter = 0;
				}
			}
		}
	}
}</pre>
<p>SQLiteBulkInsertTest.cs:</p>
<pre>using YourProject.Data.SQLite;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.SQLite;
using System.Data;
using System.IO;
using System;

namespace TestYourProject
{
    ///
    ///This is a test class for SQLiteBulkInsertTest and is intended
    ///to contain all SQLiteBulkInsertTest Unit Tests
    ///
	[TestClass()]
	public class SQLiteBulkInsertTest
	{
		private static string m_testDir;
		private static string m_testFile;
		private static string m_testTableName = "test_table";
		private static string m_connectionString;

		private static string m_deleteAllQuery = "DELETE FROM [{0}]";
		private static string m_countAllQuery = "SELECT COUNT(id) FROM [{0}]";
		private static string m_selectAllQuery = "SELECT * FROM [{0}]";

		private static SQLiteConnection m_dbCon;
		private static SQLiteCommand m_deleteAllCmd;
		private static SQLiteCommand m_countAllCmd;
		private static SQLiteCommand m_selectAllCmd;

		private TestContext testContextInstance;

		///
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///
		public TestContext TestContext {
			get {
				return testContextInstance;
			}
			set {
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		//
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		[ClassInitialize()]
		public static void MyClassInitialize(TestContext testContext){
			Random rand = new Random(Environment.TickCount);
			int rn = rand.Next(0, int.MaxValue);
			m_testDir = @"C:\SqliteBulkInsertTest-" + rn + @"\";
			m_testFile = m_testDir + "db.sqlite";

			if (!Directory.Exists(m_testDir))
				Directory.CreateDirectory(m_testDir);

			if (!File.Exists(m_testFile)) {
				FileStream fs = File.Create(m_testFile);
				fs.Close();
			}

			m_connectionString = string.Format(@"data source={0};datetimeformat=Ticks", m_testFile);
			m_dbCon = new SQLiteConnection(m_connectionString);
			m_dbCon.Open();

			SQLiteCommand cmd = m_dbCon.CreateCommand();
			string query = "CREATE TABLE IF NOT EXISTS [{0}] (id INTEGER PRIMARY KEY AUTOINCREMENT, somestring VARCHAR(16), somereal REAL, someint INTEGER(4), somedt DATETIME)";
			query = string.Format(query, m_testTableName);
			cmd.CommandText = query;
			cmd.ExecuteNonQuery();
		}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		[ClassCleanup()]
		public static void MyClassCleanup(){
			m_dbCon.Close();

			File.Delete(m_testFile);
			Directory.Delete(m_testDir);
		}
		#endregion

		private void AddParameters(SQLiteBulkInsert target) {
			target.AddParameter("somestring", DbType.String);
			target.AddParameter("somereal", DbType.String);
			target.AddParameter("someint", DbType.Int32);
			target.AddParameter("somedt", DbType.DateTime);
		}

		private long CountRecords() {
			m_countAllCmd = m_dbCon.CreateCommand();
			m_countAllCmd.CommandText = string.Format(m_countAllQuery, m_testTableName);

			long ret = (long)m_countAllCmd.ExecuteScalar();
			m_countAllCmd.Dispose();

			return ret;
		}

		private void DeleteRecords() {
			m_deleteAllCmd = m_dbCon.CreateCommand();
			m_deleteAllCmd.CommandText = string.Format(m_deleteAllQuery, m_testTableName);

			m_deleteAllCmd.ExecuteNonQuery();
			m_deleteAllCmd.Dispose();
		}

		private SQLiteDataReader SelectAllRecords() {
			m_selectAllCmd = m_dbCon.CreateCommand();
			m_selectAllCmd.CommandText = string.Format(m_selectAllQuery, m_testTableName);
			return m_selectAllCmd.ExecuteReader();
		}

		[TestMethod()]
		public void AddParameterTest() {
			SQLiteBulkInsert target = new SQLiteBulkInsert(m_dbCon, m_testTableName);
			AddParameters(target);

			string pd = target.ParamDelimiter;
			string expectedStmnt = "INSERT INTO [{0}] ([somestring], [somereal], [someint], [somedt]) VALUES ({1}somestring, {2}somereal, {3}someint, {4}somedt)";
			expectedStmnt = string.Format(expectedStmnt, m_testTableName, pd, pd, pd, pd);
			Assert.AreEqual(expectedStmnt, target.CommandText);
		}

		[TestMethod()]
		public void SQLiteBulkInsertConstructorTest() {
			SQLiteBulkInsert target = new SQLiteBulkInsert(m_dbCon, m_testTableName);
			Assert.AreEqual(m_testTableName, target.TableName);

			bool wasException = false;
			try {
				string a = target.CommandText;
			}
			catch (SQLiteException ex) { wasException = true; }

			Assert.IsTrue(wasException);
		}

		[TestMethod()]
		public void CommandTextTest() {
			SQLiteBulkInsert target = new SQLiteBulkInsert(m_dbCon, m_testTableName);
			AddParameters(target);

			string pd = target.ParamDelimiter;
			string expectedStmnt = "INSERT INTO [{0}] ([somestring], [somereal], [someint], [somedt]) VALUES ({1}somestring, {2}somereal, {3}someint, {4}somedt)";
			expectedStmnt = string.Format(expectedStmnt, m_testTableName, pd, pd, pd, pd);
			Assert.AreEqual(expectedStmnt, target.CommandText);
		}

		[TestMethod()]
		public void TableNameTest() {
			SQLiteBulkInsert target = new SQLiteBulkInsert(m_dbCon, m_testTableName);
			Assert.AreEqual(m_testTableName, target.TableName);
		}

		[TestMethod()]
		public void InsertTest() {
			SQLiteBulkInsert target = new SQLiteBulkInsert(m_dbCon, m_testTableName);

			bool didThrow = false;
			try {
				target.Insert(new object[] { "hello" }); //object.length must equal the number of parameters added
			}
			catch (Exception ex) { didThrow = true; }
			Assert.IsTrue(didThrow);

			AddParameters(target);

			target.CommitMax = 4;
			DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now; DateTime dt3 = DateTime.Now; DateTime dt4 = DateTime.Now;
			target.Insert(new object[] { "john", 3.45f, 10, dt1 });
			target.Insert(new object[] { "paul", -0.34f, 100, dt2 });
			target.Insert(new object[] { "ringo", 1000.98f, 1000, dt3 });
			target.Insert(new object[] { "george", 5.0f, 10000, dt4 });

			long count = CountRecords();
			Assert.AreEqual(4, count);

			SQLiteDataReader reader = SelectAllRecords();

			Assert.IsTrue(reader.Read());
			Assert.AreEqual("john", reader.GetString(1)); Assert.AreEqual(3.45f, reader.GetFloat(2));
			Assert.AreEqual(10, reader.GetInt32(3)); Assert.AreEqual(dt1, reader.GetDateTime(4));

			Assert.IsTrue(reader.Read());
			Assert.AreEqual("paul", reader.GetString(1)); Assert.AreEqual(-0.34f, reader.GetFloat(2));
			Assert.AreEqual(100, reader.GetInt32(3)); Assert.AreEqual(dt2, reader.GetDateTime(4));

			Assert.IsTrue(reader.Read());
			Assert.AreEqual("ringo", reader.GetString(1)); Assert.AreEqual(1000.98f, reader.GetFloat(2));
			Assert.AreEqual(1000, reader.GetInt32(3)); Assert.AreEqual(dt3, reader.GetDateTime(4));

			Assert.IsTrue(reader.Read());
			Assert.AreEqual("george", reader.GetString(1)); Assert.AreEqual(5.0f, reader.GetFloat(2));
			Assert.AreEqual(10000, reader.GetInt32(3)); Assert.AreEqual(dt4, reader.GetDateTime(4));

			Assert.IsFalse(reader.Read());

			DeleteRecords();

			count = CountRecords();
			Assert.AreEqual(0, count);
		}

		[TestMethod()]
		public void FlushTest() {
			string[] names = new string[] { "metalica", "beatles", "coldplay", "tiesto", "t-pain", "blink 182", "plain white ts", "staind", "pink floyd" };
			Random rand = new Random(Environment.TickCount);

			SQLiteBulkInsert target = new SQLiteBulkInsert(m_dbCon, m_testTableName);
			AddParameters(target);

			target.CommitMax = 1000;

			//Insert less records than commitmax
			for (int x = 0; x &lt; 50; x++)
				target.Insert(new object[] { names[rand.Next(names.Length)], (float)rand.NextDouble(), rand.Next(50), DateTime.Now });

			//Close connect to verify records were not inserted
			m_dbCon.Close();

			m_dbCon = new SQLiteConnection(m_connectionString);
			m_dbCon.Open();

			long count = CountRecords();
			Assert.AreEqual(0, count);

			//Now actually verify flush worked
			target = new SQLiteBulkInsert(m_dbCon, m_testTableName);
			AddParameters(target);

			target.CommitMax = 1000;

			//Insert less records than commitmax
			for (int x = 0; x &lt; 50; x++)
				target.Insert(new object[] { names[rand.Next(names.Length)], (float)rand.NextDouble(), rand.Next(50), DateTime.Now });

			target.Flush();

			count = CountRecords();
			Assert.AreEqual(50, count);

			//Close connect to verify flush worked
			m_dbCon.Close();

			m_dbCon = new SQLiteConnection(m_connectionString);
			m_dbCon.Open();

			count = CountRecords();
			Assert.AreEqual(50, count);

			DeleteRecords();
			count = CountRecords();
			Assert.AreEqual(0, count);
		}

		[TestMethod()]
		public void CommitMaxTest() {
			SQLiteBulkInsert target = new SQLiteBulkInsert(m_dbCon, m_testTableName);

			target.CommitMax = 4;
			Assert.AreEqual(4, target.CommitMax);

			target.CommitMax = 1000;
			Assert.AreEqual(1000, target.CommitMax);
		}

		//SPEED TEST
		[TestMethod()]
		public void AllowBulkInsertTest() {
			string[] names = new string[] { "metalica", "beatles", "coldplay", "tiesto", "t-pain", "blink 182", "plain white ts", "staind", "pink floyd"};
			Random rand = new Random(Environment.TickCount);

			SQLiteBulkInsert target = new SQLiteBulkInsert(m_dbCon, m_testTableName);
			AddParameters(target);

			const int COUNT = 100;

			target.CommitMax = COUNT;

			DateTime start1 = DateTime.Now;
			for (int x = 0; x &lt; COUNT; x++)
				target.Insert(new object[] { names[rand.Next(names.Length)], (float)rand.NextDouble(), rand.Next(COUNT), DateTime.Now });

			DateTime end1 = DateTime.Now;
			TimeSpan delta1 = end1 - start1;

			DeleteRecords();

			target.AllowBulkInsert = false;
			DateTime start2 = DateTime.Now;
			for (int x = 0; x &lt; COUNT; x++)
				target.Insert(new object[] { names[rand.Next(names.Length)], (float)rand.NextDouble(), rand.Next(COUNT), DateTime.Now });

			DateTime end2 = DateTime.Now;
			TimeSpan delta2 = end2 - start2;

			//THIS MAY FAIL DEPENDING UPON THE MACHINE THE TEST IS RUNNING ON.
			Assert.IsTrue(delta1.TotalSeconds &lt; 0.1); //approx true for 100 recs 			Assert.IsTrue(delta2.TotalSeconds &gt; 1.0); //approx true for 100 recs;

			//UNCOMMENT THIS TO MAKE IT FAIL AND SEE ACTUAL NUMBERS IN FAILED REPORT
			//Assert.AreEqual(delta1.TotalSeconds, delta2.TotalSeconds);

			DeleteRecords();
		}
	}
}</pre>
<p>Enjoy. Drop me a line if you have any problems.</p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=30&subd=procbits&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2009/09/08/sqlite-bulk-insert/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4ecadec0193bc16860cf20d02204ce3d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Read File Contents (Blobs) in GWT and Gears</title>
		<link>http://procbits.com/2009/07/29/read-file-contents-blobs-in-gwt-and-gears/</link>
		<comments>http://procbits.com/2009/07/29/read-file-contents-blobs-in-gwt-and-gears/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 21:24:01 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[GWT]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=19</guid>
		<description><![CDATA[What do you do if you want to read the contents of a file in your GWT application? One possible solution is to use Google Gears.
Gears offers a method to allow a user to select file(s). You can then use the returned &#8220;getFiles&#8221; method of the &#8220;OpenFilesEvent&#8221; object to find out what file(s) the user [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=19&subd=procbits&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>What do you do if you want to read the contents of a file in your GWT application? One possible solution is to use Google Gears.</p>
<p>Gears offers a method to allow a user to select file(s). You can then use the returned &#8220;getFiles&#8221; method of the &#8220;OpenFilesEvent&#8221; object to find out what file(s) the user selected. Each &#8220;File&#8221; class has a method called &#8220;getBlob&#8221; that returns a &#8220;Blob&#8221; object. However, each blob object doesn&#8217;t provide any direct way to access the blobs contents. Many <a href="http://www.arcaner.com/2008/09/14/google-gears-blob-hate/">people</a> <a href="http://groups.google.com/group/gears-users/browse_thread/thread/0b4d3933a1ef0e91?fwc=1">haven&#8217;t</a> found a way to read the blob contents.</p>
<p>I wrote a class to access the contents of the blob. The class is called &#8220;BlobReader&#8221; and is very simple to use. The trick lies in the fact that in Javascript we can access the &#8220;getBytes&#8221; method of the blob.</p>
<p>Here is an example reading line by line of a text file:</p>
<pre>try {
	Desktop dt = Factory.getInstance().createDesktop();
	dt.openFiles(new OpenFilesHandler(){
		public void onOpenFiles(OpenFilesEvent event) {
			File[] files = event.getFiles();
			File file = files[0];
			Blob data = file.getBlob();

			BlobReader br = new BlobReader(data);
			while (!br.endOfBlob())
				Window.alert(br.readLine());
			}
		}, true);
} catch (Exception ex){
	Window.alert(ex.toString());
}</pre>
<p>Here is BlobReader.java:</p>
<pre>package com.yourpackage.client;
import com.google.gwt.core.client.JsArrayInteger;
import com.google.gwt.gears.client.blob.Blob;

public class BlobReader {

	private final int CHUNK_SIZE = 1024;

	public BlobReader(Blob blob){
		this.blob = blob;
	}

	private Blob blob;
	public Blob getBlob(){ return this.blob; }

	private int blobPointer = 0;
	public int getBlobPointer(){ return this.blobPointer; }

	public boolean endOfBlob(){
		return (blobPointer &gt;= blob.getLength());
	}

	public byte[] readAllBytes(){
		return getBlobBytes(this.blob);
	}

	public String readAllText(){
		int size = this.blob.getLength();
		StringBuilder sb = new StringBuilder(size);

		JsArrayInteger bytes = getBlobBytes(this.blob, 0, size);
		for (int x = 0; x &lt; size; x++)
			sb.append((char)bytes.get(x));

		return sb.toString();
	}

	public String readLine(){
		int size = CHUNK_SIZE;
		boolean foundEndOfLine = false;

		JsArrayInteger bytes;
		StringBuilder sb = new StringBuilder(CHUNK_SIZE);

		while (!foundEndOfLine &amp;&amp; size &gt; 0){
			int dif = this.blob.getLength() - this.blobPointer; //remainder of the data
			if (dif &lt; CHUNK_SIZE)
				size = dif;
			bytes = getBlobBytes(this.blob, this.blobPointer, size);

			for (int x = 0; x &lt; size; x++){
				blobPointer++;
				int b = bytes.get(x);
				if (b == 10){ //newline
					foundEndOfLine = true;
					break;
				}
				sb.append((char)b);

				if (this.getBlobPointer() % 1000000 == 0)
					Window.alert("" + this.getBlobPointer());
			}
		}

		if (sb.substring(sb.length() - 1) == "\r")
			sb.deleteCharAt(sb.length() - 1);

		return sb.toString();
	}

       public void reset(){
		this.blobPointer = 0;
	}

	private byte[] getBlobBytes(Blob b){
		JsArrayInteger array = getBlobBytes(b, 0, b.getLength());
		byte[] bytes = new byte[array.length()];
		for (int x = 0; x &lt; bytes.length; x++)
			bytes[x] = (byte) array.get(x); //in google docs we are told these are from 0-255

		return bytes;
	}

	private native JsArrayInteger getBlobBytes(Blob b, int offset, int length) /*-{
		return b.getBytes(offset, length);
	}-*/;
}</pre>
<p>Notes:<br />
1) This hasn&#8217;t been thoroughly tested/debugged.<br />
2) At the time of this writing, I&#8217;m using Gears 0.5 with the GWT-Gears 1.2.1. In the current GWT-Gears svn trunk you can see upcoming support for the GWT methods &#8220;getNativeBytes&#8221; and &#8220;getBytes&#8221;</p>
<p>Enjoy!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=19&subd=procbits&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2009/07/29/read-file-contents-blobs-in-gwt-and-gears/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4ecadec0193bc16860cf20d02204ce3d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Convert InnoDB Tables to MyISAM</title>
		<link>http://procbits.com/2009/04/07/convert-innodb-tables-to-myisam/</link>
		<comments>http://procbits.com/2009/04/07/convert-innodb-tables-to-myisam/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 02:00:42 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[MySql]]></category>
		<category><![CDATA[Slicehost]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=17</guid>
		<description><![CDATA[I have been trying to optimize my 256 MB slice from slicehost.  One of the strategies is to not use the InnoDB SQL engine for your tables and instead use MyISAM.  If you need transactions or foreign key support you should not do this.
I came across this snippet:

SELECT CONCAT('ALTER TABLE ',table_schema,'.',table_name,' engine=MyISAM;') FROM [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=17&subd=procbits&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>I have been trying to optimize my 256 MB slice from <a href="http://slicehost.com">slicehost</a>.  One of the strategies is to <strong>not</strong> use the InnoDB SQL engine for your tables and instead use MyISAM.  If you need transactions or foreign key support you should not do this.</p>
<p>I came across this <a href="http://codesnippets.joyent.com/posts/show/1451">snippet</a>:<br />
<code><br />
SELECT CONCAT('ALTER TABLE ',table_schema,'.',table_name,' engine=MyISAM;') FROM information_schema.tables WHERE engine = 'InnoDB';<br />
</code></p>
<p>It seems to have worked.  Maybe I&#8217;ll provide an article or tutorial in the future on benchmarking your slice.</p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=17&subd=procbits&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2009/04/07/convert-innodb-tables-to-myisam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4ecadec0193bc16860cf20d02204ce3d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Backup a MySQL Database on Ubuntu</title>
		<link>http://procbits.com/2009/04/07/backup-a-mysql-database-on-ubuntu/</link>
		<comments>http://procbits.com/2009/04/07/backup-a-mysql-database-on-ubuntu/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 01:45:26 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySql]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=14</guid>
		<description><![CDATA[Backing up a MySQL database is extremely simple.  Just simply create a directory as to where you want to store your backups.  I typically just dump them in /var/dbbak.  You can then run the following command:

/usr/bin/mysqldump -u root -p YOUR_DB_NAME &#124; gzip &#62; /root/dbbak/YOUR_DB_NAME_`date +%y_%m_%d`.gz

-JP
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=14&subd=procbits&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<p>Backing up a MySQL database is extremely simple.  Just simply create a directory as to where you want to store your backups.  I typically just dump them in /var/dbbak.  You can then run the following command:<br />
<code><br />
/usr/bin/mysqldump -u root -p YOUR_DB_NAME | gzip &gt; /root/dbbak/YOUR_DB_NAME_`date +%y_%m_%d`.gz<br />
</code></p>
<p>-JP</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=14&subd=procbits&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2009/04/07/backup-a-mysql-database-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4ecadec0193bc16860cf20d02204ce3d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Deploying a Rails application on Ubuntu 8.04 LTS with Phusion Passenger and SQL Server 2005</title>
		<link>http://procbits.com/2009/03/10/deploying-a-rails-application-on-ubuntu-804-lts-with-phusion-passenger-and-sql-server-2005/</link>
		<comments>http://procbits.com/2009/03/10/deploying-a-rails-application-on-ubuntu-804-lts-with-phusion-passenger-and-sql-server-2005/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 05:50:10 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Modrails]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=5</guid>
		<description><![CDATA[
This article will provide step by step instructions for preparing and then deploying a Rails application on Ubuntu 8.04 LTS that uses Microsoft SQL Server 2005.
Install Ruby
sudo apt-get install ruby-full build-essential
Install Apache 2
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
Install Ruby Gems
Do not install Ruby Gems from Apt.  This will screw up your Gems repository as Apt [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=5&subd=procbits&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div>
<p>This article will provide step by step instructions for preparing and then deploying a Rails application on Ubuntu 8.04 LTS that uses Microsoft SQL Server 2005.</p>
<p><strong>Install Ruby</strong><br />
<code>sudo apt-get install ruby-full build-essential</code></p>
<p><strong>Install Apache 2</strong><br />
<code>sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev</code></p>
<p><strong>Install Ruby Gems</strong><br />
Do not install Ruby Gems from Apt.  This will screw up your Gems repository as Apt and Gems will both want to manage it.  Download the latest Gems package from <a href="http://rubyforge.org/" target="_blank">http://rubyforge.org</a>.  At the time of this writing the latest version is 1.3.  Version 1.3 is also the version that I used.<code><br />
wget <a href="http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz" target="_blank">http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz</a><br />
tar xzvf rubygems-1.3.0.tgz<br />
cd rubygems-1.3.0<br />
sudo ruby setup.rb<br />
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem<br />
sudo gem update --system</code></p>
<p><strong>Install Rails</strong><br />
Make sure to install the proper version.  You may need to pass the &#8220;&#8211;version&#8221; flag.<br />
<code>sudo gem install rails</code></p>
<p><strong>Install Phusion Passenger</strong><br />
This allows us to deploy Rails application with as much simplicity as it takes to deploy a PHP application.  This we can avoid using Mongrel/Proxy Balancing/(Apache|Lighttpd|Nginx).<code><br />
sudo gem install passenger<br />
sudo passenger-install-apache2-module</code></p>
<p>Next add the following to your /etc/apache2/apache2.conf file:<br />
<code> LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so<br />
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3<br />
PassengerRuby /usr/bin/ruby1.8</code></p>
<p><strong>Install Ruby/ODBC/SQLServer2005 Compatibility</strong><br />
In /etc/profile add the following:<br />
<code> export ODBCINI=/etc/odbc.ini<br />
export ODBCSYSINI=/etc<br />
export FREETDSCONF=/etc/freetds/freetds.conf</code></p>
<p>Make sure you restart your shell after this!</p>
<p>Now install UnixODBC:<code><br />
sudo apt-get install unixodbc<br />
sudo apt-get install unixodbc-dev<br />
sudo apt-get install tdsodbc<br />
</code></p>
<p>Now install FreeTDS (stable) from source. The FreeTDS in the Apt repository is version 0.63 and will not work with SQL Server 2005. At the time of this writing, the current stable version is 0.82.<code><br />
wget <a href="ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz" target="_blank">ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz</a><br />
cd freetds-stable<br />
./configure<br />
make<br />
sudo make install</code></p>
<p>Edit /etc/freetds/freetds.conf and add the following:<code><br />
[YOUR_DB_DEFINITION_NAME]<br />
host = 172.24.40.100<br />
port = 1433<br />
tds version = 8.0<br />
</code></p>
<p>Test it with the following:<code><br />
sqsh -S YOUR_DB_DEFINITION_NAME -U USERNAME -P PASSWORD<br />
</code></p>
<p>Once actually logged in, you can run some SQL and verify the results. Make sure to type “go” after each command and also make sure to “use” the right database.</p>
<p>Now edit /etc/odbc.ini and add the following:<code><br />
[YOUR_DB_DEFINITION_NAME]<br />
Driver          = FreeTDS<br />
Description     = ODBC connection via FreeTDS<br />
Trace           = No<br />
Servername      = YOUR_DB_DEFINITION_NAME<br />
Database        = YOUR_ACTUAL_DB_NAME<br />
</code></p>
<p>Edit /etc/odbcinst.ini and add the following:<code><br />
[FreeTDS]<br />
Description     = TDS driver (Sybase/Microsoft SQL)<br />
Driver          = /usr/lib/odbc/libtdsodbc.so<br />
Setup           = /usr/lib/odbc/libtdsS.so<br />
CPTimeout       =<br />
CPReuse         =<br />
FileUsage       = 1<br />
</code></p>
<p>Now test it….<code><br />
isql YOUR_DB_DEFINITION_NAME USERNAME PASSWORD<br />
</code></p>
<p>Install Ruby ODBC:<code><br />
wget <a href="http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9995.tar.gz" target="_blank">http://www.ch-werner.de/rubyodbc/ruby-odbc-0.9995.tar.gz</a><br />
tar zvxf ruby-odbc-0.9995.tar.gz<br />
cd ruby-odbc-0.9995/<br />
ruby extconf.rb<br />
make<br />
sudo make install<br />
</code></p>
<p>Install ActiveRecord ODBC Adapter<code><br />
sudo gem install activerecord-odbc-adapter<br />
</code></p>
<p>Edit your database.yml in your application and configure it like…<code><br />
development:<br />
adapter: odbc<br />
dsn: YOUR_DB_DEFINITION_NAME<br />
username: USERNAME<br />
password: PASSWORD<br />
</code></p>
<p>Now dump your Rails app in /var/www/yourrailsapp and add a new Apache Virtual Host as seen in the previous post. Configure the virtual host DocumentRoot to point to the public directory in Apache2.  Do not forget to change ownership of your rails app to www-data. (chown -R www-data:www-data yourrailsapp) That’s all there is too it! Now you can deploy a number of Rails apps in Apache with little trouble!</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=5&subd=procbits&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2009/03/10/deploying-a-rails-application-on-ubuntu-804-lts-with-phusion-passenger-and-sql-server-2005/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4ecadec0193bc16860cf20d02204ce3d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
		<item>
		<title>Apache Virtual Hosting</title>
		<link>http://procbits.com/2009/03/10/apache-virtual-hosting/</link>
		<comments>http://procbits.com/2009/03/10/apache-virtual-hosting/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 05:43:55 +0000</pubDate>
		<dc:creator>JP</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://procbits.com/?p=3</guid>
		<description><![CDATA[
This is extremely easy to do.  This was done on Ubuntu 8.04.  Replace &#8220;SERVER_IP&#8221; with the IP address of your  server.
Edit /etc/apache2/apache2.conf and add the following:
NameVirtualHost SERVER_IP:80
Create a new file &#8220;subdomain&#8221; in /etc/apache2/sites-available with the content:
&#60;VirtualHost SERVER_IP:80&#62; *
ServerName subdomain.yourdomain.com
DocumentRoot /var/www/subdomain
&#60;Directory “/var/www/subdomain”&#62; **
Order allow,deny
Allow from all
&#60;/Directory&#62;
&#60;/VirtualHost&#62;
Then run:
a2ensite subdomain
/etc/init.d/apache2 restart
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=3&subd=procbits&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div>
<p>This is extremely easy to do.  This was done on Ubuntu 8.04.  Replace &#8220;SERVER_IP&#8221; with the IP address of your  server.</p>
<p>Edit /etc/apache2/apache2.conf and add the following:</p>
<blockquote><p>NameVirtualHost SERVER_IP:80</p></blockquote>
<p>Create a new file &#8220;subdomain&#8221; in /etc/apache2/sites-available with the content:</p>
<blockquote><p>&lt;VirtualHost SERVER_IP:80&gt; *</p>
<p>ServerName subdomain.yourdomain.com<br />
DocumentRoot /var/www/subdomain</p>
<p>&lt;Directory “/var/www/subdomain”&gt; **<br />
Order allow,deny<br />
Allow from all<br />
&lt;/Directory&gt;</p>
<p>&lt;/VirtualHost&gt;</p></blockquote>
<p>Then run:<br />
<strong><em>a2ensite subdomain</em></strong><br />
<strong><em>/etc/init.d/apache2 restart</em></strong></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/procbits.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/procbits.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/procbits.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/procbits.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/procbits.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/procbits.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/procbits.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/procbits.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/procbits.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/procbits.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=procbits.com&blog=6893023&post=3&subd=procbits&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://procbits.com/2009/03/10/apache-virtual-hosting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4ecadec0193bc16860cf20d02204ce3d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">JP</media:title>
		</media:content>
	</item>
	</channel>
</rss>