<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>mishmashmoo</title>
	
	<link>http://mishmashmoo.com/blog</link>
	<description>the technical blog of sameh abdelhamid</description>
	<lastBuildDate>Mon, 10 Oct 2011 23:29:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
<link>http://mishmashmoo.com/blog</link>
<url>http://mishmashmoo.com/blog/wp-content/mbp-favicon/transparent.ico</url>
<title>mishmashmoo</title>
</image>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/mishmashmoo" /><feedburner:info uri="mishmashmoo" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>vugen :: search and replace characters in a string</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/vhAPkc_i17M/</link>
		<comments>http://mishmashmoo.com/blog/?p=159#comments</comments>
		<pubDate>Mon, 10 Oct 2011 23:28:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=159</guid>
		<description><![CDATA[What happens when you have to submit special charaters, or reserverd characters in vugen? It can be quite a pain. Yes you can always do a web_convert_param(), but sometimes it doesnt do what you need. I&#8217;ve noticed it converts a space to a + not a %20&#8230;.This has really confused me when submitting a webform&#8230;
The [...]]]></description>
			<content:encoded><![CDATA[<p>What happens when you have to submit special charaters, or reserverd characters in vugen? It can be quite a pain. Yes you can always do a <strong>web_convert_param()</strong>, but sometimes it doesnt do what you need. I&#8217;ve noticed it converts a space to a <strong>+</strong> not a <strong>%20</strong>&#8230;.This has really confused me when submitting a webform&#8230;<br />
The only other way to get around it is to write a function that searches your string, and replaces it.<br />
<span id="more-159"></span><br />
My colleague Brady Wood wrote this, I&#8217;m just stealing it and claiming it as my own!&#8230;.Thanks Woody.</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>replace_str<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str, <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>orig, <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>rep<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    size_t buf_index <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>;
    <span style="color: #993333;">static</span> <span style="color: #993333;">char</span> buffer<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">10000</span><span style="color: #009900;">&#93;</span>;
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>strstr<span style="color: #009900;">&#40;</span>str, orig<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  <span style="color: #666666; font-style: italic;">// Is 'orig' even in 'str'?</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> str;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    buffer<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span>;
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>;;<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>        
        <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>p;
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>p <span style="color: #339933;">=</span> strstr<span style="color: #009900;">&#40;</span>str, orig<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>  
        <span style="color: #009900;">&#123;</span>
           strcpy<span style="color: #009900;">&#40;</span>buffer <span style="color: #339933;">+</span> buf_index, str<span style="color: #009900;">&#41;</span>;
           <span style="color: #b1b100;">return</span> buffer;
        <span style="color: #009900;">&#125;</span>
        strncpy<span style="color: #009900;">&#40;</span>buffer <span style="color: #339933;">+</span> buf_index, str, p <span style="color: #339933;">-</span> str<span style="color: #009900;">&#41;</span>;
        strcpy<span style="color: #009900;">&#40;</span>buffer <span style="color: #339933;">+</span> buf_index <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>p <span style="color: #339933;">-</span> str<span style="color: #009900;">&#41;</span>, rep<span style="color: #009900;">&#41;</span>;
        buf_index <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>p<span style="color: #339933;">-</span>str<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> strlen<span style="color: #009900;">&#40;</span>rep<span style="color: #009900;">&#41;</span>;
        str <span style="color: #339933;">=</span> p <span style="color: #339933;">+</span> strlen<span style="color: #009900;">&#40;</span>orig<span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> buffer;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Use it like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="c">_otpUrlPtr <span style="color: #339933;">=</span> replace_str<span style="color: #009900;">&#40;</span>lr_eval_string<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;{urlRedirect_3}&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #ff0000;">&quot;&amp;amp;&quot;</span>, <span style="color: #ff0000;">&quot;&amp;&quot;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>and you&#8217;re done. </p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=159</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=159</feedburner:origLink></item>
		<item>
		<title>vugen :: send email [gmail] on error</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/8aTSQjctxRA/</link>
		<comments>http://mishmashmoo.com/blog/?p=153#comments</comments>
		<pubDate>Fri, 07 Oct 2011 16:21:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=153</guid>
		<description><![CDATA[Ever had to run a soak test, load test, whatever test at an un-Godly hour? Did you ever hit &#8216;play&#8217; and then go home, and, just pray (religious?) that the test would be finished with all your results when you get to work the next day?, only to find it crashed 4 mins after you [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had to run a soak test, load test, whatever test at an un-Godly hour? Did you ever hit &#8216;play&#8217; and then go home, and, just pray (religious?) that the test would be finished with all your results when you get to work the next day?, only to find it crashed 4 mins after you left&#8230;yes, it sucks.<br />
In my situation, I had a script running for about 3 days. Don&#8217;t ask why, it was just the situation I was in&#8230;! I found myself logging into the box every few hours to make sure the script was running, and it was really getting on my nerves. It got to a point where I would spontaneously wake up in the middle of the night just to check it&#8230;yes, I&#8217;m a freak, thanks for coming to my show!.<br />
So to get around this, I managed to create a very easy way to have vugen send you an email when your script fails. Its really quite simple.<br />
<span id="more-153"></span><br />
So its basically a VBS script, that is kicked off by a <strong>system();</strong> command in vugen.<br />
Here is the VBS script, I found it online and made a few changes of my own.</p>

<div class="wp_syntax"><div class="code"><pre class="vb"><span style="color: #808080;">'Email Config.....</span>
<span style="color: #b1b100;">Const</span> fromEmail	= <span style="color: #ff0000;">&quot;email_sender@gmail.com&quot;</span>
<span style="color: #b1b100;">Const</span> password	= <span style="color: #ff0000;">&quot;password&quot;</span>
&nbsp;
<span style="color: #b1b100;">Dim</span> emailObj, emailConfig
<span style="color: #b1b100;">Set</span> emailObj      = <span style="color: #b1b100;">CreateObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;CDO.Message&quot;</span><span style="color: #66cc66;">&#41;</span>
emailObj.<span style="color: #66cc66;">From</span>     = fromEmail
emailObj.<span style="color: #b1b100;">To</span>       = WScript.<span style="color: #66cc66;">Arguments</span>.<span style="color: #66cc66;">Item</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
emailObj.<span style="color: #66cc66;">Subject</span>  = WScript.<span style="color: #66cc66;">Arguments</span>.<span style="color: #66cc66;">Item</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
emailObj.<span style="color: #66cc66;">TextBody</span> = WScript.<span style="color: #66cc66;">Arguments</span>.<span style="color: #66cc66;">Item</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">If</span> WScript.<span style="color: #66cc66;">Arguments</span>.<span style="color: #b1b100;">Count</span> &gt; <span style="color: #cc66cc;">3</span> <span style="color: #b1b100;">Then</span>
	emailObj.<span style="color: #66cc66;">AddAttachment</span> WScript.<span style="color: #66cc66;">Arguments</span>.<span style="color: #66cc66;">Item</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">End</span> <span style="color: #b1b100;">If</span>
<span style="color: #b1b100;">Set</span> emailConfig = emailObj.<span style="color: #66cc66;">Configuration</span>
emailConfig.<span style="color: #66cc66;">Fields</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;</span><span style="color: #66cc66;">&#41;</span>       = <span style="color: #ff0000;">&quot;smtp.gmail.com&quot;</span>
emailConfig.<span style="color: #66cc66;">Fields</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;</span><span style="color: #66cc66;">&#41;</span>   = <span style="color: #cc66cc;">465</span>
emailConfig.<span style="color: #66cc66;">Fields</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://schemas.microsoft.com/cdo/configuration/sendusing&quot;</span><span style="color: #66cc66;">&#41;</span>        = <span style="color: #cc66cc;">2</span>
emailConfig.<span style="color: #66cc66;">Fields</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://schemas.microsoft.com/cdo/configuration/smtpauthenticate&quot;</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #cc66cc;">1</span>
emailConfig.<span style="color: #66cc66;">Fields</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://schemas.microsoft.com/cdo/configuration/smtpusessl&quot;</span><span style="color: #66cc66;">&#41;</span>       = <span style="color: #b1b100;">true</span>
emailConfig.<span style="color: #66cc66;">Fields</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://schemas.microsoft.com/cdo/configuration/sendusername&quot;</span><span style="color: #66cc66;">&#41;</span>     = fromEmail
emailConfig.<span style="color: #66cc66;">Fields</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://schemas.microsoft.com/cdo/configuration/sendpassword&quot;</span><span style="color: #66cc66;">&#41;</span>     = password
emailConfig.<span style="color: #66cc66;">Fields</span>.<span style="color: #66cc66;">Update</span>
emailObj.<span style="color: #66cc66;">Send</span>
<span style="color: #b1b100;">Set</span> emailobj	= <span style="color: #b1b100;">nothing</span>
<span style="color: #b1b100;">Set</span> emailConfig	= <span style="color: #b1b100;">nothing</span></pre></div></div>

<p>You can test this out via command line quite easily. Drop this vbs file on your C drive. and run the following (dont forget to populate the file with your gmail address and password!</p>

<div class="wp_syntax"><div class="code"><pre class="dos">cscript c:\sendemail.vbs example<span style="color: #33cc33;">@</span>gmail.com &quot;test subject line&quot; &quot;test email body&quot;</pre></div></div>

<p>And if you want an attachment..like the script&#8217;s output log which should contain the error..(which is a lovley feature!) &#8211;careful with bandwidth here, they can get quite large&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="dos">cscript c:\sendemail.vbs example<span style="color: #33cc33;">@</span>gmail.com &quot;test subject line&quot; &quot;test email body&quot; &quot;c:\ScriptName\mdrv.log&quot;</pre></div></div>

<p>Once that&#8217;s done, chuck this in your LR script, and you&#8217;re sorted.</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">char</span> command <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#93;</span>
sprintf <span style="color: #009900;">&#40;</span>command, <span style="color: #ff0000;">&quot;cscript c:<span style="color: #000099; font-weight: bold;">\\</span>email.vbs example@gmail.com <span style="color: #000099; font-weight: bold;">\&quot;</span>Error with Script<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>Your Performance Testing skills are clearly inadequate, either find a new job, or learn how to code....Script XXX has failed....that is all master.<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span>;
system<span style="color: #009900;">&#40;</span>command<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>I chuck it in vuser end, as I know it will get executed only once (on fail or completion..).<br />
I love this because my phone is always near me, and my gmail is sync&#8217;d instantly, so I can go out, have fun, and when I get that dreaded email (which I must add, doesn&#8217;t happen often, as my scripts are as robust as a Ayres Rock! <img src='http://mishmashmoo.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ), I just remote in, fix it up and off we go&#8230;..</p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=153</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=153</feedburner:origLink></item>
		<item>
		<title>not having clause :: sql</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/01wCDXNJC5k/</link>
		<comments>http://mishmashmoo.com/blog/?p=149#comments</comments>
		<pubDate>Wed, 21 Sep 2011 04:29:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=149</guid>
		<description><![CDATA[A quick and dirty blog, cause I&#8217;m really busy.
This is simple sql for the guru&#8217;s (however, I&#8217;m not a guru!), but I recently had to find out how many records don&#8217;t exist in a table.
Its easy enough to find out how many do, using the magical count(*), but I&#8217;ve never had to do this&#8230;and if [...]]]></description>
			<content:encoded><![CDATA[<p>A quick and dirty blog, cause I&#8217;m really busy.<br />
This is simple sql for the guru&#8217;s (however, I&#8217;m not a guru!), but I recently had to find out how many records <strong>don&#8217;t</strong> exist in a table.<br />
Its easy enough to find out how many do, using the magical <strong>count(*)</strong>, but I&#8217;ve never had to do this&#8230;and if I did, it was probably a silly looking subquery.<br />
<span id="more-149"></span><br />
Here is the query</p>

<div class="wp_syntax"><div class="code"><pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span> usergroup<span style="color: #66cc66;">,</span> count<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> cnt <span style="color: #993333; font-weight: bold;">FROM</span> users
 <span style="color: #993333; font-weight: bold;">WHERE</span> usergroup <span style="color: #993333; font-weight: bold;">LIKE</span> <span style="color: #ff0000;">'%GRP%'</span> <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> usergroup <span style="color: #993333; font-weight: bold;">HAVING</span> count<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">101</span></pre></div></div>

<p>You have to &#8216;<strong>group by</strong>, and it works really well, providing the &#8216;usergroup&#8217; and the number of items that exist (that is less than 101). </p>
<p>Change what you need to suit your needs&#8230;</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=149</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=149</feedburner:origLink></item>
		<item>
		<title>diffing scripts :: vugen</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/sqLEhADwzeY/</link>
		<comments>http://mishmashmoo.com/blog/?p=142#comments</comments>
		<pubDate>Thu, 01 Sep 2011 03:36:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=142</guid>
		<description><![CDATA[Working out how which values in a script need to be paramatised can be tedious and time consuming if completed manually. I always wonder about people who things manually, when, in this world of technology, we are able to utilise different applications, and tools to assist our day to day activities. Plus, its also damn [...]]]></description>
			<content:encoded><![CDATA[<p>Working out how which values in a script need to be paramatised can be tedious and time consuming if completed manually. I always wonder about people who things manually, when, in this world of technology, we are able to utilise different applications, and tools to assist our day to day activities. Plus, its also damn boring. There&#8217;s a solution at hand, and if you are a half decent performance tester, you&#8217;ll know you need to record 2 of the same scripts and diff the changed content&#8230;if you don&#8217;t know this, I highly consider a career change.<br />
<span id="more-142"></span><br />
There are some unreal diff tools in the world, but getting the right one to work in vugen is not as easy as 1,2,3. You don’t want to be copying and pasting a script every time you&#8217;re ready to roll.<br />
Here&#8217;s a quick and easy solution. </p>
<p>Firstly, download DaisyDiff from <a href="http://code.google.com/p/daisydiff/downloads/detail?name=daisydiff-1.1.zip">here</a>. Or you can get it from my website which is <a href="http://mishmashmoo.com/downloads/daisydiff.zip">here</a>. </p>
<p>Install it to your <strong>c:\daisydiff</strong> directory. </p>
<p>Create a batch file with the following contents in that directory, call it <strong>daisy.bat</strong></p>

<div class="wp_syntax"><div class="code"><pre class="dos"><span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">echo</span> off
<span style="color: #b1b100; font-weight: bold;">SET</span> <span style="color: #448844;">DIFFA</span>=<span style="color: #33cc33;">%</span><span style="color: #448888;"><span style="color: #cc66cc;">1</span></span>
<span style="color: #b1b100; font-weight: bold;">SET</span> <span style="color: #448844;">DIFFB</span>=<span style="color: #33cc33;">%</span><span style="color: #448888;"><span style="color: #cc66cc;">2</span></span>
java -Xms128m -Xmx512m -jar C:\daisydiff\daisydiff.jar <span style="color: #33cc33;">%</span><span style="color: #448888;"><span style="color: #cc66cc;">1</span></span> <span style="color: #33cc33;">%</span><span style="color: #448888;"><span style="color: #cc66cc;">2</span></span> --type=tag
C:\daisydiff\daisydiff.htm
<span style="color: #b1b100; font-weight: bold;">pause</span></pre></div></div>

<p>Now go into vugen general settings, and set the &#8216;custom diff tool&#8217; to your bat file.<br />
And you&#8217;re done!<br />
You can now use the built in Diff Scripts option in vugen and it will give you a character by character breakdown of what&#8217;s different in your 2 scripts.<br />
Much better than windiff. </p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=142</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=142</feedburner:origLink></item>
		<item>
		<title>mysql gui database management</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/nin3EV--A9E/</link>
		<comments>http://mishmashmoo.com/blog/?p=136#comments</comments>
		<pubDate>Wed, 04 Aug 2010 00:31:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=136</guid>
		<description><![CDATA[I very rarely blog about an application, however sometimes there is an app or two that make my life and job a lot easier to manager. I use a lot of mysql databases, and managing them is something I like to, lets say&#8230;not do.
I simply don&#8217;t like navigating through databases and tables from the mysql [...]]]></description>
			<content:encoded><![CDATA[<p>I very rarely blog about an application, however sometimes there is an app or two that make my life and job a lot easier to manager. I use a lot of mysql databases, and managing them is something I like to, lets say&#8230;not do.<br />
I simply don&#8217;t like navigating through databases and tables from the mysql command line editor, and I really hate the PHP gui tool that it comes with&#8230;its just so cumbersome. I&#8217;ve been using navicat of late, but I hate the idea that I have to pay for it. I mean lets face it, why the heck would you want to pay for a tool that manages an open-source application! Its irony at its greatest. So in my early morning googling, I stumbled across a diamond among the db management tools.<br />
<span id="more-136"></span><br />
This little gem is called HeidiSQL. They are located <a href="http://www.heidisql.com/download.php">here</a>, although you can download the current version (at the time of writing this article) from <a href="http://mishmashmoo.com/downloads/HeidiSQL_5.1_Setup.exe">here</a>.<br />
Its basically a full GUI management tool of your mysql database, with a whole bunch of features. I wont go into the features, but check it out yourself. </p>
<p>Props to HeidiSQL and MySQl. </p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=136</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=136</feedburner:origLink></item>
		<item>
		<title>oracle reporting through ruby</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/g0j1Rr9EkmI/</link>
		<comments>http://mishmashmoo.com/blog/?p=124#comments</comments>
		<pubDate>Tue, 03 Aug 2010 06:15:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=124</guid>
		<description><![CDATA[As the cobwebs fill up on my blog just in time for spring, I thought it may best to clean it up and put some fresh stuff&#8230;So reporting is a kind of a big deal at these big corporations. Seems like there is always someone higher in the food chain who wants a spreadsheet to [...]]]></description>
			<content:encoded><![CDATA[<p>As the cobwebs fill up on my blog just in time for spring, I thought it may best to clean it up and put some fresh stuff&#8230;So reporting is a kind of a big deal at these big corporations. Seems like there is always someone higher in the food chain who wants a spreadsheet to tell them what you&#8217;re actually doing, and if you&#8217;re hitting your targets. As annoying and cumbersome as it may be, it’s very important that you produce and provide statistics that are accurate, and up to date, so I&#8217;ve got a quick solution that will make any boss somewhat happy&#8230;<br />
<span id="more-124"></span><br />
A wise man once told me, if you do something more than once, it’s worth automating it. So I took that idea and ran a marathon with it. I automate everything. I hate repetition so I&#8217;d rather invest 3 times the effort and write a script than do it 10 times over. Simple maths really.<br />
Oracle db&#8217;s are everywhere, I blog about them, I work with them and I fight with too. If you want the basics on getting ruby and oracle to work, read my other blog post which is <a href="http://mishmashmoo.com/blog/?p=5">here</a>.</p>
<p>Once you have that established, install <a href="http://www.wampserver.com/en/">wamp</a>, which is an apache webserver, mysql and php rolled into one package.</p>
<p>Now what we&#8217;re going to do here is use the script from my other post, and enhance it somewhat. In my scenario I have a spreadsheet with NFR&#8217;s. They state the Group name, Transaction Name &amp; Response Time. I want my report to show these values (as the source) and then display the values that are in the database so my boss can compare the results and see how the system is performing.</p>
<p>Let’s assume your spreadsheet looks likes this:</p>
<table border="1">
<tr>
<td>Group</td>
<td>Transaction</td>
<td>Response Time</td>
</tr>
<tr>
<td>01.Payment</td>
<td>Submit Payment</td>
<td>12 seconds</td>
</tr>
</table>
<p>Now in my master database, my system keeps a log of when a payment changed status from entered, to submitted. Like most systems, it’s a timestamp and it will show the changed status of that particular payment x amount of times, based on how many status&#8217;s it goes through. I&#8217;ve seen this in many systems, and it’s quite kosher, or halal (depending on where you come from!). </p>
<p>Luckily I have an sql query that will do this for me, but it just presents all the payments in the date range I need, but I need the 95th Percentile of this&#8230;.luckily sql can do this for you and here is something I whipped up&#8230;with some help from my colleagues and maybe a DBA or 2..</p>

<div class="wp_syntax"><div class="code"><pre class="sql"><span style="color: #993333; font-weight: bold;">SELECT</span> trunc<span style="color: #66cc66;">&#40;</span>percentile_cont<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.95</span><span style="color: #66cc66;">&#41;</span> WITHIN <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>bt2<span style="color: #66cc66;">.</span>logtime <span style="color: #66cc66;">-</span> bt1<span style="color: #66cc66;">.</span>logtime<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">24</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">3600</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>count<span style="color: #66cc66;">&#40;</span>bt1<span style="color: #66cc66;">.</span>trans_num<span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">FROM</span> AUDIT_LOG bt1<span style="color: #66cc66;">,</span> AUDIT_LOG bt2<span style="color: #66cc66;">,</span> 
        <span style="color: #993333; font-weight: bold;">WHERE</span> bt1<span style="color: #66cc66;">.</span>TRANS_NUM <span style="color: #66cc66;">=</span> bt2<span style="color: #66cc66;">.</span>TRANS_NUM
        <span style="color: #993333; font-weight: bold;">AND</span> bt1<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'SUBMITTED'</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">AND</span> bt2<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">STATUS</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'APPROVED'</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">AND</span> at<span style="color: #66cc66;">.</span>LOG_TIMESTAMP <span style="color: #66cc66;">&gt;</span> TO_DATE<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&quot;+datetimefrom +&quot;'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYY-MM-DD HH24:MI:SS'</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #993333; font-weight: bold;">AND</span> at<span style="color: #66cc66;">.</span>LOG_TIMESTAMP <span style="color: #66cc66;">&lt;</span> TO_DATE<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'&quot;+datetimeto +&quot;'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'YYYY-MM-DD HH24:MI:SS'</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Pretty straight forward, You will obviously need to change it for your own application but it a start.<br />
So this returns 1 value, the 95th percentile, truncated to 1 decimal place, and the number of samples (count) that it evaluated the figure on. </p>
<p>So with those 3 components, we have enough to build a ruby script that will read the spreadsheet, and create a report with the results based on that query. </p>
<p>Ruby script&#8230;</p>
<p>Ok so now we need to make a functions file. lets say, that there are 100 NFR&#8217;s. Each nfr, is based on a different transaction, each one of those transactions needs a separate sql query. So we will need a functions file&#8230;with those queries that our script can call. </p>
<p>Name the following file <b>sql.rb</b></p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'OCI8'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> function<span style="color:#006600; font-weight:bold;">&#40;</span>name,datetimefrom,datetimeto<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">case</span> name
       <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">&quot;submit_payment&quot;</span>
              <span style="color:#ff6633; font-weight:bold;">$nfr_name</span> = <span style="color:#996600;">&quot;Submit Payment&quot;</span>
              <span style="color:#ff6633; font-weight:bold;">$query</span>=<span style="color:#996600;">&quot;select trunc(percentile_cont(0.95) WITHIN GROUP (ORDER BY ((bt2.logtime - bt1.logtime) * 24 * 3600 )),1),count(bt1.trans_num)
        FROM AUDIT_LOG bt1, AUDIT_LOG bt2, 
        WHERE bt1.TRANS_NUM = bt2.TRANS_NUM
        AND bt1.STATUS in ('SUBMITTED')
        AND bt2.STATUS in ('APPROVED')
        AND at.LOG_TIMESTAMP &gt; TO_DATE('&quot;</span><span style="color:#006600; font-weight:bold;">+</span>datetimefrom <span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">&quot;','YYYY-MM-DD HH24:MI:SS')
        AND at.LOG_TIMESTAMP &lt; TO_DATE('&quot;</span><span style="color:#006600; font-weight:bold;">+</span>datetimeto <span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">&quot;','YYYY-MM-DD HH24:MI:SS')&quot;</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now the script, which requires the above file.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'OCI8'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'date.rb'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'sql.rb'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'time'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'functions.rb'</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#get the current time</span>
t= <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
&nbsp;
datetimefrom = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
datetimeto = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
filename = ARGV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>
full_filename = <span style="color:#996600;">&quot;c:<span style="color:#000099;">\\</span>wamp<span style="color:#000099;">\\</span>www<span style="color:#000099;">\\</span>reports<span style="color:#000099;">\\</span>&quot;&quot;</span> <span style="color:#006600; font-weight:bold;">+</span>filename<span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;.csv&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#put the headers of the file in first</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>full_filename,<span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>the_file<span style="color:#006600; font-weight:bold;">|</span>
  the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Group,Transaction,Date/Time From, Date/Time To,RT,95th Percentile,Sample Size&quot;</span>
  the_file.<span style="color:#9900CC;">close</span>
<span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
<span style="color:#008000; font-style:italic;">#add the function names into the array</span>
<span style="color:#9966CC; font-weight:bold;">class</span> Nfrlist <span style="color:#006600; font-weight:bold;">&lt;</span>
&nbsp;
 <span style="color:#CC00FF; font-weight:bold;">Struct</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:group</span>, <span style="color:#ff3333; font-weight:bold;">:transaction</span>, <span style="color:#ff3333; font-weight:bold;">:rt</span>, <span style="color:#ff3333; font-weight:bold;">:function</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># define new array to hold the records</span>
nfr = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># open the csv file</span>
f = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;nfrs.csv&quot;</span>, <span style="color:#996600;">&quot;r&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># loop through each record in the csv file, adding</span>
<span style="color:#008000; font-style:italic;"># each record to our array.</span>
f.<span style="color:#9900CC;">each_line</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># each line has fields separated by commas, so split those fields</span>
  fields = line.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">','</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># create a new Person</span>
  <span style="color:#CC0066; font-weight:bold;">p</span> = Nfrlist.<span style="color:#9900CC;">new</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># do a little work here to get rid of double-quotes and blanks</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">group</span> = fields<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">tr_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">transaction</span> = fields<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">tr_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">rt</span> = fields<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">tr_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
    <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">function</span> = fields<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">tr_s</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&quot;'</span>, <span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">strip</span>
    nfr.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#41;</span>   
&nbsp;
&nbsp;
    <span style="color:#008000; font-style:italic;">#array declreation inside loop to clear the array on each iteration in the loop.</span>
    <span style="color:#ff6633; font-weight:bold;">$lines</span>= <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#ff6633; font-weight:bold;">$nfr</span>=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#ff6633; font-weight:bold;">$blah</span>=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#ff6633; font-weight:bold;">$percentile</span>=<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#ff6633; font-weight:bold;">$query</span>=<span style="color:#996600;">&quot;&quot;</span>
&nbsp;
    <span style="color:#008000; font-style:italic;">#call the function from the other .rb file</span>
    function<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">function</span>,datetimefrom,datetimeto<span style="color:#006600; font-weight:bold;">&#41;</span>  
&nbsp;
      <span style="color:#008000; font-style:italic;">#if the name of the function starts with CPR connect to the cpr database,   otherwise go to BTR</span>
      <span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">/</span>^cpr<span style="color:#006600; font-weight:bold;">+</span>.\w<span style="color:#006600; font-weight:bold;">+</span>$<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">function</span><span style="color:#006600; font-weight:bold;">&#41;</span>  <span style="color:#9966CC; font-weight:bold;">then</span>
         conn = OCI8.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'login'</span>, <span style="color:#996600;">'password'</span>, <span style="color:#996600;">'database1.world'</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
      <span style="color:#9966CC; font-weight:bold;">else</span>
          conn = OCI8.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'login'</span>, <span style="color:#996600;">'password'</span>, <span style="color:#996600;">'database2.world'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>    
    <span style="color:#008000; font-style:italic;">#execute the sql query</span>
    <span style="color:#008000; font-style:italic;">#if the query is blank(for items that are not required for the db, but need to have a line item in the rrport) then skip this bit...</span>
&nbsp;
   <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#ff6633; font-weight:bold;">$query</span> != <span style="color:#996600;">&quot;&quot;</span> <span style="color:#9966CC; font-weight:bold;">then</span>
    cursor = conn.<span style="color:#CC0066; font-weight:bold;">exec</span><span style="color:#006600; font-weight:bold;">&#40;</span>$query<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">while</span> r = cursor.<span style="color:#9900CC;">fetch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
       <span style="color:#008000; font-style:italic;">#add each row to the lines array, separate by tab.</span>
       <span style="color:#ff6633; font-weight:bold;">$lines</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span>p.<span style="color:#9900CC;">group</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">transaction</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> datetimefrom <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> datetimeto <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">rt</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;,&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> r.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;,&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    cursor.<span style="color:#9900CC;">close</span>
  <span style="color:#9966CC; font-weight:bold;">end</span> 
&nbsp;
    <span style="color:#ff6633; font-weight:bold;">$percentile</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#ff6633; font-weight:bold;">$lines</span>
&nbsp;
&nbsp;
<span style="color:#008000; font-style:italic;">#now write it to a file. </span>
<span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>full_filename,<span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>the_file<span style="color:#006600; font-weight:bold;">|</span>
  the_file.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#ff6633; font-weight:bold;">$percentile</span>
<span style="color:#9966CC; font-weight:bold;">end</span>  
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Now change your csv, to have a colum which has the name of the case statement name in your sql.rb file for that particular function. </p>
<table border="1">
<tr>
<td>Group</td>
<td>Transaction</td>
<td>Response Time</td>
<td>function</td>
</tr>
<tr>
<td>01.Payment</td>
<td>Submit Payment</td>
<td>12 seconds</td>
<td>submit_payment</tr>
</table>
<p>Once that’s done, you will be able to run that script. It will read the nfr.csv file, and read each column and save it in the struct. Then you can call it via the struct name, and evaluate on it. </p>
<p>As you can see there are ARGV&#8217;s for some info. Those are so this ruby file can be run remotely&#8230;.say from a web interface&#8230;.</p>
<p>Build your php&#8230;<br />
My php contains some calendar scripts, there are hundreds on the net…just have a poke around to find one that suits you.</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;script language</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;calendar.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>form action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;somewhere.php&quot;</span> method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//get class into the page</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tc_calendar.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//instantiate class and set properties</span>
<span style="color: #000033;">$dateFrom</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> tc_calendar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;date1&quot;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateFrom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIcon</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;images/iconCalendar.gif&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateFrom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Time From (HH24:MI:SS): &lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>timefrom<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//output the calendar</span>
<span style="color: #000033;">$dateFrom</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	 
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;P&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateTo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> tc_calendar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;date2&quot;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateTo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIcon</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;images/iconCalendar.gif&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$dateTo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDate</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Time To (HH24:MI:SS): &lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>text<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>timeto<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//output the calendar</span>
<span style="color: #000033;">$dateTo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeScript</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	  
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;throughput&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Yes&quot;</span><span style="color: #339933;">&gt;</span> Throughput Report <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;checkbox&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;responsetime&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Yes&quot;</span><span style="color: #339933;">&gt;</span> Response <span style="color: #990000;">Time</span> Report <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Send it!&quot;</span><span style="color: #339933;">&gt;&lt;/</span>p<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Now the php page that the form will submit to&#8230;called <b>somewhere.php</b></p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
date_default_timezone_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Australia/Sydney&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$filenameDate</span><span style="color: #339933;">=</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dmy_His&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$datefrom</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date1&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date1&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$timefrom</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;timefrom&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000033;">$dateto</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date2&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;date2&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$timeto</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;timeto&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'responsetime'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;responsetime.rb <span style="color: #000099; font-weight: bold;">\&quot;</span>$datefrom $timefrom<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>$dateto $timeto<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>ResponseTime_$filenameDate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000033;">$file</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ResponseTime_$filenameDate.csv&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='http://localhost/reports/ResponseTime_&quot;</span> <span style="color: #339933;">.</span><span style="color: #000033;">$filenameDate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.csv'&gt;Get Response Time Report&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'throughput'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;throughput.rb <span style="color: #000099; font-weight: bold;">\&quot;</span>$datefrom $timefrom<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>$dateto $timeto<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>Throughput_$filenameDate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000033;">$file2</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Throughput_$filenameDate.csv&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br&gt;&lt;a href='http://localhost/reports/Throughput_&quot;</span> <span style="color: #339933;">.</span><span style="color: #000033;">$filenameDate</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.csv'&gt;Get Throughput Report&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now give the URL of your wamp server page to your boss, and he can specify his own date/time range for the report, and it will present itself to him. It will show him something like this </p>
<table border="1">
<tr>
<td>Group</td>
<td>Transaction</td>
<td>Response Time</td>
<td>95th Percentile (from db)</td>
</tr>
<tr>
<td>01.Payment</td>
<td>Submit Payment</td>
<td>12 seconds</td>
<td>37.7</tr>
</table>
<p>Now you need worry bout reporting, as its in the hands of his trusty browser, and your script. </p>
<p>You can keep adding to this, by adding more case statement&#8217;s in the sql.rb file, and making sure you mention the name of the case statement in a row of your nfr.csv.<br />
Then you will never have to touch the script. </p>
<p>Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=124</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=124</feedburner:origLink></item>
		<item>
		<title>connect to mysql with ruby</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/I5ghpOHjQ0E/</link>
		<comments>http://mishmashmoo.com/blog/?p=117#comments</comments>
		<pubDate>Wed, 17 Feb 2010 22:13:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=117</guid>
		<description><![CDATA[Often, when I begin a new gig, I have a few little tools I install to make my job that little bit more efficient.
One of these would be a wamp server and the ruby installer, along with the usual gems I often utilise. The wamp server is great to store data for scripts I&#8217;m writing, [...]]]></description>
			<content:encoded><![CDATA[<p>Often, when I begin a new gig, I have a few little tools I install to make my job that little bit more efficient.<br />
One of these would be a wamp server and the ruby installer, along with the usual gems I often utilise. The wamp server is great to store data for scripts I&#8217;m writing, and a little ruby here and there never hurt anybody!<br />
It occurred to me that I&#8217;d never actually blogged how to get ruby and mysql connectivity. As with anything ruby related, its easy but it does require a few key steps..<br />
<span id="more-117"></span><br />
You&#8217;ll obviously need ruby installed, and the wamp server. Once that’s done, install the <strong>mysql</strong> gem:</p>

<div class="wp_syntax"><div class="code"><pre>c:\&gt;gem install mysql --no-ri --no-rdoc</pre></div></div>

<p>This will install without ri and rdocs. Some definition errors will occur if you install the gem with ri and rdoc, this is due to the location of mysql, however it&#8217;s fine, it&#8217;ll still work!</p>
<p>Once that&#8217;s done, locate your copy of <strong>libmysql.dll</strong>. It&#8217;s usually found in c:\wamp\bin\mysqlmysq<strong>VERSIONl</strong>\bin<br />
Take a copy of it and dump it in your location of ruby. Generally <strong>C:\Ruby\bin</strong>.</p>
<p>Ok so that&#8217;s that part done. Now for the serious stuff&#8230;<br />
Here&#8217;s the code. Its pretty self explanatory.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">query = <span style="color:#996600;">&quot;select columnA, ColumnB from table&quot;</span>
<span style="color:#9966CC; font-weight:bold;">begin</span>
     dbh = Mysql.<span style="color:#9900CC;">real_connect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;localhost&quot;</span>, <span style="color:#996600;">&quot;login&quot;</span>, <span style="color:#996600;">&quot;password&quot;</span>, <span style="color:#996600;">&quot;databaseName&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
     <span style="color:#008000; font-style:italic;"># get server version string and display it</span>
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Server version: &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> dbh.<span style="color:#9900CC;">get_server_info</span>
   <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#6666ff; font-weight:bold;">Mysql::Error</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Error code: #{e.errno}&quot;</span>
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Error message: #{e.error}&quot;</span>
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Error SQLSTATE: #{e.sqlstate}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> e.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;sqlstate&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#9966CC; font-weight:bold;">ensure</span>
      res = dbh.<span style="color:#9900CC;">query</span><span style="color:#006600; font-weight:bold;">&#40;</span>query<span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#9966CC; font-weight:bold;">while</span> row = res.<span style="color:#9900CC;">fetch_row</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#CC0066; font-weight:bold;">puts</span> row<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Number of rows returned: #{res.num_rows}&quot;</span>
   res.<span style="color:#9900CC;">free</span>
     <span style="color:#008000; font-style:italic;"># disconnect from server</span>
     dbh.<span style="color:#9900CC;">close</span> <span style="color:#9966CC; font-weight:bold;">if</span> dbh
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And thats it!<br />
Enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=117</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=117</feedburner:origLink></item>
		<item>
		<title>javascript error when running selenium test suite</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/XGoSVoKotuQ/</link>
		<comments>http://mishmashmoo.com/blog/?p=114#comments</comments>
		<pubDate>Wed, 10 Feb 2010 00:13:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=114</guid>
		<description><![CDATA[A strange problem occurred when I was running one of my selenium test suites. The test would run fine for my first testcase (that is, the first &#8220;method&#8221;). If you know a little about how selenium works, you&#8217;ll know that the teardown method is called after each method.
The teardown basically grabs any errors that occurs [...]]]></description>
			<content:encoded><![CDATA[<p>A strange problem occurred when I was running one of my selenium test suites. The test would run fine for my first testcase (that is, the first &#8220;method&#8221;). If you know a little about how selenium works, you&#8217;ll know that the teardown method is called after each method.<br />
The teardown basically grabs any errors that occurs and kills the browser session, thus opening a new session in your next method. The issue that was occurring was this annoying JavaScript error being pulled from Internet Explorer, saying it cannot run scripts on the page. It halted my script and I had no way to get to the following methods&#8230;so after a little digging around I found a solution&#8230;<br />
<span id="more-114"></span><br />
All you need to do, is replace your current teardown method with this</p>

<div class="wp_syntax"><div class="code"><pre class="ruby">    <span style="color:#9966CC; font-weight:bold;">def</span> teardown
		<span style="color:#0066ff; font-weight:bold;">@selenium</span>.<span style="color:#9900CC;">close</span>
		<span style="color:#0066ff; font-weight:bold;">@selenium</span>.<span style="color:#9900CC;">stop</span>
    assert_equal <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0066ff; font-weight:bold;">@verification_errors</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>That should fix it&#8230;<br />
enjoy! </p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=114</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=114</feedburner:origLink></item>
		<item>
		<title>Frequently used Selenium Commands</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/5vxLsAdpKwM/</link>
		<comments>http://mishmashmoo.com/blog/?p=100#comments</comments>
		<pubDate>Thu, 28 Jan 2010 03:26:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=100</guid>
		<description><![CDATA[So I&#8217;ve been dabling with Selenium again&#8230;I love open source, but the lack of documentation is very frustrating. Hitting F1 in Loadrunner was taken for granted, so if I find something useful, as a fellow open-sourcer, I&#8217;m going to share it. Hopefully this can be of some use to you all.
Enjoy!



	assignId(&#8221;Locator&#8221;,&#8221;String&#8221;)	
	Temporarily sets the &#8220;id&#8221; attribute [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been dabling with Selenium again&#8230;I love open source, but the lack of documentation is very frustrating. Hitting F1 in Loadrunner was taken for granted, so if I find something useful, as a fellow open-sourcer, I&#8217;m going to share it. Hopefully this can be of some use to you all.<br />
Enjoy!<br />
<span id="more-100"></span></p>
<table border=1 width="75%">
<tr>
<td width="10%">	assignId(&#8221;Locator&#8221;,&#8221;String&#8221;)	</td>
<td>	Temporarily sets the &#8220;id&#8221; attribute of the specified element	</td>
</tr>
<tr>
<td width="10%">	capture Screenshot (&#8221;File name&#8221;)	</td>
<td>	Captures a PNG screenshot to thespecified file.	</td>
</tr>
<tr>
<td width="10%">	Check(&#8221;Locator&#8221;)	</td>
<td>	Check a toggle-button(checkbox/radio)	</td>
</tr>
<tr>
<td width="10%">	click(&#8221;Locator&#8221;)	</td>
<td>	Clicks on a link, button, checkboxor radio button.	</td>
</tr>
<tr>
<td width="10%">	clickAt(&#8221;Locator&#8221;,&#8221;Coordinate String&#8221;)	</td>
<td>	Clicks on a link, button, checkboxor radio button.	</td>
</tr>
<tr>
<td width="10%">	close()	</td>
<td>	Simulates the user clicking the&#8221;close&#8221; button in the title bar of a popup window or tab.	</td>
</tr>
<tr>
<td width="10%">	doubleClick(&#8221;Locator&#8221;)	</td>
<td>	Double clicks on a link, button,checkbox or radio button.	</td>
</tr>
<tr>
<td width="10%">	doubleClickAt(&#8221;Locator&#8221;,&#8221;Coordinate String&#8221;)	</td>
<td>	Double clicks on a link, button,checkbox or radio button.	</td>
</tr>
<tr>
<td width="10%">	getAlert()	</td>
<td>	Retrieves the message of aJavaScript alert generated during the previous action, or fail if there were no alerts.	</td>
</tr>
<tr>
<td width="10%">	getAllButtons()	</td>
<td>	Returns the IDs of all buttons onthe page.	</td>
</tr>
<tr>
<td width="10%">	getAllFields()	</td>
<td>	Returns the IDs of all input fieldson the page.	</td>
</tr>
<tr>
<td width="10%">	getAllLinks()	</td>
<td>	Returns the IDs of all links on the page.	</td>
</tr>
<tr>
<td width="10%">	getAllWindowIds()	</td>
<td>	Returns the IDs of all windows that the browser knows about.	</td>
</tr>
<tr>
<td width="10%">	getAllWindowNames()	</td>
<td>	Returns the names of all windows that the browser knows about.	</td>
</tr>
<tr>
<td width="10%">	getAllWindowTitles()	</td>
<td>	Returns the titles of all windows that the browser knows about.	</td>
</tr>
<tr>
<td width="10%">	getAttribute(&#8221;Attribute Locator&#8221;)	</td>
<td>	Gets the value of an element attribute.	</td>
</tr>
<tr>
<td width="10%">	getBodyText()	</td>
<td>	Gets the entire text of the page.	</td>
</tr>
<tr>
<td width="10%">	getConfirmation()	</td>
<td>	Retrieves the message of a JavaScript confirmation dialog generated during the previous action.	</td>
</tr>
<tr>
<td width="10%">	getCookie()	</td>
<td>	Return all cookies of the current page under test.	</td>
</tr>
<tr>
<td width="10%">	getElementHeight(&#8221;Locator&#8221;)	</td>
<td>	Retrieves the height of an element	</td>
</tr>
<tr>
<td width="10%">	getElementPositionLeft(&#8221;Locator&#8221;)	</td>
<td>	Retrieves the horizontal position of an element	</td>
</tr>
<tr>
<td width="10%">	getElementPositionTop(&#8221;Locator&#8221;)	</td>
<td>	Retrieves the vertical position of an element	</td>
</tr>
<tr>
<td width="10%">	getElementWidth(&#8221;Locator&#8221;)	</td>
<td>	Retrieves the width of an element	</td>
</tr>
<tr>
<td width="10%">	getEval(&#8221;JS Expression&#8221;)	</td>
<td>	Gets the result of evaluating the specified JavaScript snippet.	</td>
</tr>
<tr>
<td width="10%">	getLocation()	</td>
<td>	Gets the absolute URL of the current page.	</td>
</tr>
<tr>
<td width="10%">	getMouseSpeed()	</td>
<td>	Returns the number of pixels between &#8220;mousemove&#8221; events during dragAndDrop commands (default=10).	</td>
</tr>
<tr>
<td width="10%">	getPrompt()	</td>
<td>	Retrieves the message of a JavaScript question prompt dialog generated during the previous action.	</td>
</tr>
<tr>
<td width="10%">	getSelectedId(&#8221;Select Locator&#8221;)	</td>
<td>	Gets option element ID for selected option in the specified select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedIds(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option element IDs for selected options in the specified select or multi-select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedIndex(&#8221;Select Locator&#8221;)	</td>
<td>	Gets option index (option number, starting at 0) for selected option in the specified select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedIndexes(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedLable(&#8221;Select Locator&#8221;)	</td>
<td>	Gets option label (visible text) for selected option in the specified select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedLables(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option labels (visible text) for selected options in the specified select or multi-select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedValue(&#8221;Select Locator&#8221;)	</td>
<td>	Gets option value (value attribute) for selected option in the specified select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectedValues(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option values (value attributes) for selected options in the specified select or multi-select element.	</td>
</tr>
<tr>
<td width="10%">	getSelectOptions(&#8221;Select Locator&#8221;)	</td>
<td>	Gets all option labels in the specified select drop-down.	</td>
</tr>
<tr>
<td width="10%">	getSpeed()	</td>
<td>	Get execution speed (i.e., get the millisecond length of the delay following each selenium operation).	</td>
</tr>
<tr>
<td width="10%">	getTable(&#8221;Table Cell Address”)	</td>
<td>	Gets the text from a cell of a table.	</td>
</tr>
<tr>
<td width="10%">	getText(&#8221;Locator&#8221;)	</td>
<td>	Gets the text of an element.	</td>
</tr>
<tr>
<td width="10%">	getTitle()	</td>
<td>	Gets the title of the current page.	</td>
</tr>
<tr>
<td width="10%">	getValue(&#8221;Locator&#8221;)	</td>
<td>	Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).	</td>
</tr>
<tr>
<td width="10%">	get Whether This Frame MatchFrameExpression(&#8221;Current Frame&#8221;,&#8221;Target&#8221;)	</td>
<td>	Determine whether current/locator identify the frame containing this running code	</td>
</tr>
<tr>
<td width="10%">	get Whether This Window MatchWindowExpression(&#8221;CurrentWindow&#8221;,&#8221;Target&#8221;)	</td>
<td>	Determine whether currentWindow String plus target identify the window containing this running code.	</td>
</tr>
<tr>
<td width="10%">	goBack()	</td>
<td>	Simulates the user clicking the &#8220;back&#8221; button on their browser.	</td>
</tr>
<tr>
<td width="10%">	highlight(&#8221;Locator&#8221;)	</td>
<td>	Briefly changes the backgroundColor of the specified element yellow.	</td>
</tr>
<tr>
<td width="10%">	isAlertPresent()	</td>
<td>	Has an alert occurred?	</td>
</tr>
<tr>
<td width="10%">	isChecked(&#8221;Locator&#8221;)	</td>
<td>	Gets whether a toggle-button (checkbox/radio) is checked.	</td>
</tr>
<tr>
<td width="10%">	isConfirmationPresent()	</td>
<td>	Has confirm() been called?	</td>
</tr>
<tr>
<td width="10%">	isEditable(&#8221;Locator&#8221;)	</td>
<td>	Determines whether the specified input element is editable, ie hasn&#8217;t been disabled.	</td>
</tr>
<tr>
<td width="10%">	isElementPresent(&#8221;Locator&#8221;)	</td>
<td>	Verifies that the specified element is somewhere on the page.	</td>
</tr>
<tr>
<td width="10%">	isPromptPresent()	</td>
<td>	Has a prompt occurred?	</td>
</tr>
<tr>
<td width="10%">	isSomethingSelected(&#8221;Locator&#8221;)	</td>
<td>	Determines whether some option in a drop-down menu is selected.	</td>
</tr>
<tr>
<td width="10%">	isTextPresent(&#8221;Pattern&#8221;)	</td>
<td>	Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.	</td>
</tr>
<tr>
<td width="10%">	isVisible(&#8221;Locator&#8221;)	</td>
<td>	Determines if the specified element is visible.	</td>
</tr>
<tr>
<td width="10%">	open(&#8221;URL&#8221;)	</td>
<td>	Opens an URL in the test frame.	</td>
</tr>
<tr>
<td width="10%">	openWindow(&#8221;URL&#8221;,&#8221;WindowID&#8221;)	</td>
<td>	Opens a popup window (if a window with that ID isn&#8217;t already open).	</td>
</tr>
<tr>
<td width="10%">	refresh()	</td>
<td>	Simulates the user clicking the &#8220;Refresh&#8221; button on their browser.	</td>
</tr>
<tr>
<td width="10%">	removeAllSelections(&#8221;Locator&#8221;)	</td>
<td>	Unselects all of the selected options in a multi-select element.	</td>
</tr>
<tr>
<td width="10%">	removeSelection(&#8221;Locator&#8221;,&#8221;Option Locator&#8221;)	</td>
<td>	Remove a selection from the set of selected options in a multi-select element using an option locator.	</td>
</tr>
<tr>
<td width="10%">	select(&#8221;Select Locator&#8221;,&#8221;Option Locator&#8221;)	</td>
<td>	Select an option from a drop-down using an option locator.	</td>
</tr>
<tr>
<td width="10%">	selectFrame(&#8221;Locator&#8221;)	</td>
<td>	Selects a frame within the current window.	</td>
</tr>
<tr>
<td width="10%">	selectWindow(&#8221;WindowID&#8221;)	</td>
<td>	Selects a popup window; once a popup window has been selected, all commands go to that window.	</td>
</tr>
<tr>
<td width="10%">	setSpeed(&#8221;Value&#8221;)	</td>
<td>	Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation).	</td>
</tr>
<tr>
<td width="10%">	setTimeout(&#8221;Time&#8221;)	</td>
<td>	Specifies the amount of time that Selenium will wait for actions to complete.	</td>
</tr>
<tr>
<td width="10%">	start()	</td>
<td>	Launches the browser with a new Selenium session 	</td>
</tr>
<tr>
<td width="10%">	stop()	</td>
<td>	Ends the test session, killing the browser	</td>
</tr>
<tr>
<td width="10%">	submit(&#8221;Form Locator&#8221;)	</td>
<td>	Submit the specified form.	</td>
</tr>
<tr>
<td width="10%">	type(&#8221;Locator&#8221;,&#8221;Value&#8221;)	</td>
<td>	Sets the value of an input field, as though you typed it in.	</td>
</tr>
<tr>
<td width="10%">	unCheck(&#8221;Locator&#8221;)	</td>
<td>	Uncheck a toggle-button (checkbox/radio)	</td>
</tr>
<tr>
<td width="10%">	waitForCondition(&#8221;JavaScript&#8221;,&#8221;Timeout&#8221;)	</td>
<td>	Runs the specified JavaScript snippet repeatedly until it evaluates to &#8220;true&#8221;.	</td>
</tr>
<tr>
<td width="10%">	waitForFrameToLoad(&#8221;Frame Address&#8221;,&#8221;Timeout&#8221;)	</td>
<td>	Waits for a new frame to load.	</td>
</tr>
<tr>
<td width="10%">	waitForPageToLoad(&#8221;Timeout&#8221;)	</td>
<td>	Waits for a new page to load.	</td>
</tr>
<tr>
<td width="10%">	waitForPopUp(&#8221;WindowID&#8221;,&#8221;Timeout&#8221;)	</td>
<td>	Waits for a popup window to appear and load up.	</td>
</tr>
<tr>
<td width="10%">	windowFocus()	</td>
<td>	Gives focus to the currently selected window	</td>
</tr>
<tr>
<td width="10%">	windowMaximize()	</td>
<td>	Resize currently selected window to take up the entire screen	</td>
</tr>
</table>
<p>  </body><br />
</html></p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=100</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=100</feedburner:origLink></item>
		<item>
		<title>setting system time :: vugen</title>
		<link>http://feedproxy.google.com/~r/mishmashmoo/~3/PE3hPuC02ig/</link>
		<comments>http://mishmashmoo.com/blog/?p=88#comments</comments>
		<pubDate>Fri, 06 Nov 2009 00:13:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mishmashmoo.com/blog/?p=88</guid>
		<description><![CDATA[Quite often I get personally contacted by people requiring some assistance or just wanting to ask me for my advice. It&#8217;s a nice ego boost, but also a very important aspect of the industry that should be maintained. My beliefs are we should do what we can to assist others, and with the use of [...]]]></description>
			<content:encoded><![CDATA[<p>Quite often I get personally contacted by people requiring some assistance or just wanting to ask me for my advice. It&#8217;s a nice ego boost, but also a very important aspect of the industry that should be maintained. My beliefs are we should do what we can to assist others, and with the use of the internet, we have a great medium to share and distribute information, with such things like twitter, Google talk and, well my blog, are all making it possible for a total stranger to speak to another and get the help he/she needs.</p>
<p>Recently, a now friend of mine, Roberto Brusa struck up a conversation about changing the system time in vugen. He was making a system call, which is fine, its a great way to do it, but he did mention that he did not want the annoying cmd pop up and probed me for a possible alternative. Now I&#8217;ve never done this before but after bouncing ideas off each other I suggested that in theory, it should be possible, through the usage of the win32api, to manipulate the tme&#8230;We found that this statment was true, and proved it with the following&#8230;<br />
<span id="more-88"></span><br />
Not many performance testers know about this little trick, but I have used it a few times. its the <strong>lr_load_dll()</strong> function. It allows you to load a dll into your <strong>vuser_init()</strong>, and once loaded, you can call any function that is inside that dll anytime in your script.<br />
The hardest part, is finding out what the dll does, what functions can be called, and the format in which they must be placed. A quick Google search should solve your issues, or jump on the msdn. </p>
<p>Now, the <strong>kernel32.dll</strong> is responsible for setting the system time, as well as many other things, and explicitly calling <strong>SetSystemTime</strong> allows full manipulation. With this information and some intuitive Google searching from Roberto and I, collectively we managed to come up with this script, which sets the system time to whatever you want, right down to the millisecond!. </p>
<p><strong>vuser init</strong><br />
note: I declare all my variables before the vuser_init function, for neatness.</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">double</span> atof <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span>;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> _SYSTEMTIME <span style="color: #009900;">&#123;</span>
  WORD wYear;
  WORD wMonth;
  WORD wDayOfWeek;
  WORD wDay;
  WORD wHour;
  WORD wMinute;
  WORD wSecond;
  WORD wMilliseconds;
<span style="color: #009900;">&#125;</span>SYSTEMTIME, <span style="color: #339933;">*</span>PSYSTEMTIME;
vuser_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   lr_load_dll<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;kernel32.dll&quot;</span><span style="color: #009900;">&#41;</span>;
   <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Action</strong><br />
Set your values, and call the function&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="c">Action<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   SYSTEMTIME st;
   st.<span style="color: #202020;">wYear</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2000</span>;
   st.<span style="color: #202020;">wMonth</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span>;
   st.<span style="color: #202020;">wDay</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">12</span>;
   st.<span style="color: #202020;">wHour</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">16</span>;
   st.<span style="color: #202020;">wMinute</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">8</span>;
   st.<span style="color: #202020;">wSecond</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">31</span>;
   st.<span style="color: #202020;">wMilliseconds</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">55</span>;
&nbsp;
   <span style="color: #666666; font-style: italic;">//call the function for the dll, parsing the input value of st paramater</span>
   SetSystemTime<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>st<span style="color: #009900;">&#41;</span>;
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Use it at your will!<br />
Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://mishmashmoo.com/blog/?feed=rss2&amp;p=88</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://mishmashmoo.com/blog/?p=88</feedburner:origLink></item>
	</channel>
</rss>

