 
 -- now findLowestTerm
 
+
+
+-- this form is too slow, precompile into table
+
+alter table temp_tax_funk add gotit number;
+
+create table temp_funky_taxonomy (
+	source_term varchar2(255),
+	conflicting_term_type varchar2(255),
+	name_using_term varchar2(255),
+	names_term_val varchar2(255)
+);
+
+delete from temp_funky_taxonomy;
+update temp_tax_funk set gotit=null;
+
+
+
+exec DBMS_SCHEDULER.DROP_JOB('J_TEMP_UPDATE_JUNK');
+
+CREATE OR REPLACE PROCEDURE temp_update_junk IS
+tt varchar2(255);
+begin
+	for r in (select * from temp_tax_funk where gotit is null) loop
+		if lower(r.funky_term_type) = 'pylorder' then
+			tt:='ORDER';
+		else
+			tt:=r.funky_term_type;
+		end if;
+		--dbms_output.put_line(r.sciname);
+		--dbms_output.put_line(r.funky_term_type);
+		for c in (
+			select distinct
+				scientific_name,
+				term
+			from
+				taxon_term,
+				taxon_name
+			where
+				taxon_term.taxon_name_id=taxon_name.taxon_name_id and
+				upper(term_type)=upper(tt) and
+				source='Arctos' and
+				taxon_term.taxon_name_id in (
+					select taxon_name_id from taxon_term where upper(term)=upper(r.sciname) and source='Arctos'
+				)
+			order by term,scientific_name
+		) loop
+			insert into temp_funky_taxonomy (
+				source_term,
+				conflicting_term_type,
+				name_using_term,
+				names_term_val
+			) values (
+				r.sciname,
+				r.funky_term_type,
+				c.scientific_name,
+				c.term
+			);
+		end loop;
+		update temp_tax_funk set gotit=1 where sciname=r.sciname and funky_term_type=r.funky_term_type;
+		commit;
+	end loop;
+end;
+/
+
+
+
+select * from temp_tax_funk where gotit is not null;
+select count(*) from temp_funky_taxonomy;
+
+select conflicting_term_type,count(*) from temp_funky_taxonomy group by conflicting_term_type;
+
+BEGIN
+  DBMS_SCHEDULER.CREATE_JOB (
+    job_name    => 'J_TEMP_UPDATE_JUNK',
+    job_type    => 'STORED_PROCEDURE',
+    job_action    => 'temp_update_junk',
+    enabled     => TRUE,
+    end_date    => NULL
+  );
+END;
+/
+
+select * from temp_funky_taxonomy;
+
+
+
+
+
+
 ---->
 
 
 <cfoutput>
-	<cfquery name="cols" datasource="uam_god">
-		select column_name from user_tab_cols where table_name='TEMP_NEW_CLASS_TEMP' ORDER BY INTERNAL_COLUMN_ID
-	</cfquery>
-
-	<cfdump var=#cols#>
+
+	<cfif action is "nothing">
+		<cfquery name="d" datasource="uam_god">
+			select sciname,funky_term_type from temp_tax_funk order by sciname
+		</cfquery>
+
+		<cfloop query="d">
+			<br><a href="funkyTaxonomy.cfm?action=findOne&diff_term=#funky_term_type#&src_term=#sciname#">#sciname# (#funky_term_type#)</a>
+		</cfloop>
+	</cfif>
+
+
 
 	<cfif action is "findLowestTerm">
+		<cfquery name="cols" datasource="uam_god">
+			select column_name from user_tab_cols where table_name='TEMP_NEW_CLASS_TEMP' ORDER BY INTERNAL_COLUMN_ID desc
+		</cfquery>
+
 		<cfquery name="d" datasource="uam_god">
 			select * from temp_tax_funk where lowest_term is null
 		</cfquery>
+		<cfloop query="d">
+			<cfloop query="cols">
+				<cfquery name="flt" datasource="uam_god">
+					select
+						#cols.column_name# v
+					from
+						temp_new_class_temp
+					where scientific_name='#d.sciname#' and
+					#cols.column_name# is not null
+				</cfquery>
+				<cfif len(flt.v) gt 0>
+					<p>
+						found something break
+					</p>
+					<cfquery name="fit" datasource="uam_god" result="x">
+						update temp_tax_funk set lowest_term='#flt.v#' where sciname='#d.sciname#'
+					</cfquery>
+					<cfbreak>
+				</cfif>
+
+			</cfloop>
+		</cfloop>
+
 	</cfif>
 
 
 <cfif action is "findOne">
-
-
-
-<cfset diff_term="nomenclatural_code">
-<cfset src_term="Asilini">
-
-
+	<script src="/includes/sorttable.js"></script>
+
+
+<p>
+	This page is cached.
+	<a href="funkyTaxonomy.cfm?action=findOneLive&diff_term=#diff_term#&src_term=#src_term#">click here for live data</a>
+	and to refresh the cache.
+</p>
+
+
+
+results for source_term=#src_term#, differences in #diff_term#
+
+
+<cfquery name="f" datasource="uam_god">
+	select *
+	from
+		temp_related_funky_taxonomy
+	where
+		wonky_term='#src_term#' and used_as_rank='#diff_term#'
+	order by used_as_rank,using_name
+</cfquery>
+
+<table id="t" border  class="sortable">
+	<tr>
+		<th>ScientificName</th>
+		<th>#diff_term#</th>
+	</tr>
+
+<cfloop query="f">
+	<tr>
+		<td><a href="/name/#USING_NAME#" target="_blank">#USING_NAME#</a></td>
+		<td>#USED_VALUE#</td>
+	</tr>
+</cfloop>
+
+</table>
+</cfif>
+<cfif action is "findOneLive">
+
+
+
+
+results for source_term=#src_term#, differences in #diff_term#
+<cfif diff_term is "phylorder">
+	<cfset dterm='order'>
+<cfelse>
+	<cfset dterm=diff_term>
+
+</cfif>
 <cfquery name="f" datasource="uam_god">
 	select distinct
 		scientific_name,

</cfloop>

</table>
</cfoutput>
</cfif>
<cfinclude template = "/includes/_footer.cfm">

<cfinclude template = "/includes/_header.cfm">


<!--- from the effort to create names for all terms

https://github.com/ArctosDB/arctos/issues/891
