<?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>Coding Friends &#187; Windows</title>
	<atom:link href="http://www.codingfriends.com/index.php/tag/windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingfriends.com</link>
	<description>Coding Friends, place for developers.</description>
	<lastBuildDate>Mon, 06 Sep 2010 20:18:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Linux file structure &#8211; comparsion with Windows</title>
		<link>http://www.codingfriends.com/index.php/2010/02/07/linux-file-structure-comparsion-with-windows/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=linux-file-structure-comparsion-with-windows</link>
		<comments>http://www.codingfriends.com/index.php/2010/02/07/linux-file-structure-comparsion-with-windows/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 13:51:30 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[comparsion]]></category>
		<category><![CDATA[directory structure]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=659</guid>
		<description><![CDATA[Here is the Linux file structure from the root, which some explanations. The main explanation for the /bin, /boot /lib are the basic files that are required on boot up that the kernel needs to &#8220;run&#8221; as such. The files within the /usr are the files that user programs use e.g. games. Anyway here is [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the Linux file structure from the root, which some explanations.   The main explanation for the /bin, /boot /lib are the basic files that are required on boot up that the kernel needs to &#8220;run&#8221; as such.  The files within the /usr are the files that user programs use e.g. games.</p>
<p>Anyway here is a list of directories on my linux setup.</p>
<table>
<tr>
<td width="15%">bin</td>
<td>binary files for boot up e.g. mount e.g. </td>
</tr>
<tr>
<td>boot</td>
<td>boot files &#8211; kernel images etc.</td>
</tr>
<tr>
<td>dev</td>
<td>devices on the computer.</td>
</tr>
<tr>
<td>etc</td>
<td>configuration files for the programs</td>
</tr>
<tr>
<td>home</td>
<td>home users, e.g. your name /home/ian</td>
</tr>
<tr>
<td>lib</td>
<td>libraries </td>
</tr>
<tr>
<td>lib32</td>
<td>libraries for the 32bit programs</td>
</tr>
<tr>
<td>lib64</td>
<td>/lib	(link to the libraries since I am using the 64 linux version)</td>
</tr>
<tr>
<td>lost+found</td>
<td></td>
</tr>
<tr>
<td>media</td>
<td>media that is going to be mounted (cd-rom&#8217;s)</td>
</tr>
<tr>
<td>mnt</td>
<td>media that is going to be mounted (Hard drives etc)</td>
</tr>
<tr>
<td>opt</td>
<td>opitional programs e.g. things like google chrome, they are normally place in here is not distro specific.</td>
</tr>
<tr>
<td>proc</td>
<td>processes that are happening on the computer, all process you can &#8220;talk&#8221; to </td>
</tr>
<tr>
<td>root</td>
<td>root home files.</td>
</tr>
<tr>
<td>sbin</td>
<td>sbin, booted up at initial stage of the boot process, things like modprobe for setting up systems items.</td>
</tr>
<tr>
<td>sys</td>
<td>system image of devices attached and also file systems that are loadable.</td>
</tr>
<tr>
<td>tmp</td>
<td>tempoary files.</td>
</tr>
<tr>
<td>usr</td>
<td>user files, e.g. games, libraries, binary files<br />
		  bin  games  include  lib  lib32  lib64  local  sbin  share  src<br />
		  it has its own includes, libraries, sbin and bin directories for all of the files within that user directory.</td>
</tr>
<tr>
<td>var</td>
<td>variable files, e.g. logs, apache www hosting files.</td>
</tr>
</table>
<p>The Windows equivalent would be that most of the / (root) directory is within the c:/windows directory, apart from the /home which is the c:/Users or c:/Documents depending on your Windows version.</p>
<table>
<tr>
<td width="15%">bin</td>
<td>/Windows /Windows/System32 /Windows/System</td>
</tr>
<tr>
<td>boot</td>
<td>boot.ini file that points to what to do.</td>
</tr>
<tr>
<td>dev</td>
<td>Does not appear to have something similar on the file system</td>
</tr>
<tr>
<td>etc</td>
<td>/Program Data (depending on Windows versions)</td>
</tr>
<tr>
<td>home</td>
<td>/Users</td>
</tr>
<tr>
<td>lib</td>
<td>/Windows /Windows/System32 /Windows/System /Windows/.Net (for .Net stuff) etc.</td>
</tr>
<tr>
<td>lib32</td>
<td></td>
</tr>
<tr>
<td>media</td>
<td>Does not appear to have a link to the different mount points but display them on the windows explorer</td>
</tr>
<tr>
<td>mnt</td>
<td>Does not appear to have a link to the different mount points but display them on the windows explorer</td>
</tr>
<tr>
<td>opt</td>
<td>/Program files/</td>
</tr>
<tr>
<td>proc</td>
<td>Does not appear to have a list of running process on the file system, but you can view them with pslist pskill</td>
</tr>
<tr>
<td>root</td>
<td>/Documents/Admin user account</td>
</tr>
<tr>
<td>sbin</td>
<td>/Windows</td>
</tr>
<tr>
<td>sys</td>
<td>Does not appear to have a list of devices attached</td>
</tr>
<tr>
<td>tmp</td>
<td>/tmp</td>
</tr>
<tr>
<td>usr</td>
<td>/Program files/</td>
</tr>
<tr>
<td>var</td>
<td>/Program files/ or where ever you want them.</td>
</tr>
</table>
<p>That kinder helps me to understand that there is more details on the command line, directory structure to actual processes and devices attached than Windows, well of course there is the regviewer that can display options like the /etc in the linux but nothing as structured, things just across like a mess (to me anyway).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/02/07/linux-file-structure-comparsion-with-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SugarCRM hook &#8211; what are they</title>
		<link>http://www.codingfriends.com/index.php/2009/09/07/sugarcrm-hook-what-are-they/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sugarcrm-hook-what-are-they</link>
		<comments>http://www.codingfriends.com/index.php/2009/09/07/sugarcrm-hook-what-are-they/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 11:32:13 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SugarCRM]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=378</guid>
		<description><![CDATA[SugarCRM is a very nice and open source CRM (Customer relationship management) system. And with being open source means that you are able to alter the internals of it and also are able to write modules for it easier than closed source applications because you can follow the direction of things if you are for [...]]]></description>
			<content:encoded><![CDATA[<p>SugarCRM is a very nice and open source CRM (Customer relationship management) system.  And with being open source means that you are able to alter the internals of it and also are able to write modules for it easier than closed source applications because you can follow the direction of things if you are for example debugging etc.</p>
<p>The hooks part of the sugarCRM setup allows to place your own code into the base code at set parts of execution e.g. after retrieve of data, or post processing of data updates.</p>
<p>Here is a link to the sugarcrm site of <a href="http://developers.sugarcrm.com/docs/OS/5.2/-docs-Developer_Guides-Developer_Guide_5.2-DevGuide%205.2.1.47.html#9002554">hooks</a> definitions.  Basically there is 3 main types, with subhooks attached to those types.</p>
<ul>
<li>Application hooks</li>
<ul>
<li>after_ui_frame &#8211; Fired after the frame has been invoked and before the footer has been invoked</li>
<li>after_ui_footer &#8211; Fired after the footer has been invoked</li>
<li>server_round_trip &#8211; Fired at the end of every SugarCRM page</li>
</ul>
<li>Module hooks</li>
<ul>
<li>before_delete &#8211; Fired before a record is deleted</li>
<li>after_delete &#8211; Fired after a record is deleted</li>
<li>before_restore &#8211; Fired before a record is undeleted</li>
<li>after_restore &#8211; Fired after a record is undeleted</li>
<li>after_retrieve &#8211; Fired after a record has been retrieved from the database. This hook does not fire when you create a new record.</li>
<li>before_save &#8211; Fired before a record is saved.</li>
<li>after_save &#8211; Fired after a record is saved.</li>
<li>process_record  &#8211; Fired immediately prior to the database query resulting in a record being made current. This gives developers an opportunity to examine and tailor the underlying queries. This is also a perfect place to set values in a record’s fields prior to display in the DetailView or ListView. This event is not fired in the EditView.</li>
</ul>
<li>Users</li>
<ul>
<li>before_logout &#8211; Fired before a user logs out of the system</li>
<li>after_logout &#8211; Fired after a user logs out of the system</li>
<li>after_login &#8211; Fired after a user logs into the system.</li>
<li>after_logout &#8211; Fired after a user logs out of the system.</li>
<li>before_logout &#8211; Fired before a user logs out of the system.</li>
<li>login_failed &#8211; Fired on a failed login attempt</li>
</ul>
</ul>
<p>What I have done below is to use a module hook for the after_retrieve method.</p>
<p>If you save this</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$hook_version</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$hook_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$hook_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'after_retrieve'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$hook_array</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'after_retrieve'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'after_retrieve'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'custom/modules/Users/users_after_retrieve.php'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'users_after_retrieve_class'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'users_after_retrieve_method'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>In the <basefolder>/custom/modules/Users directory and call it hooks.php</p>
<p>The hook array denotes the hooks to add into the module execution and you first create a array and then another array for the &#8216;after_retrieve&#8217; functions to be called.   The third array structure is version, event, php file, class name, method to call.</p>
<p>And here is the php file for the above hook, called users_after_retrieve.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> users_after_retrieve_class
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> users_after_retrieve_method<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$bean</span><span style="color: #339933;">,</span> <span style="color: #000088;">$event</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arguments</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// 		print_r($bean);  // to get the full details of the bean</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// make sure we are doing a after_retrieve event</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$event</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'after_retrieve'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$bean</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">description</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;The best thing in the world is being a dad, it really is&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The output of this, you will have to goto the Users in the Admin area <baseurl>/index.php?module=Users&#038;action=index and then select the user and in the User Information field there is now the message &#8220;The best thing in the world is being a dad, it really is&#8221;. I have included a screen shot of it.<br />
<div id="attachment_392" class="wp-caption aligncenter" style="width: 611px"><a href="http://www.codingfriends.com/wp-content/uploads/2009/09/sugarhook1.jpeg"><img src="http://www.codingfriends.com/wp-content/uploads/2009/09/sugarhook1.jpeg" alt="SugarCRM Hook output" title="SugarCRM Hook" width="601" height="342" class="size-full wp-image-392" /></a><p class="wp-caption-text">SugarCRM Hook output</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2009/09/07/sugarcrm-hook-what-are-they/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Constant casting</title>
		<link>http://www.codingfriends.com/index.php/2009/08/03/constant-casting/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=constant-casting</link>
		<comments>http://www.codingfriends.com/index.php/2009/08/03/constant-casting/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 11:21:41 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C / C++]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=331</guid>
		<description><![CDATA[Constant casting is when you are for example calling a external library function that does not understand the const (constant) type and so you will need to take it off because the program will do something funny otherwise, crash. etc.. Here is a example code of a const_cast #include &#60;iostream&#62; &#160; using namespace std; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Constant casting is when you are for example calling a external library function that does not understand the const (constant) type and so you will need to take it off because the program will do something funny otherwise, crash. etc..</p>
<p>Here is a example code of a const_cast</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> exampleextenalfuction<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> value<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// you can alter the value if you want to, since it is not longer a constant value</span>
	<span style="color: #0000ff;">return</span> value  <span style="color: #000040;">+</span> value<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> constvalue <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> constvalue <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Calling a external function that does not use constant types&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> exampleextenalfuction<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000040;">&amp;</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>constvalue<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2009/08/03/constant-casting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Static casting</title>
		<link>http://www.codingfriends.com/index.php/2009/08/03/static-casting/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=static-casting</link>
		<comments>http://www.codingfriends.com/index.php/2009/08/03/static-casting/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 11:16:00 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C / C++]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=329</guid>
		<description><![CDATA[Static casting is when you want to convert one type into another, static casting is used allot of the time without even knowing. For example int value = 2; float t = float&#40;value&#41;; the float(value) is a static casting of converting one value into another. Below is a full code example #include &#60;iostream&#62; &#160; using [...]]]></description>
			<content:encoded><![CDATA[<p>Static casting is when you want to convert one type into another, static casting is used allot of the time without even knowing.  For example</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> value <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">float</span> t <span style="color: #000080;">=</span> <span style="color: #0000ff;">float</span><span style="color: #008000;">&#40;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>the float(value) is a static casting of converting one value into another.  Below is a full code example</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span><span style="color: #008080;">;</span>
	<span style="color: #666666;">// the float(&lt;value)&gt; is basically a static cast from a interger value into a float</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000ff;">float</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000ff;">static_cast</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">float</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>It is very small since static_cast&#8217;ing is very basic in nature, but the only problem is that you have to check to make sure that there is a error e.g not NULL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2009/08/03/static-casting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Execution order</title>
		<link>http://www.codingfriends.com/index.php/2009/08/03/execution-order/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=execution-order</link>
		<comments>http://www.codingfriends.com/index.php/2009/08/03/execution-order/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 11:05:47 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C / C++]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=327</guid>
		<description><![CDATA[Execution order of programs code is very much a vital thing to understand and where some fault finds will take a long while to figure out. Basically like in maths where there is a order of calculating, well in coding structures and also multitasking and multi-threading setups the execution order may be incorrect for lines [...]]]></description>
			<content:encoded><![CDATA[<p>Execution order of programs code is very much a vital thing to understand and where some fault finds will take a long while to figure out.  Basically like in maths where there is a order of calculating, well in coding structures and also multitasking and multi-threading setups the execution order may be incorrect for lines of code.</p>
<p>Here is some examples, the first is when will a function be called and the later when post/pre incrementation will take place.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> value <span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> setvalue2<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;setting value&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
	value <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> value<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> returnvalue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;renting value&quot;</span><span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> value<span style="color: #008080;">;</span>	
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #666666;">// depending on the order of execution the value may be</span>
	<span style="color: #ff0000; font-style: italic;">/* setvalue2 called first
		(setvalue2 = 2 / returnvalue = 2) = 1
	   returnvalue called first
		(setvalue2 = 2 / returnvalue = 1) = 2
	*/</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> setvalue2<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">/</span> returnvalue<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">int</span> i<span style="color: #008080;">;</span>
	i <span style="color: #000080;">=</span> i<span style="color: #000040;">++</span> <span style="color: #000040;">-</span> <span style="color: #000040;">++</span>i<span style="color: #008080;">;</span>	<span style="color: #666666;">// not sure what i will be because the pre/post increaments </span>
	i <span style="color: #000080;">=</span> <span style="color: #0000dd;">3</span>, i<span style="color: #000040;">++</span>, i<span style="color: #000040;">++</span><span style="color: #008080;">;</span> <span style="color: #666666;">// i will equal 5 because in correct order.</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2009/08/03/execution-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Casting</title>
		<link>http://www.codingfriends.com/index.php/2009/08/01/dynamic-casting/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=dynamic-casting</link>
		<comments>http://www.codingfriends.com/index.php/2009/08/01/dynamic-casting/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 20:28:02 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C / C++]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=322</guid>
		<description><![CDATA[Dynamic casting, means that you can convert one object into another that is off the same type. For example, if you had a base class called Shape and a inherited class called Rectangle then you are able to convert a Shape object into a Rectangle. Rectangle *rec = dynamic_cast&#60;Shape *&#62;&#40;shapeobject&#41;; sort of thing, there has [...]]]></description>
			<content:encoded><![CDATA[<p>Dynamic casting, means that you can convert one object into another that is off the same type.  For example, if you had a base class called Shape and a inherited class called Rectangle then you are able to convert a Shape object into a Rectangle.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">Rectangle <span style="color: #000040;">*</span>rec <span style="color: #000080;">=</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;</span>Shape <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>shapeobject<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>sort of thing, there has to be a virtual function within the base class otherwise the compiler will complain, but apart from that that is about it.</p>
<p>Dynamic casting allows for NULL returns which is the best thing, because you can test to see if the casting actually worked and not to do anything silly on a NULL object which would crash the program.</p>
<p>Pointer casting uses the sytnax</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #000080;">&lt;</span>type<span style="color: #000080;">&gt;</span> <span style="color: #000040;">*</span>p_subclass <span style="color: #000080;">=</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;&lt;</span>type<span style="color: #000080;">&gt;</span> <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> p_obj <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Reference will not throw an error/expcetion so will need to check std::bad_cast< typeinfo header >, here is the syntax</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #000080;">&lt;</span>type<span style="color: #000080;">&gt;</span> subclass <span style="color: #000080;">=</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;&lt;</span>type<span style="color: #000080;">&gt;</span> <span style="color: #000040;">&amp;</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span> ref_obj <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Hopefully this will make more sense for how and why it works.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">class</span> classA 
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">public</span>	<span style="color: #008080;">:</span>
		<span style="color: #0000ff;">int</span> x<span style="color: #008080;">;</span>		<span style="color: #666666;">// should be private</span>
		<span style="color: #0000ff;">char</span> y<span style="color: #008080;">;</span>		<span style="color: #666666;">// should be private</span>
&nbsp;
		classA<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
 		<span style="color: #0000ff;">virtual</span> ~classA<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span> 	<span style="color: #666666;">// need to have a virtual function for dynamic casting</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// basic classA constructor</span>
classA<span style="color: #008080;">::</span><span style="color: #007788;">classA</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span> 
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;classA&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span> 
	x <span style="color: #000080;">=</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> 
	y <span style="color: #000080;">=</span> <span style="color: #FF0000;">'a'</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #0000ff;">class</span> classB <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> classA
<span style="color: #008000;">&#123;</span>	
	<span style="color: #0000ff;">public</span> <span style="color: #008080;">:</span>
		<span style="color: #0000ff;">int</span> b<span style="color: #008080;">;</span>		<span style="color: #666666;">// should be private</span>
&nbsp;
		classB<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
		~classB<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>	<span style="color: #666666;">// complete the virtual</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// basic classB constructor</span>
classB<span style="color: #008080;">::</span><span style="color: #007788;">classB</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;classB&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	x <span style="color: #000080;">=</span> <span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
	y <span style="color: #000080;">=</span> <span style="color: #FF0000;">'b'</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	classA newa<span style="color: #008080;">;</span>	<span style="color: #666666;">// classA obj</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;class A constructed&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	classB newb<span style="color: #008080;">;</span>	<span style="color: #666666;">// classB obj</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;class B constructed&quot;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;NewA X &quot;</span> <span style="color: #000080;">&lt;&lt;</span> newa.<span style="color: #007788;">x</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;NewB X &quot;</span> <span style="color: #000080;">&lt;&lt;</span> newb.<span style="color: #007788;">x</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// point a classB to a already created classB object</span>
	classB <span style="color: #000040;">*</span>normalB <span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span>newb<span style="color: #008080;">;</span>
	<span style="color: #666666;">// dynamic_cast a normalB object (newb) to another classA object</span>
	classA <span style="color: #000040;">*</span>dynA <span style="color: #000080;">=</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;</span>classB <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>normalB<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>	
	<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;dynamic A X &quot;</span> <span style="color: #000080;">&lt;&lt;</span> dynA<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #666666;">// does not work, because you cannot convert classA into a classB, but if classA was pointing to a classB type.</span>
	classA <span style="color: #000040;">*</span>normalA <span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span>newa<span style="color: #008080;">;</span>
	classB <span style="color: #000040;">*</span>dynB <span style="color: #000080;">=</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;</span>classB <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>normalA<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>dynB<span style="color: #008000;">&#41;</span>	<span style="color: #666666;">// above produces a 0 because invalid.</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;dynamic B X &quot;</span> <span style="color: #000080;">&lt;&lt;</span> dynB<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;dynamic B X &quot;</span> <span style="color: #000080;">&lt;&lt;</span> dynB<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>b <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #666666;">// this does work because it is converting from a pointer of classB type, which was &quot;sitting&quot; in a classA container</span>
	<span style="color: #666666;">// and then is converted back to a classB</span>
	classA <span style="color: #000040;">*</span>normalA2 <span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span>newb<span style="color: #008080;">;</span>
	classB <span style="color: #000040;">*</span>dynB2 <span style="color: #000080;">=</span> <span style="color: #0000ff;">dynamic_cast</span><span style="color: #000080;">&lt;</span>classB <span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>normalA2<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>dynB2<span style="color: #008000;">&#41;</span>	<span style="color: #666666;">// above produces a 0 because invalid.</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;dynamic A2X &quot;</span> <span style="color: #000080;">&lt;&lt;</span> normalA2<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>	<span style="color: #666666;">// output is 2 because it was a classB constructed</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;dynamic B X &quot;</span> <span style="color: #000080;">&lt;&lt;</span> dynB2<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;dynamic B X &quot;</span> <span style="color: #000080;">&lt;&lt;</span> dynB2<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>b <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2009/08/01/dynamic-casting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grab data from tables</title>
		<link>http://www.codingfriends.com/index.php/2009/07/28/grab-data-from-tables/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=grab-data-from-tables</link>
		<comments>http://www.codingfriends.com/index.php/2009/07/28/grab-data-from-tables/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 13:25:40 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[SQL (Structured Query Language)]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MS SQL]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Postgres]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=279</guid>
		<description><![CDATA[Alter the variable @tableName to the table and also the @tableWhere for the where condition, I found that if you use the standard sql dumps that you was taking allot of other crap with you as well. The code declare @colName varchar&#40;100&#41;, @colSql varchar&#40;500&#41;, @colSQLInsert varchar&#40;500&#41;, @type int, @auto int, @tableName varchar&#40;50&#41;, @tableWhere varchar&#40;500&#41;; SET [...]]]></description>
			<content:encoded><![CDATA[<p>Alter the variable @tableName to the table and also the @tableWhere for the where condition, I found that if you use the standard sql dumps that you was taking allot of other crap with you as well.</p>
<p>The code</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">declare @colName varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @colSql varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @colSQLInsert varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @type int<span style="color: #66cc66;">,</span> @auto int<span style="color: #66cc66;">,</span> @tableName varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> @tableWhere varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">500</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">SET</span> @tableName <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'tablename'</span>;
<span style="color: #993333; font-weight: bold;">SET</span> @tableWhere <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'the where condition'</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">-- grab the table column names</span>
declare tablecol cursor <span style="color: #993333; font-weight: bold;">FOR</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> name<span style="color: #66cc66;">,</span> typestat<span style="color: #66cc66;">,</span> autoval <span style="color: #993333; font-weight: bold;">FROM</span> syscolumns <span style="color: #993333; font-weight: bold;">WHERE</span> id <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> id <span style="color: #993333; font-weight: bold;">FROM</span> sysobjects <span style="color: #993333; font-weight: bold;">WHERE</span> name <span style="color: #66cc66;">=</span> @tableName<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">--The @auto is the auto generated fields e.g. primary key. &lt;/b&gt;</span>
<span style="color: #993333; font-weight: bold;">SET</span> @colSql <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span>;
<span style="color: #993333; font-weight: bold;">SET</span> @colSQLInsert <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span>;
open tablecol;
fetch tablecol <span style="color: #993333; font-weight: bold;">INTO</span> @colName<span style="color: #66cc66;">,</span> @type<span style="color: #66cc66;">,</span> @auto;
while <span style="color: #66cc66;">&#40;</span>@@fetch_status <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
begin
       <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@auto <span style="color: #993333; font-weight: bold;">IS</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span>
       begin
              <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>charindex<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">,</span>@colName<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">SET</span> @colName <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'['</span><span style="color: #66cc66;">+</span>@colName<span style="color: #66cc66;">+</span><span style="color: #ff0000;">']'</span>;
              <span style="color: #993333; font-weight: bold;">SET</span> @colSQL <span style="color: #66cc66;">=</span> @colName <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">','</span> <span style="color: #66cc66;">+</span>@colSQL;
              <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>@type <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>
                     <span style="color: #993333; font-weight: bold;">SET</span> @colSQLInsert <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'+isnull('</span> <span style="color: #66cc66;">+</span> @colName <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">',0)+'</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">','</span> <span style="color: #66cc66;">+</span> @colSQLInsert;
              else
                     <span style="color: #993333; font-weight: bold;">SET</span> @colSQLInsert <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">''</span><span style="color: #ff0000;">'+str(isnull('</span> <span style="color: #66cc66;">+</span> @colName <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">','</span><span style="color: #ff0000;">''</span><span style="color: #ff0000;">'))+'</span><span style="color: #ff0000;">','</span> <span style="color: #66cc66;">+</span> @colSQLInsert;
       end
       fetch next <span style="color: #993333; font-weight: bold;">FROM</span> tablecol <span style="color: #993333; font-weight: bold;">INTO</span> @colName<span style="color: #66cc66;">,</span> @type<span style="color: #66cc66;">,</span> @auto;
end
close tablecol;
deallocate tablecol;
<span style="color: #808080; font-style: italic;">-- to build the sql statement, since it stops at 255 charactes split the outputs&lt;/b&gt;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">'select ('</span><span style="color: #ff0000;">'insert into '</span><span style="color: #66cc66;">+</span>@tableName<span style="color: #66cc66;">+</span><span style="color: #ff0000;">' ('</span>;
declare @loopingVal int;
<span style="color: #993333; font-weight: bold;">SET</span> @loopingVal <span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>;
while <span style="color: #66cc66;">&#40;</span>len<span style="color: #66cc66;">&#40;</span>@colSQL<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> @loopingVal<span style="color: #66cc66;">&#41;</span>
begin
       <span style="color: #993333; font-weight: bold;">SELECT</span> substring<span style="color: #66cc66;">&#40;</span>@colSQL<span style="color: #66cc66;">,</span> @loopingVal<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
       <span style="color: #993333; font-weight: bold;">SET</span> @loopingVal <span style="color: #66cc66;">=</span> @loopingVal <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">255</span>;
end
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">') values ('</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">SET</span> @loopingVal <span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>;
while <span style="color: #66cc66;">&#40;</span>len<span style="color: #66cc66;">&#40;</span>@colSQLInsert<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> @loopingVal<span style="color: #66cc66;">&#41;</span>
begin
       <span style="color: #993333; font-weight: bold;">SELECT</span> substring<span style="color: #66cc66;">&#40;</span>@colSQLInsert<span style="color: #66cc66;">,</span> @loopingVal<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>;
       <span style="color: #993333; font-weight: bold;">SET</span> @loopingVal <span style="color: #66cc66;">=</span> @loopingVal <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">255</span>;
end
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">')'</span><span style="color: #ff0000;">') from '</span><span style="color: #66cc66;">+</span>@tableName <span style="color: #66cc66;">+</span> <span style="color: #ff0000;">' '</span> <span style="color: #66cc66;">+</span> @tableWhere;</pre></div></div>

<p>The output will be x lines, and if you just copy them into a single line and this will display (once executed) the insert lines.</p>
<p>If anyone has any better methods, please comment <img src='http://www.codingfriends.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2009/07/28/grab-data-from-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
