<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SHpartners / myFMbutler Blog &#187; DoSQL</title>
	<atom:link href="http://blog.myfmbutler.com/?feed=rss2&#038;cat=17" rel="self" type="application/rss+xml" />
	<link>http://blog.myfmbutler.com</link>
	<description>FileMaker Tips &#038; Tricks</description>
	<lastBuildDate>Mon, 30 Aug 2010 10:02:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>DoSQL 1.4 for FileMaker Pro 11 released</title>
		<link>http://blog.myfmbutler.com/?p=677</link>
		<comments>http://blog.myfmbutler.com/?p=677#comments</comments>
		<pubDate>Tue, 10 Aug 2010 11:36:41 +0000</pubDate>
		<dc:creator>info</dc:creator>
				<category><![CDATA[DoSQL]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=677</guid>
		<description><![CDATA[This is a simultaneous release of DoSQL 1.4 for FileMaker Pro 11 and DoSQL 1.3.1 for FileMaker Pro 10 and earlier. Version 1.3.1 uses the older FileMaker SQL engine, version 1.4 uses the new engine in FileMaker Pro 11. About some of the changes in this version: 1.4 solves the problems under FileMaker 11 with [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simultaneous release of <strong><em>DoSQL 1.4 for FileMaker Pro 11</em></strong> and <strong><em>DoSQL 1.3.1 for FileMaker Pro 10</em></strong> and earlier.<br />
Version 1.3.1 uses the older FileMaker SQL engine, version 1.4 uses the new engine in FileMaker Pro 11.</p>
<p>About some of the changes in this version:</p>
<li>1.4 solves the problems under FileMaker 11 with SQL statements that feed the result of a SELECT into an INSERT
<li>Fields starting with an underscore "_" have to be quoted<br />
	e.g. mFMb_DoSQL ( "select \"_k1\" from myTable" )</p>
<li>Number values cannot be quoted: if you have a number field, you cannot write or update it with a single-quoted value. '1' is forbidden, 1 is OK. Use NULL for empty fields.
<li>Date, time and timestamp fields have to be casted. Simply single quoting a date doesn't work anymore. It's good practice to replace a single quoted date with<br />
"CAST ( " & mFMb_DoSQL_Quote ( Year ( theParameter ) & "-" & Month ( theParameter ) & "-" & Day ( theParameter) ) & " AS DATE )" in a custom function.</p>
<li>Error reporting with the new engine is different. The new engine now returns error values 8309, 8310 and sometimes a few others. The first indicating a semantics error, the other a syntax error. There is also additional error reporting in the FM11 SQL engine. You can get that information using the mFMb_DoSQL_lastresult function. A list of the possible FQL errors is included in the DoSQL download.
<li>For more details about the new SQL engine and the SQL statements that are supported, please refer to the FileMaker documentation available <a href="http://www.filemaker.com/support/product/docs/fmp/fm11_odbc_jdbc_guide_en.pdf">here</a>.
<p>More information is available on the <a href="http://myfmbutler.com/index.lasso?p=425">DoSQL product page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=677</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining the internal date format</title>
		<link>http://blog.myfmbutler.com/?p=495</link>
		<comments>http://blog.myfmbutler.com/?p=495#comments</comments>
		<pubDate>Tue, 29 Sep 2009 11:32:50 +0000</pubDate>
		<dc:creator>Koen Van Hulle</dc:creator>
				<category><![CDATA[DoSQL]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=495</guid>
		<description><![CDATA[Last week I had an interesting discussion with Kevin Frank. We were trying to figure out what would be the best way to insert or update dates when using the myFMbutler DoSQL plug-in. Before we go and look at the solution, let’s give you a little bit of background about how the plug-in works. When [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.myfmbutler.com/wp-content/uploads/2009/09/date_001.jpg" alt="date_001" title="date_001" width="446" height="335" class="alignnone size-full wp-image-499" /></p>
<p>Last week I had an interesting discussion with <a href="http://www.kevinfrank.com" target="_blank">Kevin Frank</a>.<br />
We were trying to figure out what would be the best way to insert or update dates when using the myFMbutler DoSQL plug-in.</p>
<p><span id="more-495"></span></p>
<p>Before we go and look at the solution, let’s give you a little bit of background about how the plug-in works. When entering date and time values, you must match the format of the database file locale. This is the system format used on the machine where the file was created.<br />
For example, if the database was created on a Belgian system, you would need to use the Belgian date and time format.</p>
<p>There can be a big difference between the format returned from a calculation by the calculation engine and the format that will be required for the plug-in environment.</p>
<p><strong>An Example</strong><br />
Let’s pretend we have created a file on a machine with a US system and we want to use the file in an international environment, so Europeans can view and enter the dates in their own date format. To do so we will set the following File Option: “Always use current system settings”.</p>
<p><img src="http://blog.myfmbutler.com/wp-content/uploads/2009/09/date_002.png" alt="date_002" title="date_002" width="475" height="444" class="alignnone size-full wp-image-500" /><br />
￼<br />
<em>US System</em><br />
<code>Date(1 ; 31 ; 2010)</code> returns 01-31-2010 (MM-DD-YYYY)<br />
Format required for INSERT or UPDATE: <code>{01-31-2010} {MM-DD-YYYY}</code></p>
<p><em>Belgian System</em><br />
<code>Date(1 ; 31 ; 2010)</code> returns 31-01-2010 (DD-MM-YYYY)<br />
Format required for INSERT or UPDATE:<code> {01-31-2010} {MM-DD-YYYY}</code></p>
<p>On both systems, you need the use the US format when using the plug-in.</p>
<p>But if the file was originally created on a Belgian system, the situation would be different:</p>
<p><em>US System</em><br />
<code>Date(1 ; 31 ; 2010)</code> returns 01-31-2010 (MM-DD-YYYY)<br />
Format required for INSERT or UPDATE: <code>{31-01-2010} {DD-MM-YYYY}</code></p>
<p><em>Belgian System</em><br />
<code>Date(1 ; 31 ; 2010)</code> returns 31-01-2010 (DD-MM-YYYY)<br />
Format required for INSERT or UPDATE: <code>{31-12-2010} {DD-MM-YYYY}</code></p>
<p>An additional problem that may arise is when a user makes an empty clone or a recovered version of your file. When making an empty clone or when recovering a file, the original system formats will be removed. The first system that opens the new file, will save its system format to the file.</p>
<p>Say you have a solution that was originally created on a US system, and all DoSQL statements in that solution are using the {MM-DD-YYYY} format, if a Belgian user makes an empty clone of your solution and opens it on his machine, the solution will break.</p>
<p><strong>Determine the Date Format</strong><br />
You can determine the file’s date format with the following calculation:</p>
<p><code>Case (<br />
not EvaluationError(mFMb_DoSQL("SELECT {1/31/2010}")); "MMDDYYYY" ;<br />
not EvaluationError(mFMb_DoSQL("SELECT {31/1/2010}")); "DDMMYYYY";<br />
not EvaluationError(mFMb_DoSQL("SELECT {2010/31/1}")); "YYYYMMDD";<br />
not EvaluationError(mFMb_DoSQL("SELECT {2010/1/31}")); "YYYYDDMM";<br />
"????????"<br />
)</code></p>
<p><strong>Solution number two</strong><br />
Another way to insert or update a Date, is by using the DATE function. When you use the date function, you must always use the ISO format YYYY-MM-DD.</p>
<p><code>UPDATE FROM table SET myDateField = DATE ‘2009-01-31’;</code></p>
<p><strong>Bonus: Determining the Decimal separator</strong><br />
Another problem that you can face in International projects is to determine the decimal separator. There is an easy calculation for that:</p>
<p><code>Middle( PI ; 2; 1)</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=495</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enhanced Changelogs with DoSQL</title>
		<link>http://blog.myfmbutler.com/?p=341</link>
		<comments>http://blog.myfmbutler.com/?p=341#comments</comments>
		<pubDate>Wed, 29 Apr 2009 09:40:24 +0000</pubDate>
		<dc:creator>info</dc:creator>
				<category><![CDATA[DoSQL]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=341</guid>
		<description><![CDATA[For this week's blog article, we want to extend a special thanks to Kevin Frank and Dave Walton who sent us the example. When using DoSQL to create a ChangeLog of your records, you want to avoid creating log records when nothing has actually changed. The trick is to prevent DoSQL from firing unless you [...]]]></description>
			<content:encoded><![CDATA[<p>For this week's blog article, we want to extend a special thanks to <a href="http://www.kevinfrank.com/" target="_blank">Kevin Frank</a> and <a href="http://www.coredbs.com/" target="_blank">Dave Walton</a> who sent us the example.</p>
<p>When using DoSQL to create a ChangeLog of your records, you want to avoid creating log records when nothing has actually changed.</p>
<p>The trick is to prevent DoSQL from firing unless you want to log a change... take a look at the example and check the validation on _K in the Data table... basically, if the parent sees that nothing has changed since the last corresponding ChangeLog record was created, then doSQL won't trigger.</p>
<div style="text-align:center;"><img src="http://blog.myfmbutler.com/wp-content/uploads/2009/04/dosqlchangelog-2.png" alt="DoSQLChangeLog-2.png" border="0" width="450" height="173" /></div>
<p>Note that if you have no ChangeLog record for a given parent record, then it will be created *regardless* of which parent field you edit, but... once you have at least one change log record for a given parent, then any "don't log" fields will be respected.</p>
<p>The thing I like about this technique is that ChangeLog records will be created when a Replace is performed and when parent records are imported.</p>
<p><a href="http://blog.myfmbutler.com/wp-content/uploads/2009/04/dosql-changelog.zip" title="DoSQL ChangeLog.zip">DoSQL ChangeLog Example</a></p>
<p><a href="http://myfmbutler.com/downloads">DoSQL Plug-in download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=341</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New DoSQL 1.2 allows for more universal SQL calculations</title>
		<link>http://blog.myfmbutler.com/?p=310</link>
		<comments>http://blog.myfmbutler.com/?p=310#comments</comments>
		<pubDate>Thu, 05 Feb 2009 10:04:46 +0000</pubDate>
		<dc:creator>info</dc:creator>
				<category><![CDATA[DoSQL]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=310</guid>
		<description><![CDATA[We just released version 1.2 of our DoSQL plug-in. This new version provides a new function: mFMb_DoSQL_QuoteField( fieldname ) The function converts "FileMaker-style" syntax like my Table::my Field to SQL syntax like "my Table.my Field" (with quotes). The nice thing about this is that it allows you to double-click a field to insert it in [...]]]></description>
			<content:encoded><![CDATA[<p>We just released version 1.2 of our <a href="http://myfmbutler.com/dosql" target="_blank">DoSQL plug-in</a>.</p>
<p>This new version provides a new function:</p>
<blockquote><p>mFMb_DoSQL_QuoteField( fieldname )</p></blockquote>
<p>The function converts "FileMaker-style" syntax like my Table::my Field to SQL syntax like "my Table.my Field" (with quotes). The nice thing about this is that it allows you to double-click a field to insert it in a calculation.</p>
<div style="text-align:center;"><img src="http://blog.myfmbutler.com/wp-content/uploads/2009/02/dosqlcalc.png" alt="DoSQLCalc.png" border="0" width="430" height="113" /></div>
<p>Combined with FileMaker Pro 10’s new ‘GetFieldname’ function, this allows you to make the SQL statements much more universal.</p>
<p>Download <a href="http://blog.myfmbutler.com/wp-content/uploads/2009/02/newdosql.zip" title="newDoSQL.zip"> this example</a> for more details on how this can be used (make sure you have version 1.2 of the DoSQL plug-in installed)</p>
<p>Although the use of spaces in field names is not recommended, this solution will continue to function properly if you do use spaces.</p>
<p><a href="http://myfmbutler.com/index.lasso?p=359">Download DoSQL 1.2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=310</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>myFMbutler products and FileMaker 10 compatibility</title>
		<link>http://blog.myfmbutler.com/?p=285</link>
		<comments>http://blog.myfmbutler.com/?p=285#comments</comments>
		<pubDate>Fri, 09 Jan 2009 12:14:25 +0000</pubDate>
		<dc:creator>info</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[AutoSender]]></category>
		<category><![CDATA[Clip Manager]]></category>
		<category><![CDATA[DoSQL]]></category>
		<category><![CDATA[DoScript]]></category>
		<category><![CDATA[PrinterSwitch]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=285</guid>
		<description><![CDATA[We wanted to give everyone an update on the compatibility status of our products with FileMaker 10: Initial testing of our plug-ins (DoSQL, DoScript, PrinterSwitch), have not shown any compatibility issues with the FileMaker 10 platform. AutoSender 2.5 also seems to work fine with FileMaker Server 10, although we'll be providing a small update that [...]]]></description>
			<content:encoded><![CDATA[<p>We wanted to give everyone an update on the compatibility status of our products with FileMaker 10:</p>
<p>Initial testing of our plug-ins (<strong>DoSQL, DoScript, PrinterSwitch</strong>), have not shown any compatibility issues with the FileMaker 10 platform.</p>
<p><strong>AutoSender 2.5</strong> also seems to work fine with FileMaker Server 10, although we'll be providing a small update that will integrate a new JDBC driver by February.</p>
<p><strong>Clip Manager 3</strong> does have some issues for people trying to 'Get' or 'Set' a custom function with FileMaker Pro 10 Advanced. We will be releasing version 3.1 later this month. This version will also provide a number of other fixes.</p>
<p>We also recently found issues (unrelated to FM10) when using the '<strong>Copy to Clip Manager</strong>' function on Brian Dunning's <a href="http://www.briandunning.com/filemaker-custom-functions/list.php" target=_blank>CF web site</a>. Starting with a certain build of Flash 9 and all builds of Flash 10, the copying no longer works. We are currently working on a fix and hope to provide it by next week (actually, we already fixed it today).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=285</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DoSQL 1.1 just released</title>
		<link>http://blog.myfmbutler.com/?p=233</link>
		<comments>http://blog.myfmbutler.com/?p=233#comments</comments>
		<pubDate>Tue, 26 Aug 2008 08:39:52 +0000</pubDate>
		<dc:creator>info</dc:creator>
				<category><![CDATA[DoSQL]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=233</guid>
		<description><![CDATA[We just released an update to our DoSQL plug-in. We added a couple of new functions: DoSQL_LastErrNum, DoSQL_LastResult and DoSQL_LastSQL are three new functions that will make it easier to add improved error trapping to your DoSQL solutions We added a "VersionAutoUpdate" function that was recently agreed upon by a group of FileMaker plug-in developers [...]]]></description>
			<content:encoded><![CDATA[<p>We just released an update to our DoSQL plug-in.</p>
<div style="text-align:center;"><img src="http://blog.myfmbutler.com/wp-content/uploads/2008/08/dosqlfunctions1.png" alt="DoSQLfunctions.png" border="0" width="228" height="185" /></div>
<p>We added a couple of new functions:</p>
<li> DoSQL_LastErrNum, DoSQL_LastResult and DoSQL_LastSQL are three new functions that will make it easier to add improved error trapping to your DoSQL solutions
<li> We added a "VersionAutoUpdate" function that was recently agreed upon by a group of FileMaker plug-in developers - the purpose of this function is to provide a unified way to use FMS AutoUpdate in your solutions.
<p>More information about DoSQL is available on the <a href="http://myfmbutler.com/dosql/">product page</a>.</p>
<p>Download the latest update <a href="http://myfmbutler.com/downloads/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=233</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A spotlight-like Portal Filter with DoSQL Plug-in: Part III</title>
		<link>http://blog.myfmbutler.com/?p=141</link>
		<comments>http://blog.myfmbutler.com/?p=141#comments</comments>
		<pubDate>Tue, 18 Dec 2007 07:53:50 +0000</pubDate>
		<dc:creator>Koen Van Hulle</dc:creator>
				<category><![CDATA[Custom Functions]]></category>
		<category><![CDATA[DoSQL]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=141</guid>
		<description><![CDATA[In the previous posts about this topic, we created a spotlight-like portal filter with the DoSQL plug-in. Last time we created a custom function to simplify the implementation. This time we will enhance that custom function so you can implement a spotlight-like portal filter in your solution without the need of any SQL knowledge. Download [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://blog.myfmbutler.com/wp-content/uploads/2007/12/portalfilter3_0_000.jpg'  /></p>
<p>In the previous posts about this topic, we created a spotlight-like portal filter with the DoSQL plug-in.<br />
Last time we created a custom function to simplify the implementation.<br />
This time we will enhance that custom function so you can implement a spotlight-like portal filter in your solution without the need of any SQL knowledge.</p>
<p><span id="more-141"></span></p>
<p>Download the myFMbutler DoSQL plug-in <a href="http://www.myfmbutler.com/index.lasso?p=359" target="_blank">here</a>.<br />
If you have not read the previous post, you can do it <a href="http://blog.myfmbutler.com/?p=80">here.</a></p>
<p><strong>Scenario</strong><br />
In our first article, we were searching for all records that CONTAIN our condition. To obtain this we used the % wild card before and after the condition. The search criterion "an" will return "an", "anna" and "jan".<br />
Wouldn't it be nice, if could extend this with other search options like "begins with", "ends with" and "literal" ?</p>
<p><strong>Step 1: The LIKE condition</strong><br />
The LIKE condition is used to specify a search for a pattern. % is a wild card and can be used both before and after the pattern.</p>
<p><em>"Contains" example</em><br />
<code>SELECT id FROM contact WHERE firstname LIKE '%an%'</code><br />
The search criterion "an" will return "an", "anna" and "jan".</p>
<p><em>"Begins with" example</em><br />
<code>SELECT id FROM contact WHERE firstname LIKE 'an%'</code><br />
The search criterion "an" will only return "an" and "anna".</p>
<p><em>"Ends with" example</em><br />
<code>SELECT id FROM contact WHERE firstname LIKE '%an'</code><br />
The search criterion "an" will only return "an" and "jan".</p>
<p><em>"Literal" example</em><br />
<code>SELECT id FROM contact WHERE firstname LIKE 'an'</code><br />
The search criterion "an" will only return "an".</p>
<p><strong>Step 2: The custom function</strong><br />
Now we are going change our custom function, and add an extra parameter "condition".</p>
<p><code>mfb_DoSQLPortalFilter( theTablename; theIDname ; theFields; theFilter ; theCondition )</code></p>
<p>In our example it will look like:<br />
<code>mfb_DoSQLPortalFilter( "contact"; "id" ; "firstname¶lastname¶"; "an" ; "contains" )</code><br />
This function will return the SQL statement:<br />
<code>SELECT id FROM contact WHERE lower(firstname) LIKE '%an%' OR lower(lastname) LIKE '%an%'</code></p>
<p>And the function:<br />
<code>mfb_DoSQLPortalFilter( "contact"; "id" ; "firstname¶lastname¶"; "an" ; "begins with" )</code><br />
will return:<br />
<code>SELECT id FROM contact WHERE lower(firstname) LIKE 'an%' OR lower(lastname) LIKE 'an%'</code></p>
<p><a href='http://blog.myfmbutler.com/wp-content/uploads/2007/12/mfb_dosqlportalfilter.zip' title='Custom Function'>Download the custom function as a myFMbutler Clip Manager Clip.</a><br />
<a href='http://blog.myfmbutler.com/wp-content/uploads/2007/12/07_portalfilter.zip' title='Example file'>Download the example file.</a></p>
<p>Now the custom function is ready and can easily be implemented in your solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=141</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display a running clock using DoSQL &amp; conditional formatting</title>
		<link>http://blog.myfmbutler.com/?p=112</link>
		<comments>http://blog.myfmbutler.com/?p=112#comments</comments>
		<pubDate>Mon, 12 Nov 2007 10:50:56 +0000</pubDate>
		<dc:creator>Luk Dhondt</dc:creator>
				<category><![CDATA[Conditional Formatting]]></category>
		<category><![CDATA[DoSQL]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=112</guid>
		<description><![CDATA[This is a simple example that demonstrates how to use conditional formatting with the myFMbutler DoSQL plug-in in order to display a running clock in FileMaker. This example requires that the DoSQL plug-in be installed. You can download DoSQL here. Download the Clock example]]></description>
			<content:encoded><![CDATA[<p>This is a simple example that demonstrates how to use conditional formatting with the myFMbutler DoSQL plug-in in order to display a running clock in FileMaker.</p>
<p>This example requires that the <a href="http://myfmbutler.com/index.lasso?p=425">DoSQL plug-in</a> be installed. You can download DoSQL <a href="http://myfmbutler.com/index.lasso?p=359">here</a>.</p>
<p><a href='http://blog.myfmbutler.com/wp-content/uploads/2007/11/clock.zip' title='Download Clock.zip'>Download the Clock example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=112</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A spotlight-like Portal Filter with the DoSQL plug-in &#8211; part II</title>
		<link>http://blog.myfmbutler.com/?p=80</link>
		<comments>http://blog.myfmbutler.com/?p=80#comments</comments>
		<pubDate>Tue, 09 Oct 2007 07:18:14 +0000</pubDate>
		<dc:creator>Koen Van Hulle</dc:creator>
				<category><![CDATA[Custom Functions]]></category>
		<category><![CDATA[DoSQL]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=80</guid>
		<description><![CDATA[A couple of weeks ago, we showed you how to create a spotlight-like portal filter using the DoSQL plugin. At the same time it was an example of how you can implement an OR relationship, without overloading your database with complex calculations. This time we are going to expand the demo with a powerful search [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter2_0_000.jpg' alt='Portal Filter' /></p>
<p>A couple of weeks ago, we showed you how to create a spotlight-like portal filter using the DoSQL plugin. At the same time it was an example of how you can implement an OR relationship, without overloading your database with complex calculations.<br />
This time we are going to expand the demo with a powerful search option.</p>
<p><span id="more-80"></span></p>
<p>Download the myFMbutler DoSQL plug-in <a href="http://www.myfmbutler.com/index.lasso?p=359">here</a>.<br />
If you have not read the original post, <a href="http://blog.myfmbutler.com/?p=47">you can do it here</a>. </p>
<p><strong>Scenario</strong><br />
Our FileMaker solution contains a table with contacts. We want to create a spotlight-like portal filter where we can search by first name OR by last name OR by state OR by county. This time we want the user to be able to choose which fields to search, similar to the search options of e.g. Mail.app.</p>
<p><img src='http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter2_0_001.jpg' alt='Mail' /></p>
<p><strong>Step 1</strong><br />
<a href="http://blog.myfmbutler.com/?p=47">Download</a> the example file of part 1 of this post.<br />
To enable a search only on selected fields, we create a value list "Fields" and populate them with the values: First Name, Last Name, State, County.</p>
<p><img src='http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter2_1_001.jpg' alt='Portal Filter' /></p>
<p>In the table "portalfilter" we create a new global text field "fields" and add it onto the layout.</p>
<p><img src='http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter2_1_002.jpg' alt='portalfilter2_1_002' /></p>
<p><a href='http://blog.myfmbutler.com/wp-content/uploads/2007/09/04_portalfilter.zip' title='04_PortalFilter.zip'>Download step 1</a></p>
<p><strong>Step 2</strong><br />
In the second step we are going to figure out which fields we have to search.  Let's change the calculation of the field IDs:</p>
<p><code>Let<br />
(<br />
[<br />
theNumberofFields = ValueCount(fields)<br />
;<br />
searchField1 = GetValue(fields ; 1)<br />
;<br />
searchField2 = GetValue(fields ; 2)<br />
;<br />
searchField3 = GetValue(fields ; 3)<br />
;<br />
searchField4 = GetValue(fields ; 4)<br />
;<br />
searchFieldName1 =  Case(searchField1 = "First Name" ;  "firstname" ; searchField1 = "Last Name" ;  "lastname" ; searchField1 = "State" ;  "state" ; searchField1 = "County" ;  "county" ; "")<br />
;<br />
searchFieldName2 =  Case(searchField2 = "First Name" ;  "firstname" ; searchField2 = "Last Name" ;  "lastname" ; searchField2 = "State" ;  "state" ; searchField2 = "County" ;  "county" ; "")<br />
;<br />
searchFieldName3 =  Case(searchField3 = "First Name" ;  "firstname" ; searchField3 = "Last Name" ;  "lastname" ; searchField3 = "State" ;  "state" ; searchField3 = "County" ;  "county" ; "")<br />
;<br />
searchFieldName4 =  Case(searchField4 = "First Name" ;  "firstname" ; searchField4 = "Last Name" ;  "lastname" ; searchField4 = "State" ;  "state" ; searchField4 = "County" ;  "county" ; "")</p>
<p>...<br />
</code></p>
<p>This could be implemented more elegantly with a recursive custom function, but for now let's leave it like this. The next thing we have to do, is to change our SQL statement:</p>
<p><code>...<br />
theRowSeparator = mFMb_DoSQL_SetRowSeparator( 13 ) // Return<br />
;<br />
theSQL = "SELECT id FROM contact"<br />
;<br />
theSQL = theSQL & If(not IsEmpty(filter) and  theNumberofFields>0 ; " WHERE " )<br />
;<br />
theSQL = theSQL & If(not IsEmpty(filter) and theNumberofFields >0 ; "lower(" & searchFieldName1 & ") LIKE " & mFMb_DoSQL_Quote( "%" & Lower(filter) & "%" ) )<br />
;<br />
theSQL = theSQL & If(not IsEmpty(filter) and theNumberofFields >1; " OR lower(" & searchFieldName2 & ") LIKE " & mFMb_DoSQL_Quote( "%" & Lower(filter) & "%" ) )<br />
;<br />
theSQL = theSQL & If(not IsEmpty(filter) and theNumberofFields >2; " OR lower(" & searchFieldName3 & ") LIKE " & mFMb_DoSQL_Quote( "%" & Lower(filter) & "%" ) )<br />
;<br />
theSQL = theSQL & If(not IsEmpty(filter) and theNumberofFields >3; " OR lower(" & searchFieldName4 & ") LIKE " & mFMb_DoSQL_Quote( "%" & Lower(filter) & "%" ) )<br />
;<br />
theIDs = If( theNumberofFields  â  0 ; mFMb_DoSQL( theSql ) )<br />
]<br />
;<br />
theIDs<br />
)<br />
</code></p>
<p>If all fields are selected, the SQL statement will look like this:<br />
<code>SELECT id FROM contact WHERE lower(firstname) LIKE '%an%' OR lower(lastname) LIKE '%an%' OR lower(state) LIKE '%an%' OR lower(county) LIKE '%an%'</code></p>
<p>But, if only the field "firstname" is selected, the SQL statement will look like this:<br />
<code>SELECT id FROM contact WHERE lower(firstname) LIKE '%an%'</code></p>
<p><a href='http://blog.myfmbutler.com/wp-content/uploads/2007/09/05_portalfilter.zip' title='05_PortalFilter.zip'>Download step 2</a></p>
<p><strong>Step 3: Custom Function approach</strong><br />
In the previous steps we have changed the example file to add a search option for the fields. If you look at the calculation it's becoming complex. In this step we will create a <a href='http://blog.myfmbutler.com/wp-content/uploads/2007/10/mfb_dosqlportalfilter.zip' title='Custom Function: mfb_DoSQLPortalFilter'>custom function</a> that makes the implementation of this technique in other files much easier.</p>
<p><code>mfb_DoSQLPortalFilter( theTablename; theIDname ; theFields; theFilter ) </code></p>
<p>In our example it will look like:<br />
<code>mfb_DoSQLPortalFilter( "contact"; "id" ; "firstname¶lastname¶; "an" ) </code></p>
<p>This function will return the SQL statement:<br />
<code>SELECT id FROM contact WHERE lower(firstname) LIKE '%an%' OR lower(lastname) LIKE '%an%'</code></p>
<p>This custom function requires a list of field names, so we need to change the value list "fields". Create a new table with two text fields "fieldname" and "label". </p>
<p><img src='http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter2_3_001.jpg' alt='Portal Filter' /></p>
<p>Now we have to change the value list "fields":</p>
<p><img src='http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter2_3_002.jpg' alt='portalfilter2_3_002' /></p>
<p>The only thing we still need to do, is to change or formula of the field "IDs":<br />
<code>Let<br />
(<br />
[<br />
theRowSeparator = mFMb_DoSQL_SetRowSeparator( 13 ) // Return<br />
;<br />
theSQL =mfb_DoSQLPortalFilter ( "contact" ; "id" ; fields ; filter )<br />
;<br />
theIDs = mFMb_DoSQL( theSql )<br />
]<br />
;<br />
theIDs<br />
)<br />
</code></p>
<p><img src='http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter2_3_003.jpg' alt='Portal Filter' /></p>
<p><a href='http://blog.myfmbutler.com/wp-content/uploads/2007/10/06_portalfilter1.zip' title='06_PortalFilter.zip' title='06_PortalFilter.zip'>Download the example file.</a></p>
<p><a href='http://blog.myfmbutler.com/wp-content/uploads/2007/10/mfb_dosqlportalfilter.zip' title='Custom Function: mfb_DoSQLPortalFilter'>Download the custom function as myFMbutler Clip Manager Clip.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=80</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A spotlight-like Portal Filter with the DoSQL Plug-in &#8211; part I</title>
		<link>http://blog.myfmbutler.com/?p=47</link>
		<comments>http://blog.myfmbutler.com/?p=47#comments</comments>
		<pubDate>Tue, 11 Sep 2007 08:21:05 +0000</pubDate>
		<dc:creator>Koen Van Hulle</dc:creator>
				<category><![CDATA[DoSQL]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.myfmbutler.com/?p=47</guid>
		<description><![CDATA[Portal filters are sometimes tough to create. Some combinations are almost impossible to establish with standard FileMaker functionality. In the following example we will show you how you can implement a spotlight-like portal filter with the myFMbutler DoSQL plug-in. Download the myFMbutler DoSQL plug-in here. Scenario Our FileMaker solution contains a table with contact persons [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter_001.jpg" alt="Portalfilter_001" /></p>
<p>Portal filters are sometimes tough to create. Some combinations are almost impossible to establish with standard FileMaker functionality.</p>
<p>In the following example we will show you how you can implement a spotlight-like portal filter with the myFMbutler DoSQL plug-in.</p>
<p><span id="more-47"></span><br />
Download the myFMbutler DoSQL plug-in <a href="http://www.myfmbutler.com/index.lasso?p=359" target="_blank">here</a>.</p>
<p><strong>Scenario</strong><br />
Our FileMaker solution contains a table with contact persons (contacts). We want to create a spotlight-like portal filter where we can search on the first name or the last name or the state or the county.</p>
<p><strong>Step 1: Principle</strong><br />
The principle of this example is very simple. We create a text field 'IDs'. This field will contain the idâs of the records that will be shown in the portal.</p>
<p><img src="http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter_1_001.jpg" alt="portalfilter_1_001" /></p>
<p><img src="http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter_1_002.jpg" alt="portalfilter_1_002" /></p>
<p><a href="http://blog.myfmbutler.com/wp-content/uploads/2007/09/01_portalfilter.zip" title="Download step 1">Download step 1</a></p>
<p><strong>Step 2: the SELECT statement</strong><br />
Instead of manually typing in some id's, we will fill in the id's with the DoSQL plug-in. In this step we will ask FileMaker to return a list of all id's from the contacts table.<br />
To achieve this, we will use the SELECT statement. The SELECT statement is used to select data from a table. To select all id's from the contacts table, we will use the following statement:</p>
<p><code>SELECT id FROM contact</code></p>
<p>Change the field 'IDs' in the table âportaltableâ to an unstored calculation (TEXT) with the following formula:</p>
<p><code>Let<br />
(<br />
[<br />
theRowSeparator = mFMb_DoSQL_SetRowSeparator( 13 ) // Return;<br />
theSQL = "SELECT id FROM contact";<br />
theIDs = mFMb_DoSQL( theSql)<br />
]<br />
;<br />
theIDs<br />
)</code></p>
<p>mFMb_DoSQL_SetRowSeparator( 13 ) will set the return as row separator.mFMb_DoSQL() will execute the SQL-statement.</p>
<p><img src="http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter_2_001.jpg" alt="portalfilter_2_001" /></p>
<p><a href="http://blog.myfmbutler.com/wp-content/uploads/2007/09/02_portalfilter.zip" title="Download step 2">Download step 2</a></p>
<p><strong>Step 3: Add some filtering</strong><br />
If you explore the behavior of a spotlight search in Mail or in the Finder, you will notice that if no search criteria are defined all mails/files are shown. If you enter a search criterion all matching mails/files are shown. The search criterion "an" will return "an", "anna" and "jan".<br />
To achieve this we need to amend the SELECT statement.<br />
The 'where' clause needs to be added to the 'select' statement.</p>
<p><code>SELECT id FROM contact WHERE firstname LIKE '%an%' OR lastname LIKE '%an%' OR state LIKE '%an%' OR county LIKE '%an%'</code></p>
<p>% is a wild card and simalar to the * in FileMaker.<br />
Select statements are case sensitive. We can use the lower function to make it case insensitive:</p>
<p><code>SELECT id FROM contact WHERE lower(firstname) LIKE '%an%' OR lower(lastname) LIKE '%an%' OR lower(state) LIKE '%an%' OR lower(county) LIKE '%an%'</code></p>
<p>Add a new global text field "filter". This field will contain the search criterion.<br />
Change the calculation of the 'IDs' field:</p>
<p><code>Let<br />
(<br />
[<br />
theRowSeparator = mFMb_DoSQL_SetRowSeparator( 13 ) // Return;<br />
theSQL = "SELECT id FROM contact";<br />
theSQL = theSQL &amp; If(not IsEmpty(filter); " WHERE " );<br />
theSQL = theSQL &amp; If(not IsEmpty(filter); "lower(firstname) LIKE " &amp; mFMb_DoSQL_Quote( "%" &amp; Lower(filter) &amp; "%" ) );<br />
theSQL = theSQL &amp; If(not IsEmpty(filter); " OR lower(lastname) LIKE " &amp; mFMb_DoSQL_Quote( "%" &amp; Lower(filter) &amp; "%" ) );<br />
theSQL = theSQL &amp; If(not IsEmpty(filter); " OR lower(state) LIKE " &amp; mFMb_DoSQL_Quote( "%" &amp; Lower(filter) &amp; "%" ) );<br />
theSQL = theSQL &amp; If(not IsEmpty(filter); " OR lower(county) LIKE " &amp; mFMb_DoSQL_Quote( "%" &amp; Lower(filter) &amp; "%" ) );<br />
theIDs = mFMb_DoSQL( theSql )<br />
]<br />
;<br />
theIDs<br />
)</code></p>
<p>Now we are ready.</p>
<p><img src="http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter_3_001.jpg" alt="portalfilter_3_001" /></p>
<p><a href="http://blog.myfmbutler.com/wp-content/uploads/2007/09/portalfilter.zip" title="Download the example file.">Download the example file.</a></p>
<p><strong>Note:</strong> Another example of more complex portal filtering can be found in the demo files included with the DoSQL plug-in.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.myfmbutler.com/?feed=rss2&amp;p=47</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
