<?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>Eric Fickes &#187; mysql</title>
	<atom:link href="http://ericfickes.com/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://ericfickes.com</link>
	<description>Design minded Internet Programmer</description>
	<lastBuildDate>Fri, 28 Oct 2011 04:14:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Use INFORMATION_SCHEMA to find data about your database</title>
		<link>http://ericfickes.com/2011/02/find-out-data-about-your-database-with-system-views/</link>
		<comments>http://ericfickes.com/2011/02/find-out-data-about-your-database-with-system-views/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 21:29:23 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[internets]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[data discovery]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[information_schema]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[rdmbs]]></category>
		<category><![CDATA[schemata]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[sql-92]]></category>
		<category><![CDATA[SQLSERVER]]></category>
		<category><![CDATA[system tables]]></category>
		<category><![CDATA[system views]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=2062</guid>
		<description><![CDATA[Have you ever been in this situation?  You&#8217;re the new developer for a database powered application and you have to figure out what tables contain a specific column?  Or maybe you&#8217;ve got a legacy database that needs it&#8217;s stored procedures &#8230; <a href="http://ericfickes.com/2011/02/find-out-data-about-your-database-with-system-views/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Have you ever been in this situation?  You&#8217;re the new developer for a database powered application and you have to figure out what tables contain a specific column?  Or maybe you&#8217;ve got a legacy database that needs it&#8217;s stored procedures and user defined functions cleaned up?  Or perhaps you&#8217;ve been assigned a unique database inventory task that requires you to report on the structure of your database, rather than the contents of your database.  Besides cracking open your favorite SQL editor and clicking through your database by hand, you might find the data you need from your database&#8217;s INFORMATION_SCHEMA System View.</p>
<p>All of the RDMS systems I&#8217;ve worked with have built in System Views ( or tables ) that contain data about the structure and contents of your database.  These views are there to help you with non data tasks.  For the sake of this post we&#8217;re only going mention the INFORMATION_SCHEMA, which is the system view I use most in SQL Server, and MySQL.  For your reference, here are links to INFORMATION_SCHEMA docs for four popular RDMS systems.</p>
<ol>
<li>SQL Server &#8211; <a title="SQL Server INFORMATION_SCHEMA" href="http://msdn.microsoft.com/en-us/library/ms186778.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms186778.aspx</a></li>
<li>MySQL &#8211; <a title="MySQL INFORMATION_SCHEMA" href="http://dev.mysql.com/doc/refman/5.5/en/information-schema.html" target="_blank">http://dev.mysql.com/doc/refman/5.5/en/information-schema.html</a></li>
<li>Oracle &#8211; <a title="Oracle INFORMATION_SCHEMA" href="http://download.oracle.com/docs/cd/E17952_01/refman-5.0-en/information-schema.html" target="_blank">http://download.oracle.com/docs/cd/E17952_01/refman-5.0-en/information-schema.html</a></li>
<li>DB2 &#8211; <a title="DB2 INFORMATION_SCHEMA" href="http://www.tar.hu/sqlbible/sqlbible0100.html" target="_blank">http://www.tar.hu/sqlbible/sqlbible0100.html</a></li>
</ol>
<p>If you work with SQL Server, you&#8217;ll be happy to know you can see all of the System Views in Management Studio by default.</p>
<div id="attachment_2065" class="wp-caption aligncenter" style="width: 419px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/AdventureWorks-SystemViews.png" rel="lightbox[2062]"><img class="size-full wp-image-2065" title="AdventureWorks-SystemViews" src="http://ericfickes.com/wp-content/uploads/2011/02/AdventureWorks-SystemViews.png" alt="SQL Server Management Studio shows all System Views" width="409" height="461" /></a><p class="wp-caption-text">System Views in the AdventureWorks database</p></div>
<p>If you work with MySQL, you can see the INFORMATION_SCHEMA database in MySQL Workbench, but you&#8217;ll have to enable it in Preferences first.</p>
<div id="attachment_2066" class="wp-caption aligncenter" style="width: 610px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/mysql-ShowMetadataSchemata.png" rel="lightbox[2062]"><img class="size-medium wp-image-2066   " title="mysql-ShowMetadataSchemata" src="http://ericfickes.com/wp-content/uploads/2011/02/mysql-ShowMetadataSchemata-300x146.png" alt="" width="600" height="293" /></a><p class="wp-caption-text">Edit &gt; Preferences &gt; SQL Editor &gt; Check &#39;Show Metadata Schemata&#39;</p></div>
<p>Now for the MySQL users, turning on the Metadata Schemata is <em>not</em> required in order to query those system tables.  Assuming your user has appropriate permissions, you can always fire up Workbench and fire a query like this.</p>
<pre class="brush: sql; title: ; notranslate">
SELECT *
FROM INFORMATION_SCHEMA.Columns
WHERE Column_Name LIKE '%user%'
</pre>
<div id="attachment_2069" class="wp-caption aligncenter" style="width: 432px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/mysql-has-info-schemas.png" rel="lightbox[2062]"><img class="size-full wp-image-2069" title="mysql-has-info-schemas" src="http://ericfickes.com/wp-content/uploads/2011/02/mysql-has-info-schemas.png" alt="" width="422" height="469" /></a><p class="wp-caption-text">MySQL has INFORMATION_SCHEMA tables too!</p></div>
<p>Now that you know about INFORMATION_SCHEMA, you should be happy to know this is part of the SQL-92 standard.  Which means whatever sql scripts you write in MySQL, will most likely work with SQL Server as well.  So go ahead and start querying your database, you&#8217;ll probably find uses for the INFORMATION_SCHEMA in your daily life really quickly.</p>
<p>I&#8217;m going to assume you&#8217;ve got the general idea here, so here are a few sql scripts that I&#8217;ve used over the years.  The first three are informational queries, and the last three are stored procedures that generate .NET or Coldfusion code based off of a table name.</p>
<p><strong>Find all tables with the column EmployeeID</strong></p>
<pre class="brush: sql; title: ; notranslate">
SELECT	*
FROM	INFORMATION_SCHEMA.COLUMNS
WHERE	COLUMN_NAME LIKE 'EmployeeID'
</pre>
<div id="attachment_2072" class="wp-caption aligncenter" style="width: 478px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/1-which-tables-contain-columnName.png" rel="lightbox[2062]"><img class="size-full wp-image-2072" title="1-which-tables-contain-columnName" src="http://ericfickes.com/wp-content/uploads/2011/02/1-which-tables-contain-columnName.png" alt="" width="468" height="236" /></a><p class="wp-caption-text">Which tables have an EmployeeID column?</p></div>
<p><strong>How many tables have the word employee in the name</strong></p>
<pre class="brush: sql; title: ; notranslate">
SELECT	*
FROM	INFORMATION_SCHEMA.TABLES
WHERE	LOWER(TABLE_NAME) LIKE '%employee%'
</pre>
<div id="attachment_2073" class="wp-caption aligncenter" style="width: 483px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/2-which-tables-are-named.png" rel="lightbox[2062]"><img class="size-full wp-image-2073" title="2-which-tables-are-named" src="http://ericfickes.com/wp-content/uploads/2011/02/2-which-tables-are-named.png" alt="" width="473" height="183" /></a><p class="wp-caption-text">How many %employee% tables are in the DB?</p></div>
<p><strong>How many SPROCs and UDFs does our database contain?</strong></p>
<pre class="brush: sql; title: ; notranslate">
SELECT	s.SPROCs, f.UDFs
FROM
(
	SELECT	COUNT(ROUTINE_NAME) AS 'SPROCs', NULL AS 'UDFs'
	FROM	INFORMATION_SCHEMA.ROUTINES
	WHERE	ROUTINE_TYPE = 'PROCEDURE'
) AS s,
(
	SELECT	NULL AS 'SPROCs', COUNT(ROUTINE_NAME) AS 'UDFs'
	FROM	INFORMATION_SCHEMA.ROUTINES
	WHERE	ROUTINE_TYPE = 'FUNCTION'
) AS f
</pre>
<div id="attachment_2076" class="wp-caption aligncenter" style="width: 159px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/3-how-many-sprocs-udfs.png" rel="lightbox[2062]"><img class="size-full wp-image-2076" title="3-how-many-sprocs-udfs" src="http://ericfickes.com/wp-content/uploads/2011/02/3-how-many-sprocs-udfs.png" alt="" width="149" height="65" /></a><p class="wp-caption-text">How many stored procedures and user defined functions are in the DB?</p></div>
<p>The stored procedures listed below all accept an incoming table name, then reads data from INFORMATION_SCHEMA to generate code for the specified database table.  Instead of listing the raw SQL, I&#8217;m just showing a sample result and allowing you to download the raw SQL sprocs.</p>
<p><strong>Generate C# ADO.NET to VO Stored Procedure</strong></p>
<div id="attachment_2077" class="wp-caption aligncenter" style="width: 583px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/4-create-sproc-generateGetTableCode.png" rel="lightbox[2062]"><img class="size-full wp-image-2077" title="4-create-sproc-generateGetTableCode" src="http://ericfickes.com/wp-content/uploads/2011/02/4-create-sproc-generateGetTableCode.png" alt="" width="573" height="458" /></a><p class="wp-caption-text">Build custom C# ADO.NET to custom VO fillerup code</p></div>
<p><a title="Download 'Generate C# ADO.NET to VO' Stored Procedure" href="http://ericfickes.com/code/INFO_SCHEMA/DotNet-generateGetTableCode.sql" target="_blank">download stored procedure</a></p>
<p><a title="Download 'Generate C# ADO.NET to VO' Stored Procedure" href="http://ericfickes.com/code/INFO_SCHEMA/DotNet-generateGetTableCode.sql" target="_blank"></a><br />
<strong>Generate .NET VO class Stored Procedure</strong></p>
<p><a href="http://ericfickes.com/wp-content/uploads/2011/02/5-create-sproc-generateTableVoClass.png" rel="lightbox[2062]"><img class="aligncenter size-full wp-image-2078" title="5-create-sproc-generateTableVoClass" src="http://ericfickes.com/wp-content/uploads/2011/02/5-create-sproc-generateTableVoClass.png" alt="Generate C# VO class for DB table name" width="315" height="454" /></a></p>
<p><a title="Download 'Generate .NET VO class' stored procedure" href="http://ericfickes.com/code/INFO_SCHEMA/DotNet-generateTableVoClass.sql" target="_blank">download stored procedure</a></p>
<p><strong>Generate Coldfusion CFFunction with CFQUERY Stored Procedure</strong></p>
<div id="attachment_2079" class="wp-caption aligncenter" style="width: 502px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/6-create-sproc-MakeSelectFromDbTable.png" rel="lightbox[2062]"><img class="size-full wp-image-2079" title="6-create-sproc-MakeSelectFromDbTable" src="http://ericfickes.com/wp-content/uploads/2011/02/6-create-sproc-MakeSelectFromDbTable.png" alt="" width="492" height="276" /></a><p class="wp-caption-text">Generate Coldfusion CFFunction with CFQUERY for specified table name</p></div>
<p><a title="Download 'Generate Coldfusion CFFunction with CFQUERY' stored procedure" href="http://ericfickes.com/code/INFO_SCHEMA/Coldfusion-MakeSelectFromDbTable.sql" target="_blank">download stored procedure</a></p>
<p>I use these System Views almost daily, and there are a lot of scenarios where my job would take a lot longer to do if I didn&#8217;t know about this information.  The INFORMATION_SCHEMA also feeds my passion to build code that makes code, just love it.  Hopefully this nickel tour was enough information to help somebody out.</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2011/02/find-out-data-about-your-database-with-system-views/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://ericfickes.com/code/INFO_SCHEMA/DotNet-generateGetTableCode.sql" length="17232" type="audio/mpeg" />
		</item>
		<item>
		<title>Eleven Coldfusion-ish tips from the field</title>
		<link>http://ericfickes.com/2011/02/eleven-coldfusion-ish-tips-from-the-field/</link>
		<comments>http://ericfickes.com/2011/02/eleven-coldfusion-ish-tips-from-the-field/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 08:34:49 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[adobe]]></category>
		<category><![CDATA[coldfusion]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[asc]]></category>
		<category><![CDATA[cfml]]></category>
		<category><![CDATA[cfscript]]></category>
		<category><![CDATA[chr]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[listcontains]]></category>
		<category><![CDATA[listfind]]></category>
		<category><![CDATA[listhasvalue]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[parameterized query]]></category>
		<category><![CDATA[special character]]></category>
		<category><![CDATA[sproc]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[stored procedure]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1965</guid>
		<description><![CDATA[I&#8217;ve had this running list of Coldfusion tips on my wall for the last few years and it&#8217;s time to get these online.  All of the items in this list came from Coldfusion projects over the last few years, but &#8230; <a href="http://ericfickes.com/2011/02/eleven-coldfusion-ish-tips-from-the-field/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had this running list of Coldfusion tips on my wall for the last few years and it&#8217;s time to get these online.  All of the items in this list came from Coldfusion projects over the last few years, but a good portion of these could easily be considered tips for server programmers.  I definitely run into the same items when programming Asp.NET.</p>
<p>There is no rhyme or reason here, just some things I felt need to be repeated.</p>
<h2>1. <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_m-r_14.html" target="_blank">PreserveSingleQuotes</a>()</h2>
<p>This one came in really handy on a project requiring large text files to be imported into a MySQL database.  I used Coldfusion to upload and read the files into large INSERT chunks using <a href="http://dev.mysql.com/doc/refman/5.5/en/insert.html" target="_blank">MySQL&#8217;s multi &#8211; row INSERT syntax</a>. Code built the VALUES portion of the SQL, then I just fed the data into a function for insertion.</p>
<pre class="brush: sql; title: ; notranslate">
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
</pre>
<pre class="brush: coldfusion; title: ; notranslate">
	&lt;cfquery name=&quot;insert_data&quot; result=&quot;insert_result&quot; DATASOURCE=&quot;#request.dsn#&quot; USERNAME=&quot;#request.dbuser#&quot; PASSWORD=&quot;#request.dbpswd#&quot;&gt;
	INSERT INTO table
	( column1, column2, column3, column4, column5, column6, column7 )
	VALUES
	#PreserveSingleQuotes( insert_values )#
	&lt;/cfquery&gt;
</pre>
<h2>2. What if GENERATED_KEY doesn&#8217;t work?</h2>
<p>If you&#8217;re using MySQL and the GENERATED_KEY property of your cfquery objects isn&#8217;t populating, you can use <a href="http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_last-insert-id" target="_blank">LAST_INSERT_ID</a> instead.</p>
<pre class="brush: sql; title: ; notranslate">SELECT LAST_INSERT_ID();</pre>
<h2>3. Use ArrayAppend when building strings</h2>
<p>Classic performance tuning tip for just about any programming language.  Here I&#8217;ll give a Coldfusion example and keep it dead simple.  If you ever have to concatenate strings in code, user ArrayAppend instead.  Here are two loops that do the same thing.  If you run this code, you should notice loop1 takes forever, and loop2 is smoking fast.</p>
<p><strong>slow&#8230;..</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfscript&gt;
xx				= 100000;
insertString	= &quot;&quot;;

// do the loop
while( xx &gt; 0 ) {
	insertString &amp;= xx &amp; &quot; &quot;;
	xx--;
}

WriteOutput( insertString);
&lt;/cfscript&gt;
</pre>
<p><strong>FAST!</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfscript&gt;
xx				= 1000000;
insertArray		= ArrayNew(1);
// do the loop
while( xx &gt; 0 ) {
	ArrayAppend( insertArray, xx &amp; &quot; &quot; );
	xx--;
}

WriteOutput( ArrayToList( insertArray, &quot; &quot; ) );
ArrayClear( insertArray );
&lt;/cfscript&gt;
</pre>
<h2>4. If CSV, then CHR</h2>
<p>This one is simple, if you find yourself creating CSV or any other text file, use special characters when dealing with single and double quotes, etc.</p>
<ul>
<li>chr(9) = Tab</li>
<li>chr(34) = &#8221; double quote</li>
<li>chr(39) = &#8216; single quote</li>
</ul>
<p>And if you&#8217;re not sure of the correct code for the character you&#8217;re looking to use, just wrap that character in <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_a-b_25.html" target="_blank">ASC()</a> and <a href="http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ecf.html" target="_blank">WriteOutput</a> to the page.</p>
<h2>5. Use CFMail with GMail</h2>
<p>This is a no brainer, but with how difficult sending email can be with <em><a title="I love .NET, but it's a pain in the butt sometimes" href="http://www.google.com/search?sourceid=chrome&amp;ie=UTF-8&amp;q=send+email+with+ASP.NET" target="_blank">other languages</a></em>, I&#8217;m mentioning it here.</p>
<p><strong>Application.cfc</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfscript&gt;
	APPLICATION.mail.server		= &quot;smtp.gmail.com&quot;;
	APPLICATION.mail.port		= &quot;465&quot;;
	APPLICATION.mail.ssl		= true;
	APPLICATION.mail.user		= &quot;gmailAccount&quot;;
	APPLICATION.mail.pswd		= &quot;gmailPasssword&quot;;
&lt;/cfscript&gt;
</pre>
<p><strong>Emailer.cfm</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfmail to=&quot;work@ericfickes.com&quot;
		bcc=&quot;&quot;
		from=&quot;web@master.com&quot;
		subject=&quot;sending mail is easy with Coldfusion&quot;
		server=&quot;#application.mail.server#&quot;
		useSSL=&quot;#application.mail.ssl#&quot;
		port=&quot;#application.mail.port#&quot;
		username=&quot;#application.mail.user#&quot;
		password=&quot;#application.mail.pswd#&quot;&gt;
#emailBody#
&lt;/cfmail&gt;
</pre>
<h2>6. CFSCRIPT doesn&#8217;t know NULL?</h2>
<p>Another tip from the land of importing and exporting data.  While working with query objects in CFScript, for some reason I could never accurately detect for NULL values.  I tried all sorts of detection schemes and ended up just writing a hacky fail safe.  Please, if you have a better suggestion for *easy* NULL detection in CFSCript, add it in the comments below.</p>
<p><strong>utils.cfc</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;!---  Simple value getter with try / catch to get around NULL values
This function originated in a script where we always needed a &quot; &quot; even if
the value from the database was null.
---&gt;
&lt;cffunction name=&quot;qryGetString&quot; access=&quot;public&quot; returntype=&quot;string&quot;&gt;

&lt;cfargument name=&quot;data&quot; type=&quot;string&quot;&gt;

&lt;cftry&gt;
	&lt;cfscript&gt;
	return #data# &amp; &quot; &quot;;
	&lt;/cfscript&gt;

	&lt;cfcatch type=&quot;Any&quot;&gt;
		&lt;cfreturn &quot; &quot;/&gt;
	&lt;/cfcatch&gt;
&lt;/cftry&gt;

&lt;/cffunction&gt;
</pre>
<p><strong>Exporter.cfm</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
// largeish loop
tab = chr(9);
for( xx = 1; xx &lt;= queryObj.RecordCount; xx++ )
{
	// start the row
	this_row = 	utils_cfc.qryGetString( queryObj.FirstName[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.MiddleName[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.LastName[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.Suffix[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.MedicalTitle[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.email[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_phone[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_fax[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_name[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_address1[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_address2[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_city[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_state[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.practice_zipcode[xx] ) &amp; tab &amp;
			utils_cfc.qryGetString( queryObj.hospital_affiliation[xx] ) &amp; tab;

	// do stuff with the data
}
</pre>
<h2>7. How I find list items</h2>
<h2><span style="font-size: 16px; color: #444444; line-height: 24px;">Ever notice the different behavior in the Coldfusion ListFind commands?  I ended up writing my own ListHasValue function in order to find exact pattern matching in a list.  I had a list of role ids in a list, and just couldn&#8217;t get the built in functions to tell me when my id was in the list without also matching on other ids.  This one makes sense when you run some code.</span></h2>
<p>The top of this sample as my custom ListHasValue() command, and the lower half does three simple loops counting from 1 to 100, and using ListFind, ListContains, and ListHasValue for number checking against the same list.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;!---
	Use this to do an exact pattern check for a value in a list.
	This is useful inside of a loop checking numbers against a number list.

	EX :

	list = &quot;91, 92&quot;

	if you loop from 1 - 100, ListFind and related CF functions will match
	on 1, 2, and 9.  Not just 91 and 92

	Use this when you're looping and you ONLY want to match on 91, or 92

---&gt;
&lt;cffunction name=&quot;ListHasValue&quot; access=&quot;public&quot; returntype=&quot;boolean&quot;&gt;

	&lt;cfargument name=&quot;list&quot; required=&quot;yes&quot; type=&quot;string&quot;&gt;
	&lt;cfargument name=&quot;value&quot; required=&quot;yes&quot; type=&quot;any&quot;&gt;

	&lt;cfscript&gt;
		// clean up to be safe
		list = trim( toString( list ) );

		// check to see if we have a *possible* match
		position = ListContains( list, value ) ;

		if( position &gt; 0 )
		{
			// NOTE : KEEP THE TRIM AND TOSTRING
			found_value = trim( toString( ListGetAt( list, position ) ) );

			if( Compare( value, found_value ) == 0 )
			{
				return true;
			}
		}

		// no match for you!
		return false;
	&lt;/cfscript&gt;

&lt;/cffunction&gt;

&lt;cfscript&gt;
list	= &quot;1, 11, 21, 31, 41, 51, 61, 71, 81, 91, 99&quot;;
xx		= 1;

WriteOutput( &quot;List = &quot; &amp; list &amp; &quot;&lt;hr&gt;&quot;);

while( xx &lt; 100 ) {
	if( ListContains( list, xx ) &gt; 0 )
	{
		WriteOutput( &quot;ListContains found &quot; &amp; xx &amp; &quot;&lt;br&gt;&quot; );
	}
    xx++;
}

WriteOutput(&quot;&lt;hr /&gt;&quot;);

xx = 1;
while( xx &lt; 100 ) {
	// ListFind
	if( ListFind( list, xx ) &gt; 0 )
	{
		WriteOutput( &quot;ListFind found &quot; &amp; xx &amp; &quot;&lt;br&gt;&quot; );
	}
    xx++;
}

WriteOutput(&quot;&lt;hr /&gt;&quot;);

xx = 1;
while( xx &lt; 100 ) {
    // Eric's ListHasValue
	if( ListHasValue( list, xx ) )
	{
		WriteOutput( &quot;ListHasValue found &quot; &amp; xx &amp; &quot;&lt;br&gt;&quot; );
	}
	xx++;
}
&lt;/cfscript&gt;
</pre>
<p>If you run this code on your Coldfusion server, you should notice the following results.  ListContains matches single digits from the loop that do not really exist in the list.  ListFind only finds the number 1?  And finally, my function does exactly what I needed it to do.  Tell me when a specific number exists in a list.</p>
<div id="attachment_1980" class="wp-caption alignnone" style="width: 240px"><a href="http://ericfickes.com/wp-content/uploads/2011/02/cf-list-find1.png" rel="lightbox[1965]"><img class="size-full wp-image-1980" title="cf-list-find" src="http://ericfickes.com/wp-content/uploads/2011/02/cf-list-find1.png" alt="CF ListFind function comparison" width="230" height="559" /></a><p class="wp-caption-text">Coldfusion ListFind functions don&#39;t always behave how I want them to</p></div>
<p><span style="font-size: 16px; color: #444444; line-height: 24px;"><br />
</span></p>
<h2>8. Make PDFs faster</h2>
<p>This could easily be it&#8217;s own topic, but I&#8217;ll say one thing about making PDFs faster with CFDocument.  Only put final content between &lt;cfdocument&gt; and &lt;/cfdocument&gt;.  That is, if you have any processing code, cfqueries, cfloops, inside of your cfdocument tag, your cfml page is running slower than it needs to be.  Here&#8217;s a simple example of one of my cfml pages that has only final content in the cfdocument tags.</p>
<p>The key to this example is moving all of my content creation code into an external file, then including at the top of my page. I always do a check for my main PDF_BODY variable, and then spit out my PDF document.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfinclude template=&quot;code/export_pdf_codefile.cfm&quot;&gt;

&lt;cfif PDF_BODY NEQ &quot;&quot;&gt;

    &lt;cfdocument	name=&quot;provider_profile&quot;
                format=&quot;PDF&quot;
                pagetype=&quot;A4&quot;
                mimetype=&quot;application/pdf&quot;
                orientation=&quot;portrait&quot;
                margintop=&quot;0&quot;
                marginbottom=&quot;0.2&quot;
                marginleft=&quot;0.2&quot;
                marginright=&quot;0.2&quot;
                &gt;
        &lt;cfoutput&gt;#PDF_BODY#&lt;/cfoutput&gt;
    &lt;/cfdocument&gt;

    &lt;!--- send directly to client ---&gt;
    &lt;cfheader name=&quot;Content-Disposition&quot; value=&quot;attachment; filename=#filename#&quot;&gt;
    &lt;cfcontent type=&quot;application/pdf&quot; variable=&quot;#provider_profile#&quot;&gt;

&lt;cfelse&gt;
	No PDF content found
&lt;/cfif&gt;
</pre>
<h2>9. Use parameterized queries</h2>
<p>This is a tip for all server side programmers whether you use Coldfusion, ASP, JSP, PBJ.  Use parameterized queries when doing any database interaction.  It&#8217;s too easy not to use, and you get protection from SQL Injection, as well as enforcing proper data types when speaking to your database.  This is something all server programmers should do regardless of your language, the sample below is for Coldfusion.</p>
<p><strong>BAD</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfquery name=&quot;tblInsert&quot; datasource=&quot;myDb&quot;&gt;
INSERT INTO	myTable
( col1, col2, col3, col4 )
VALUES
( '#Form.field1#', '#Form.field2#', '#Form.field3#' )
&lt;/cfquery&gt;
</pre>
<p><strong>GOOD</strong></p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfset val1 = Form.field1&gt;
&lt;cfset val2 = Form.field1&gt;
&lt;cfset val3 = Form.field1&gt;

&lt;cfquery name=&quot;tblInsert&quot; datasource=&quot;myDb&quot;&gt;
INSERT INTO	myTable
( col1, col2, col3, col4 )
VALUES
(
    &lt;cfqueryparam cfsqltype=&quot;cf_sql_varchar&quot; value=&quot;#val1#&quot; /&gt;,
    &lt;cfqueryparam cfsqltype=&quot;cf_sql_varchar&quot; value=&quot;#val2#&quot; /&gt;,
    &lt;cfqueryparam cfsqltype=&quot;cf_sql_varchar&quot; value=&quot;#val3#&quot; /&gt;
)
&lt;/cfquery&gt;
</pre>
<h2>10. Where&#8217;d the time go?</h2>
<p>For the good programmers already using parameterized queries, ever insert a timestamp into your database and find out the date is correct, but the time is always 12:00:00?  Take a closer look at the cfsqltype in your cfqueryparam, I had this exact problem and here&#8217;s what happened.</p>
<p>Using <strong>cf_sql_date does</strong> not include the full date and timestamp, just the date.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfqueryparam cfsqltype=&quot;cf_sql_date&quot; value=&quot;#paymentDate#&quot; /&gt;
</pre>
<p>&nbsp;</p>
<p>Using <strong>cf_sql_timestamp</strong> includes the full date and timestamp I was looking for.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfqueryparam cfsqltype=&quot;cf_sql_timestamp&quot; value=&quot;#paymentDate#&quot; /&gt;
</pre>
<h2>11. Stored Procedures are a little different</h2>
<p>This last one isn&#8217;t much of a tip, but more of a reminder to myself.  I do so much database work that stored procedures are just queries to me, but not so to Coldfusion and the CFQuery tag.  If you want to get data from a stored procedure, you need to use the <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_r-s_22.html" target="_blank">CFStoredproc</a> tag.  Here&#8217;s a sample of passing one argument into a stored procedure, and how to get the resulting data.</p>
<pre class="brush: coldfusion; title: ; notranslate">
&lt;cfstoredproc	datasource=&quot;myDb&quot; procedure=&quot;GetDataFaster&quot;&gt;

	&lt;cfprocparam type=&quot;in&quot; cfsqltype=&quot;cf_sql_integer&quot; value=&quot;#inputVar#&quot; /&gt;

	&lt;!--- specify sproc result here, cfstoredproc res != returned recordset ---&gt;
	&lt;cfprocresult name = sprocResult&gt;

&lt;/cfstoredproc&gt;

&lt;cfreturn #sprocResult.ColumnFromQuery#&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2011/02/eleven-coldfusion-ish-tips-from-the-field/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Invalid token &#8216;void&#8217; in class, struct, or interface member declaration</title>
		<link>http://ericfickes.com/2010/02/invalid-token-void-in-class-struct-or-interface-member-declaration/</link>
		<comments>http://ericfickes.com/2010/02/invalid-token-void-in-class-struct-or-interface-member-declaration/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 23:32:34 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[ADO.NET Entity Data Model]]></category>
		<category><![CDATA[edmx]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[visual studio 2008]]></category>
		<category><![CDATA[void]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=1041</guid>
		<description><![CDATA[EDIT : After finishing this post I ran into all sorts of other strange issues and restarted using a Web Appliction instead of a plain old Website.  Between IntelliSense not showing any classes, to project reference issues, I couldn&#8217;t figured it &#8230; <a href="http://ericfickes.com/2010/02/invalid-token-void-in-class-struct-or-interface-member-declaration/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>EDIT :</h2>
<p>After finishing this post I ran into all sorts of other strange issues and restarted using a Web Appliction instead of a plain old Website.  Between <a title="IntelliSense is the BEST feature of all Visual Studios" href="http://en.wikipedia.org/wiki/IntelliSense" target="_blank">IntelliSense</a> not showing any classes, to project reference issues, I couldn&#8217;t figured it out in time.  I&#8217;m sure there&#8217;s a way, I just had to move on.  So maybe this ramble below will be helpful for someone.</p>
<address>EF</address>
<p>Just ran into something quirky with Visual Studio 2008&#8242;s new ADO.NET Entity Data Model wizard.  While working on an ASP.NET 3.5 website ( not a codebehind web application ) I was trying to get the ADO.NET Entity Data model wizard to work with MySQL and ran into a probable Visual Studio bug.  To sum up the issue, if you are going to add a new edmx to your project, do NOT save it to the App_Code folder initially.  Put it in your root folder, compile your project, then move the edmx where you&#8217;d like.</p>
<p>Assuming you&#8217;ve already created your ASP.NET Website project, here&#8217;s how you reproduce this issue.</p>
<h3 style="text-align: center;"><strong>Right click your project and left click &#8216;Add New Item&#8217;</strong></h3>
<p style="text-align: center;">
<div id="attachment_1042" class="wp-caption aligncenter" style="width: 390px"><a href="http://ericfickes.com/wp-content/uploads/2010/02/vs1-AddNewItem.png" rel="lightbox[1041]"><img class="size-full wp-image-1042" title="Add New Item" src="http://ericfickes.com/wp-content/uploads/2010/02/vs1-AddNewItem.png" alt="Right click your project, left click Add New Item" width="380" height="225" /></a><p class="wp-caption-text">Add New Item</p></div>
<h3 style="text-align: center;"><strong>Select ADO.NET Entity Data Model, name it, select your language of preference</strong></h3>
<p style="text-align: center;">
<div id="attachment_1045" class="wp-caption aligncenter" style="width: 372px"><a href="http://ericfickes.com/wp-content/uploads/2010/02/vs2-NewEDM1.png" rel="lightbox[1041]"><img class="size-full wp-image-1045" title="New ADO.NET Entity Data Model" src="http://ericfickes.com/wp-content/uploads/2010/02/vs2-NewEDM1.png" alt="New ADO.NET Entity Data Model" width="362" height="466" /></a><p class="wp-caption-text">ADO.NET Entity Data Model</p></div>
<h3 style="text-align: center;"><strong>Click Yes to the &#8216;Store in App_Code&#8217; prompt</strong></h3>
<p style="text-align: center;"><strong> </strong></p>
<div id="attachment_1046" class="wp-caption aligncenter" style="width: 500px"><strong><strong><a href="http://ericfickes.com/wp-content/uploads/2010/02/vs3-AddToAPP_CODE.png" rel="lightbox[1041]"><img class="size-full wp-image-1046" title="Place your edmx in App_Code folder" src="http://ericfickes.com/wp-content/uploads/2010/02/vs3-AddToAPP_CODE.png" alt="Place your edmx in App_Code folder" width="490" height="199" /></a></strong></strong><p class="wp-caption-text">Place file in &#39;App_Code&#39; folder</p></div>
<p><strong> </strong></p>
<h3 style="text-align: center;"><strong>Complete the new Entity Data Model wizard</strong></h3>
<p style="text-align: center;"><a title="ADO.NET DataEntities and WCF Feeding a Silverlight DataGrid" href="http://silverlight.net/learn/tutorials/adonetdataentities-cs/" target="_blank">See this tutorial if you have not done this before</a></p>
<p style="text-align: center;">
<p style="text-align: center;">
<h3 style="text-align: center;"><strong>Compile project after completing wizard</strong></h3>
<p style="text-align: left;">
<div id="attachment_1047" class="wp-caption aligncenter" style="width: 665px"><a href="http://ericfickes.com/wp-content/uploads/2010/02/vs4-BuildFail.png" rel="lightbox[1041]"><img class="size-full wp-image-1047" title="Invalid token 'void' in class, struct, or interface member declaration" src="http://ericfickes.com/wp-content/uploads/2010/02/vs4-BuildFail.png" alt="Invalid token 'void' in class, struct, or interface member declaration" width="655" height="399" /></a><p class="wp-caption-text">Invalid token &#39;void&#39; in class, struct, or interface member declaration</p></div>
<p style="text-align: left;">At this point your project should have a new.edmx file located inside of the App_Code folder, but the project won&#8217;t build without failing.  If you are stuck in this predicament, follow this workaround.</p>
<h3 style="text-align: center;"><strong>Move .edmx to root folder and rebuild</strong></h3>
<p style="text-align: left;"><strong> </strong></p>
<div id="attachment_1048" class="wp-caption aligncenter" style="width: 346px"><strong><strong><a href="http://ericfickes.com/wp-content/uploads/2010/02/vs5-move_edmx.png" rel="lightbox[1041]"><img class="size-full wp-image-1048" title="Move edmx to root and recompile, no errors!" src="http://ericfickes.com/wp-content/uploads/2010/02/vs5-move_edmx.png" alt="Move edmx to root and recompile, no errors!" width="336" height="468" /></a></strong></strong><p class="wp-caption-text">WORKAROUND : move edmx to root folder, then recompile</p></div>
<p><strong> </strong></p>
<p style="text-align: left;">
<p style="text-align: left;">After moving your edmx file to the root folder you should be able to compile without problem.  Assuming this solves your problem, you should be able to move your edmx file to the App_Code folder without problem.  Seems like an initial compile problem<strong>.<br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2010/02/invalid-token-void-in-class-struct-or-interface-member-declaration/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Copy a MySQL database to your local MySQL machine</title>
		<link>http://ericfickes.com/2008/12/copy-a-mysql-database-to-your-local-mysql-machine/</link>
		<comments>http://ericfickes.com/2008/12/copy-a-mysql-database-to-your-local-mysql-machine/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 03:43:04 +0000</pubDate>
		<dc:creator>Eric Fickes</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tips and tricks]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[copy database]]></category>
		<category><![CDATA[dump file]]></category>
		<category><![CDATA[export database]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[import database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql5]]></category>
		<category><![CDATA[phpMyAdmin]]></category>

		<guid isPermaLink="false">http://ericfickes.com/?p=343</guid>
		<description><![CDATA[Here&#8217;s one way to copy a MySQL database from one server to another using phpMyAdmin, and the MySQL command line client. Requirements : MySQL 5.x installed on your local machine MySQL command line client on your local machine Access to &#8230; <a href="http://ericfickes.com/2008/12/copy-a-mysql-database-to-your-local-mysql-machine/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s one way to copy a MySQL database from one server to another using phpMyAdmin, and the MySQL command line client.</p>
<p><strong>Requirements :</strong></p>
<ul>
<li>MySQL 5.x installed on your local machine</li>
<li>MySQL command line client on your local machine</li>
<li>Access to phpMyAdmin on your source MySQL machine</li>
</ul>
<p><strong>Assumptions:</strong></p>
<ul>
<li>You have access to the MySQL command line client.</li>
<li>You have the root password for your local MySQL instance</li>
<li>You are comfortable using phpMyAdmin and MySQL command line client</li>
</ul>
<p><strong>Instructions:</strong></p>
<ol>
<li>Log into phpMyAdmin on your source MySQL machine.</li>
<li>Click the Export link on the lower part of the home page.</li>
<li>Select your database in the &#8216;Export&#8217; box on the left.</li>
<li>Make sure SQL is selected under the database box.</li>
<li>In the &#8216;Options&#8217; box on the right, make sure Structure and Data are selected.</li>
<li>Make sure to check &#8216;Add DROP TABLE / DROP VIEW&#8217; as well.</li>
<li>Towards the bottom, check the box next to &#8216;Save as file&#8217;.  This will be the file we import later.</li>
<li>Click the GO button, and your browser should prompt you to download your SQL file.  *Make note of where you saved your exported sql file.  I saved mine to d:\downloads\import.sql because it&#8217;s an easy path to use later.</li>
<li>Open your local MySQL Command Line Client.  ( From MySql Program menu or type &#8220;<strong>mysql -u root -p</strong>&#8221; in the run dialog box ).</li>
<li>Enter your root password when prompted.</li>
<li>Import your database by running this command &#8220;<strong>mysql \. d:\downloads\import.sql</strong>&#8220;.  Be sure to adjust the path to match where you saved your sql file from step 8.</li>
<li>Now you should see your database listed when you run the command &#8220;<strong>show databases;</strong>&#8220;</li>
</ol>
<p> </p>
<p>Here are instructions for doing the same thing on OS X</p>
<ol>
<li>Follow steps 1 through 8 above to created your sql export file</li>
<li>Connect to mysql &#8220;/usr/local/mysql/bin/mysql -u root -p&#8221;</li>
<li>{enter root password}</li>
<li>If it&#8217;s not already created, created your databse &#8220;create database {your db name};&#8221;</li>
<li>Select your database &#8220;user {your db name};&#8221;</li>
<li>&#8220;mysql \. /users/ericfickes/Downloads/mydbfile.sql&#8221;</li>
</ol>
<p>Be sure to adjust the paths listed to match your MySQL install, and the location where you downloaded the sql file.</p>
]]></content:encoded>
			<wfw:commentRss>http://ericfickes.com/2008/12/copy-a-mysql-database-to-your-local-mysql-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

