<?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>Scott Means &#187; coding</title>
	<atom:link href="http://smeans.com/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://smeans.com</link>
	<description>Ripping the envelope of software development, one technology at a time.</description>
	<lastBuildDate>Tue, 06 Oct 2009 13:47:26 +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>Core data model migration on the iPhone.</title>
		<link>http://smeans.com/2009/08/02/core-data-model-migration-on-the-iphone/</link>
		<comments>http://smeans.com/2009/08/02/core-data-model-migration-on-the-iphone/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 21:39:21 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://smeans.com/?p=196</guid>
		<description><![CDATA[Doing something as simple as adding a new attribute to an entity in your Core Data model will break your application when it comes to opening older persistent data stores. Core Data has some support for automatic migration, documented in the &#8220;Introduction to Core Data Model Versioning and Data Migration Programming Guide&#8221; (whew!) in the [...]]]></description>
			<content:encoded><![CDATA[<p>Doing something as simple as adding a new attribute to an entity in your Core Data model will break your application when it comes to opening older persistent data stores. Core Data has some support for automatic migration, documented in the &#8220;Introduction to Core Data Model Versioning and Data Migration Programming Guide&#8221; (whew!) in the Lightweight Migration section. Unfortunately, there are crucial steps that are not mentioned in this section. Kudos to Grouchal on Stack Overflow for giving us the <a href="http://stackoverflow.com/questions/1018155/what-do-i-have-to-do-to-get-core-data-to-automatically-migrate-models/1219911#1219911">rest of the story</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2009/08/02/core-data-model-migration-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My MySQL tool is on softpedia.com.</title>
		<link>http://smeans.com/2009/06/18/my-mysql-tool-is-on-softpediacom/</link>
		<comments>http://smeans.com/2009/06/18/my-mysql-tool-is-on-softpediacom/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 20:06:21 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://smeans.com/?p=184</guid>
		<description><![CDATA[I just got the notice today. I wrote this bulk row insert tool for MySQL that is designed to run over the Internet. It&#8217;s for really large data sets being loaded into &#8230; ahem &#8230; inexpensive hosted MySQL databases. Check out the mysqlxfer softpedia page.
]]></description>
			<content:encoded><![CDATA[<p>I just got the notice today. I wrote this bulk row insert tool for MySQL that is designed to run over the Internet. It&#8217;s for really large data sets being loaded into &#8230; ahem &#8230; <em>inexpensive</em> hosted MySQL databases. Check out the <a href="http://www.softpedia.com/get/Internet/Servers/Database-Utils/mysqlxfer.shtml">mysqlxfer softpedia page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2009/06/18/my-mysql-tool-is-on-softpediacom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roll-your-own iPhone framework.</title>
		<link>http://smeans.com/2009/06/06/roll-your-own-iphone-framework/</link>
		<comments>http://smeans.com/2009/06/06/roll-your-own-iphone-framework/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 16:05:34 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://smeans.com/?p=179</guid>
		<description><![CDATA[After starting work on my latest iPhone app (#6 or so), I finally decided it was time to get more efficient with my existing library of code. I&#8217;ve been building various helper classes for manipulating bitmaps, etc, and I wanted to be able to share them between my apps in a more organized way.
As usual, [...]]]></description>
			<content:encoded><![CDATA[<p>After starting work on my latest iPhone app (#6 or so), I finally decided it was time to get more efficient with my existing library of code. I&#8217;ve been building various helper classes for manipulating bitmaps, etc, and I wanted to be able to share them between my apps in a more organized way.</p>
<p>As usual, there isn&#8217;t much on the web about this, but I eventually tracked down a couple of useful articles to get me started:</p>
<ul>
<li><a href="http://github.com/keremk/iphone-static-library-project-template/tree/master">keremk&#8217;s iphone-static-library-project-template</a></li>
<li><a href="http://blog.stormyprods.com/2008/11/using-static-libraries-with-iphone-sdk.html">Building static libraries with the iPhone SDK</a></li>
</ul>
<p>The first article shows you how to add your own custom project type template to XCode so you can easily create shared iPhone libraries. The second one shows you how to reference your new library from your application. With a little trial-and-error I now have a nice shared lib of iPhone classes. Pretty soon, who knows, maybe Apple will allow dynamic linking and we can move iPhone development into the 80s!</p>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2009/06/06/roll-your-own-iphone-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone programming: fun with grayscale images.</title>
		<link>http://smeans.com/2009/06/03/iphone-programming-fun-with-grayscale-images/</link>
		<comments>http://smeans.com/2009/06/03/iphone-programming-fun-with-grayscale-images/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 17:55:21 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://smeans.com/?p=177</guid>
		<description><![CDATA[So I was trying to do something that I thought was simple. I needed to convert an image from full color to grayscale in my iPhone application, and I easily found the CGColorSpaceCreateDeviceGray method which seemed to put me on the right track. But the complication came when I tried to use this color space [...]]]></description>
			<content:encoded><![CDATA[<p>So I was trying to do something that I <em>thought</em> was simple. I needed to convert an image from full color to grayscale in my iPhone application, and I easily found the <span style="font-family: monospace">CGColorSpaceCreateDeviceGray</span> method which seemed to put me on the right track. But the complication came when I tried to use this color space with <span style="font-family: monospace">CGBitmapContextCreate</span>. I got this error in the console:</p>
<pre>&lt;Error&gt;: CGBitmapContextCreate: unsupported parameter combination:
8 integer bits/component; 16 bits/pixel; 1-component colorspace;
kCGImageAlphaPremultipliedLast; 1472 bytes/row.</pre>
<p>So the combination of parameters was incorrect. But which one was at fault? Thankfully, I found a helpful <a href="http://lists.apple.com/archives/Carbon-dev/2007/Jun/msg00014.html">post</a> on the web that led me to this article:</p>
<p><a href="http://developer.apple.com/qa/qa2001/qa1037.html">CGBitmapContextCreate Supported Color Spaces</a></p>
<p>Very handy. Wish that this table were actually included in the documentation for the <span style="font-family: monospace">CGBitmapContextCreate</span> method. Imagine how useful that would be! So, for your convenience, here is a function to create a grayscale copy of a <span style="font-family: monospace">UIImage</span>:</p>
<pre>UIImage *createGrayCopy(UIImage *source)
{
	int width = source.size.width;
	int height = source.size.height;

	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();

	CGContextRef context = CGBitmapContextCreate (nil,
						 width,
						 height,
						 8,      // bits per component
						 0,
						 colorSpace,
						 kCGImageAlphaNone);

	CGColorSpaceRelease(colorSpace);

	if (context == NULL) {
		return nil;
	}

	CGContextDrawImage(context,
		CGRectMake(0, 0, width, height), source.CGImage);

	UIImage *grayImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage(context)];
	CGContextRelease(context);

	return grayImage;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2009/06/03/iphone-programming-fun-with-grayscale-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A day with the Jester.</title>
		<link>http://smeans.com/2009/05/30/a-day-with-the-jester/</link>
		<comments>http://smeans.com/2009/05/30/a-day-with-the-jester/#comments</comments>
		<pubDate>Sat, 30 May 2009 21:47:52 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[life]]></category>

		<guid isPermaLink="false">http://smeans.com/?p=159</guid>
		<description><![CDATA[I just finished one of the most interesting software development projects ever this week. After responding to a note posted to the Atlanta iPhone Developer Meetup group I ended up trading emails with JD Howard, author of the Naughty Jester blog. JD wanted an iPhone app to help connect with his readers, but he didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://naughtyjester.com"><img src="http://smeans.com/wp-content/uploads/2009/05/jesterimage1-143x150.jpg" alt="The Naughty Jester" title="The Naughty Jester" width="143" height="150" class="alignright size-thumbnail wp-image-161" /></a>I just finished one of the most interesting software development projects ever this week. After responding to a note posted to the <a href="http://www.meetup.com/atliphonedev/">Atlanta iPhone Developer Meetup group</a> I ended up trading emails with JD Howard, author of the <a href="http://naughtyjester.com">Naughty Jester</a> blog. JD wanted an iPhone app to help connect with his readers, but he didn&#8217;t have a big budget and he didn&#8217;t have a lot of time. He wanted to &#8220;drive down and knock an app out&#8221; in a day or so.</p>
<p>Never one to pass up a challenge, I told him to come on down. I was careful to set his expectations as low as possible, because one day really isn&#8217;t enough time to do a meaningful application. All I could promise was that at the end we would have something to submit to the iTunes App Store, and he was OK with that.</p>
<p>So at approximately 3:00 PM on Monday (Memorial Day), JD pulled up to my house in Columbia, SC. The trip took him 5 hours, instead of the 3 that he had originally thought. After a brief meet &#038; greet (plus various social networking connections, which I guess are the modern equivalent of <a href="http://en.wikipedia.org/wiki/Visiting_card">calling cards</a>), we sat down to do a quick mockup of his site.</p>
<p>We used a new tool that I really, really like: <a href="http://www.balsamiq.com/products/mockups">Balsamique Markups</a>. It&#8217;s a very nice WYSIWYG tool for laying out web pages, applications, and iPhone apps. For OCD perfectionists (which many developers are), I find the cartoony graphics strangely freeing. It really lets me lay out the gist of something without getting sucked into the minutiae of a full design.</p>
<p>We agreed on a basic application that would:
<ul>
<li>display his blog in a browser control</li>
<li>let the user forward a link to a friend</li>
<li>take the user to a newsletter signup</li>
<li>take the user to feedburner</li>
</ul>
<p>The one rule of iPhone development is that the things you think will be simple will be hard, and the things you think will be hard will be easy. We had a browser window up and running with his blog in it within 30 minutes. But producing a decent-looking home button image took almost an hour.</p>
<p>Possibly the most interesting part of the project was having someone I&#8217;d never met come and crash at my house while developing an application. My mother (who lives with me) was a little leery of the idea at first. &#8220;What if he&#8217;s an axe murderer?&#8221;</p>
<p>After JD and I had been working for a while and I mentioned this to him, he assured her that he was not an axe murderer, which I&#8217;m not sure had the desired effect. I put it to her like this &#8220;It&#8217;s like we&#8217;re running a bed &#038; breakfast, with iPhone development on the side.&#8221; Hmmmm&#8230;.</p>
<p>In any case, working with JD was a real pleasure, and we had some interesting conversations over cigars at the end of the day. Now, let&#8217;s all keep our fingers crossed that Apple will be kind and merciful and approve the app!</p>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2009/05/30/a-day-with-the-jester/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The mother of all dynamic SQL Crosstab View Builders.</title>
		<link>http://smeans.com/2009/02/03/the-mother-of-all-dynamic-sql-crosstab-view-builders/</link>
		<comments>http://smeans.com/2009/02/03/the-mother-of-all-dynamic-sql-crosstab-view-builders/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 19:53:35 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[life]]></category>
		<category><![CDATA[crosstab]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://smeans.com/?p=110</guid>
		<description><![CDATA[Ok, so maybe it&#8217;s not too poetic, but it&#8217;s descriptive. As I found myself writing a dynamic crosstab-query builder in MS SQL for probably the fifth time of my career, I decided I&#8217;d post it here to save you all just a little time in your day. Make sure you use the saved time for [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so maybe it&#8217;s not too poetic, but it&#8217;s descriptive. As I found myself writing a dynamic crosstab-query builder in MS SQL for probably the fifth time of my career, I decided I&#8217;d post it here to save you all just a little time in your day. Make sure you use the saved time for something I&#8217;d approve of (smoking a good cigar, playing a little poker, something like that).</p>
<p>This proc is designed for when you have a dynamic set of row-oriented data you want to pivot and show column-wise. It takes four parameters:</p>
<p>@tableName &#8211; Name of the source table (or view) that will be queried by the new crosstab view.<br />
@excludeCols &#8211; A comma separated list of columns to exclude from the crosstab. In most cases, will be the ID column of the table.<br />
@valueColName &#8211; Name of the column in the @tableName table that contains the value in a given row.<br />
@targetViewName &#8211; Name of the view that the stored procedure will create. It will *automatically* drop this column before re-creating it, so be warned.</p>
<p>This proc also assumes that the @tableName table (or view) has a column called [colName]. It uses this value to create the corresponding columns across the top of the output view.</p>
<p>Good luck!</p>
<p><code>ALTER PROCEDURE BuildCrosstabView(<br />
	@tableName VARCHAR(100),<br />
	@excludeCols VARCHAR(1000),<br />
	@valueColName VARCHAR(1000),<br />
	@targetViewName VARCHAR(100)<br />
)<br />
AS<br />
BEGIN<br />
	-- SET NOCOUNT ON added to prevent extra result sets from<br />
	-- interfering with SELECT statements.<br />
	SET NOCOUNT ON;</p>
<p>	DECLARE @cols VARCHAR(4000)<br />
	SET @cols = ''</p>
<p>	EXEC ('SELECT DISTINCT colName INTO ##colList FROM ' + @tableName)<br />
	DECLARE col_cursor CURSOR FOR<br />
	SELECT colName<br />
	FROM ##colList</p>
<p>	OPEN col_cursor</p>
<p>	DECLARE @colName VARCHAR(100)</p>
<p>	FETCH NEXT FROM col_cursor INTO @colName</p>
<p>	WHILE @@FETCH_STATUS = 0<br />
	BEGIN</p>
<p>	IF @cols &lt;&gt; ''<br />
	BEGIN<br />
		SET @cols = @cols + ', '<br />
	END</p>
<p>	SET @cols = @cols + 'MAX(CASE colName WHEN ''' + @colName + ''' THEN ' + @valueColName + ' ELSE NULL END) AS [' + @colName + ']<br />
'<br />
	FETCH NEXT FROM col_cursor INTO @colName</p>
<p>	END</p>
<p>	CLOSE col_cursor<br />
	DEALLOCATE col_cursor</p>
<p>	DROP TABLE ##colList</p>
<p>	DECLARE @sql VARCHAR(3000)<br />
	SET @sql = 'SELECT DISTINCT ' + @excludeCols + ', ' + @cols + ' FROM ' + @tableName + ' GROUP BY ' + @excludeCols<br />
	PRINT @sql<br />
	EXECUTE (@sql)<br />
	IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[' + @targetViewName + ']'))<br />
		EXECUTE ('DROP VIEW ' + @targetViewName)<br />
	EXECUTE ('CREATE VIEW ' + @targetViewName + ' AS ' + @sql)<br />
END<br />
GO</code></p>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2009/02/03/the-mother-of-all-dynamic-sql-crosstab-view-builders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bulk SQL inserting, anyone?</title>
		<link>http://smeans.com/2008/12/14/bulk-sql-inserting-anyone/</link>
		<comments>http://smeans.com/2008/12/14/bulk-sql-inserting-anyone/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 19:50:45 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[open-source]]></category>

		<guid isPermaLink="false">http://smeans.com/?p=90</guid>
		<description><![CDATA[As part of the BlinkStory app, I needed to upload about 200K (200 thousand, for the geek-impaired) records into a MySql database hosted on a very inexpensive (cheap) hosting provider. I&#8217;d tried several options to get the data in, with frustrating results. Either my file upload would be interrupted, or an error would occur around [...]]]></description>
			<content:encoded><![CDATA[<p>As part of the BlinkStory app, I needed to upload about 200K (200 thousand, for the geek-impaired) records into a MySql database hosted on a very inexpensive (cheap) hosting provider. I&#8217;d tried several options to get the data in, with frustrating results. Either my file upload would be interrupted, or an error would occur around row 75K, wasting an hour or so of my time.</p>
<p>So I decided, like any good programmer, to roll my own solution. I created a tool for <a href="https://sourceforge.net/projects/mysqlxfer/">bulk uploading SQL over the Internet</a> that I call mysqlxfer. Not wanting to hoard it, I submitted it to <a href="http://sourceforge.net">SourceForge.net</a> as an open source project. If you need to upload a bunch of data over an unreliable and slow connection, give it a shot. It does a couple of cool things, like automatically detecting your field separator character and logging the failed inserts in SQL format to a .err file. Check it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2008/12/14/bulk-sql-inserting-anyone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A picture of misery.</title>
		<link>http://smeans.com/2008/11/02/a-picture-of-misery/</link>
		<comments>http://smeans.com/2008/11/02/a-picture-of-misery/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 16:40:10 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[life]]></category>

		<guid isPermaLink="false">http://smeans.com/?p=72</guid>
		<description><![CDATA[View Larger Map
I was reading the local paper on Thursday and came across the list of properties that will be auctioned by the Richland County treasurer for back taxes. I got curious, and found the list of properties on the county web site, but a big list of names and amounts just wasn&#8217;t very easy [...]]]></description>
			<content:encoded><![CDATA[<p><iframe width="450" height="450" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=103502897134112242148.00045a7d736f2d7be9f31&amp;s=AARTsJrGFJCAnosU4-j9tSRBaahHGo77uQ&amp;ll=34.051522,-81.009064&amp;spn=0.273076,0.439453&amp;z=11&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=103502897134112242148.00045a7d736f2d7be9f31&amp;ll=34.051522,-81.009064&amp;spn=0.273076,0.439453&amp;z=11&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small><br />
I was reading the local paper on Thursday and came across the list of properties that will be auctioned by the Richland County treasurer for back taxes. I got curious, and found the list of properties on the county web site, but a big list of names and amounts just wasn&#8217;t very easy for me to picture. So I wrote a little script, geocoded the addresses, converted the results to KML, and uploaded to it to Google Maps. Hard to believe that behind every little dot there&#8217;s a story of someone&#8217;s home lost.</p>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2008/11/02/a-picture-of-misery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check out my submission to the Truveo development contest.</title>
		<link>http://smeans.com/2008/05/22/check-out-my-submission-to-the-truveo-development-contest/</link>
		<comments>http://smeans.com/2008/05/22/check-out-my-submission-to-the-truveo-development-contest/#comments</comments>
		<pubDate>Thu, 22 May 2008 18:38:35 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://smeans.com/2008/05/22/check-out-my-submission-to-the-truveo-development-contest/</guid>
		<description><![CDATA[I just submitted my final version of Serendipity to this development contest sponsored by Truveo and run by TopCoder. Check out my application here:
http://smeans.com/truveo
It&#8217;s basically a video search tool that takes the results of one search, finds &#8220;interesting&#8221; words in the descriptions of the matching videos and searches some more. Check it out!
]]></description>
			<content:encoded><![CDATA[<p>I just submitted my final version of Serendipity to this development contest sponsored by Truveo and run by TopCoder. Check out my application here:</p>
<p><a href="http://smeans.com/truveo">http://smeans.com/truveo</a></p>
<p>It&#8217;s basically a video search tool that takes the results of one search, finds &#8220;interesting&#8221; words in the descriptions of the matching videos and searches some more. Check it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2008/05/22/check-out-my-submission-to-the-truveo-development-contest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows hosting with GoDaddy is a royal PITA.</title>
		<link>http://smeans.com/2008/05/06/windows-hosting-with-godaddy-is-a-royal-pita/</link>
		<comments>http://smeans.com/2008/05/06/windows-hosting-with-godaddy-is-a-royal-pita/#comments</comments>
		<pubDate>Tue, 06 May 2008 18:42:11 +0000</pubDate>
		<dc:creator>smeans</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://smeans.com/2008/05/06/windows-hosting-with-godaddy-is-a-royal-pita/</guid>
		<description><![CDATA[At least the shared stuff is. I&#8217;ve spent at least four hours today trying to get my SQL 2005 database configured on their server. Since they don&#8217;t allow remote access through SQL Server Management Studio, I&#8217;ve been forced to use their not-so-powerful web-based administration tool. Compounding that is the fact that I used to have [...]]]></description>
			<content:encoded><![CDATA[<p>At least the shared stuff is. I&#8217;ve spent at least four hours today trying to get my SQL 2005 database configured on their server. Since they don&#8217;t allow remote access through SQL Server Management Studio, I&#8217;ve been forced to use their not-so-powerful web-based administration tool. Compounding that is the fact that I used to have references between two different databases on my local server that I now need to merge into a single monolithic database, I&#8217;m not a happy camper.</p>
<p>As part of this process I&#8217;ve had to populate a bunch of tables with application-specific values. After wrestling with the crappy CSV import function that GoDaddy gave me I decided to write my own little tool to generate SQL INSERT statements for the data in my tables. Since WordPress won&#8217;t let me upload it, here&#8217;s the code:</p>
<pre>
<code>/*
 * Created by SharpDevelop.
 * User: smeans
 * Date: 5/6/2008
 * Time: 11:58 AM
 *
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace sql2insert
{
  class sql2insert
  {
    public static void Main(string[] args)
    {
      foreach (string dsn in args) {
        Console.WriteLine("writing files to " + System.Environment.CurrentDirectory);

        using (SqlConnection cn = new SqlConnection(args[0])) {
          cn.Open();

          DataTable dt = cn.GetSchema("Tables");

          foreach (DataRow row in dt.Rows) {
            for (int i = 0; i &lt; dt.Columns.Count; i++) {
              if (((string)row[3]).Equals("BASE TABLE")) {
                dumpTable(cn, (string)row[2]);
              }
            }
          }
        }
      }
    }

   static void dumpTable(SqlConnection cn, string tableName) {
     SqlCommand cmd = new SqlCommand(String.Format("SELECT * FROM [{0}]", tableName), cn);

     SqlDataReader sdr = cmd.ExecuteReader();

     if (sdr.HasRows) {
       Console.WriteLine("writing data for table " + tableName);

       using (TextWriter tw = new StreamWriter(String.Format("{0}.sql", tableName))) {
         tw.WriteLine(String.Format("SET IDENTITY_INSERT [{0}] ON", tableName));
         tw.WriteLine("GO\\r\\n");

         StringBuilder sbCols = new StringBuilder();

         for (int i = 0; i &lt; sdr.FieldCount; i++) {
          switch (sdr.GetFieldType(i).ToString()) {
             case "System.Byte[]": {
             } break;
             default: {
              if (sbCols.Length &gt; 0) {
                sbCols.Append(", ");
              }

              sbCols.Append(String.Format("[{0}]", sdr.GetName(i)));
             } break;
          }
         }

         tw.WriteLine();

         while (sdr.Read()) {
           tw.Write(String.Format("INSERT INTO [{0}] ({1}) VALUES (", tableName, sbCols.ToString()));

           for (int i = 0; i &lt; sdr.FieldCount; i++) {
            if (sdr.IsDBNull(i)) {
               if (i &gt; 0) {
                tw.Write(',');
               }

               tw.Write("null");
            } else {
             switch (sdr.GetFieldType(i).ToString()) {
             case "System.Int32": {
               if (i &gt; 0) {
                tw.Write(',');
               }

               tw.Write(sdr[i].ToString());
             } break;

             case "System.Decimal": {
               if (i &gt; 0) {
                tw.Write(',');
               }

               tw.Write(sdr[i].ToString());
             } break;

             case "System.Byte[]": {
             } break;

             case "System.DateTime": {
               if (i &gt; 0) {
                tw.Write(',');
               }

               tw.Write(String.Format("'{0}'", ((DateTime)sdr[i]).ToString("M/d/yyyy h:m:s tt")));
             } break;

             default: {
               if (i &gt; 0) {
                tw.Write(',');
               }

              tw.Write(String.Format("'{0}'", sdr[i].ToString().Replace("\\'", "\\'\\'")));
             } break;
             }
           }
           }

           tw.WriteLine(")\\r\\nGO");
         }

         tw.WriteLine(String.Format("SET IDENTITY_INSERT [{0}] OFF", tableName));
         tw.WriteLine("GO\\r\\n");

         tw.Close();
       }
     }

     sdr.Close();
   }
}
}</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://smeans.com/2008/05/06/windows-hosting-with-godaddy-is-a-royal-pita/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
