Example 3: Complex queries

26–50 of 6,860
IDNameCodeDescriptionLatitudeLongitude
1,676 Fright Cove BAY bay/inlet 47° 13′ 47″ S 167° 37′ 47″ E
127,787 Taukihepa/Big South Cape Island ISLD island 47° 13′ 47″ S 167° 24′ 00″ E
127,789 Titi/Muttonbird Islands ISLD island 47° 13′ 47″ S 167° 19′ 48″ E
1,633 Tamaitemioka Island ISLD island 47° 13′ 11″ S 167° 19′ 11″ E
1,634 Pohowaitai Island ISLD island 47° 13′ 11″ S 167° 19′ 11″ E
1,636 Putauhina Nuggets ISLD island 47° 13′ 11″ S 167° 21′ 36″ E
1,638 Pukeweka Island ISLD island 47° 13′ 11″ S 167° 25′ 48″ E
1,656 Potted Head PNT point 47° 13′ 11″ S 167° 24′ 35″ E
1,668 Pigeon House ROCK rock 47° 13′ 11″ S 167° 39′ 00″ E
1,669 South Passage STRA strait 47° 13′ 11″ S 167° 39′ 00″ E
1,679 Bald Cone HILL hill 47° 13′ 11″ S 167° 35′ 24″ E
1,681 Huirapa Island ISLD island 47° 13′ 11″ S 167° 22′ 12″ E
1,683 Sheathknife Bay BAY bay/inlet 47° 13′ 11″ S 167° 38′ 23″ E
63,070 Rerewhakaupoko Island (Solomon) ISLD island 47° 13′ 11″ S 167° 25′ 48″ E
1,577 Smooth Point PNT point 47° 12′ 36″ S 167° 41′ 59″ E
1,637 Putauhina Island ISLD island 47° 12′ 36″ S 167° 23′ 23″ E
1,640 Pukuparara Island ISLD island 47° 12′ 36″ S 167° 26′ 23″ E
1,644 Hebe Island ISLD island 47° 12′ 36″ S 167° 37′ 47″ E
1,645 Noble Island ISLD island 47° 12′ 36″ S 167° 39′ 35″ E
1,646 Dryad Island ISLD island 47° 12′ 36″ S 167° 37′ 12″ E
1,653 Tupari Bay BAY bay/inlet 47° 12′ 36″ S 167° 28′ 11″ E
1,670 Blind Passage STRA strait 47° 12′ 36″ S 167° 40′ 11″ E
1,677 Shipbuilders Cove BAY bay/inlet 47° 12′ 36″ S 167° 35′ 59″ E
1,680 Micrometer Rock and Reef MRFM marine rock formation 47° 12′ 36″ S 167° 37′ 47″ E
1,682 Kelp Point PNT point 47° 12′ 36″ S 167° 37′ 47″ E
26–50 of 6,860

Sometimes a record set will need to combine data from different tables. We can implement this by creating a view in the database (example 2) or by writing the join directly within the table attribute. Here we have also added a clause to restrict the records to those below 45° south.

Features of this example:

  • The tables are joined within the table attribute, so we don't need to set up a database view.
  • A where attribute controls the subset of records to be displayed.
  • As pointdescriptioncode appears in both tables, we must qualify the column with the table name.
  • The expression attribute is used for latitude and longitude to call a user-defined function.
  • Query caching using the cachedwithin attribute.
  • The 'glacier_lavender' skin.
  • Locale-specific formatting for 'English (US)' (change this using the selector at bottom right).
Source code for this example 
<!--- 
Note that the database for this example must be set up as a datasource first. The Microsoft Access database is located in the examples folder. Place the datasource name in the request.dsn variable.

Microsoft Access is not recommended for web purposes, and is provided here for demonstration purposes only. Better performance will be achieved with enterprise databases.
--->

<cfimport prefix="esw" taglib="../customtags/eswsoftware/">

<cfif structKeyExists(url, "relatedId")>
	<cfoutput><p>Record selected: #htmlEditFormat(url.relatedId)#</p></cfoutput>
</cfif>

<esw:sortableplus 
	link="example3.cfm?relatedid=##relatedid##"
	table="namedata inner join pointdes on namedata.pointdescriptioncode = pointdes.pointdescriptioncode"
	dbms="Microsoft Access"
	datasource="#request.dsn#"
	sortBy="Latitude"
	key="relatedid"
	style="width : 600px"
	where="latitude < -45"
	cachedwithin="#createTimeSpan(0, 0, 10, 0)#"
	skin="glacier_lavender"
>

	<esw:column
		column="relatedid"
		caption="ID"
		type="numeric"
		sortDirection="asc"
	/>
	
	<esw:column
		column="pointname"
		caption="Name"
	/>
	
	<esw:column
		column="pointdes.pointdescriptioncode"
		caption="Code"
	/>
	
	<esw:column
		column="pointdescriptionname"
		caption="Description"
	/>
	
	<esw:column
		column="Latitude"
		type="numeric"
		expression="##caller.dmsFormat(latitude, 'NS')##"
	/>
	
	<esw:column
		column="Longitude"
		type="numeric"
		expression="##caller.dmsFormat(Longitude, 'EW')##"
	/>
	
</esw:sortableplus>

<cfscript>
	function dmsFormat(value) {
		var temp = abs(value);
		var d = int(temp);
		var m = 0;
		var s = 0;
		var signIndicator = arrayLen(arguments) gt 1;
		var result = "";
		temp = (temp - d) * 60;
		m = int(temp);
		temp = (temp - m) * 60;
		s = int(temp);
		result = "#d#&##176; #numberFormat(m, "00")#&##8242; #numberFormat(s, "00")#&##8243;";
		
		if ( signIndicator )
			if ( value lt 0 )
				result = result & " " & right(arguments[2],1);
			else 
				result = result & " " & left(arguments[2],1);
		else
			if ( value lt 0 )
				result = "-" & result;
		return result;
	}
</cfscript>

To run the example, you will need to:-