 
 <cfif action is "impData">
  impData
+
+-- temp_ht is a list of terms we need to get data and make it hierarchical for
+drop table temp_ht;
+
+create table temp_ht (
+	TAXON_NAME_ID number not null,
+	SCIENTIFIC_NAME varchar2(255) not null,
+	dataset_name varchar2(255) not null,
+	source varchar2(255) not null
+);
+
+
+
+-- temp_hierarcicized is a log table so we can avoid weird oracle errors
+drop table temp_hierarcicized;
+	create table temp_hierarcicized (taxon_name_id number,dataset_name varchar2(255));
+
+
+
+-- small test
+
+insert into temp_ht (scientific_name,taxon_name_id,dataset_name,source) (
+			select distinct
+				scientific_name,
+				taxon_name.taxon_name_id,
+				'small_test',
+				'Arctos Plants'
+			from
+				taxon_name,
+				taxon_term
+			where
+				taxon_name.taxon_name_id=taxon_term.taxon_name_id and
+				taxon_term.source='Arctos Plants' and
+				scientific_name like 'Veronica %'
+			);
+
+-- wut?
+
+select count(*) from temp_ht;
+
+commit;
+
+-- now let the stored procedure chew on things
+
+CREATE OR REPLACE PROCEDURE proc_hierac_tax IS
+	--declare
+		v_pid number;
+		v_tid number;
+		v_c number;
+	begin
+		v_pid:=NULL;
+		for t in (
+			select
+				*
+			from
+				temp_ht
+			where
+				(taxon_name_id,dataset_name) not in (select taxon_name_id,dataset_name from temp_hierarcicized) and
+				rownum<10000
+		) loop
+			--dbms_output.put_line(t.scientific_name);
+			-- we'll never have this, just insert
+			-- actually, I don't think we need this at all, it should usually be handled by eg, species (lowest-ranked term)
+
+			for r in (
+				select
+					term,
+					term_type
+				from
+					taxon_term
+				where
+					taxon_term.taxon_name_id =t.taxon_name_id and
+					source=t.source and
+					position_in_classification is not null and
+					term_type != 'scientific_name'
+				order by
+					position_in_classification ASC
+			) loop
+				--dbms_output.put_line(r.term_type || '=' || r.term);
+				-- see if we already have one
+				select count(*) into v_c from hierarchical_taxonomy where term=r.term and rank=r.term_type;
+				if v_c=1 then
+					-- grab the ID for use on the next record, move on
+					select tid into v_pid from hierarchical_taxonomy where term=r.term and rank=r.term_type;
+				else
+					-- create the term
+					-- first grab the current ID
+					select someRandomSequence.nextval into v_tid from dual;
+					insert into hierarchical_taxonomy (
+						tid,
+						parent_tid,
+						term,
+						rank,
+						dataset_name
+					) values (
+						v_tid,
+						v_pid,
+						r.term,
+						r.term_type,
+						t.dataset_name
+					);
+					-- now assign the term we just made's ID to parent so we can use it in the next loop
+					v_pid:=v_tid;
+				end if;
+
+
+			end loop;
+			-- log
+			insert into temp_hierarcicized (taxon_name_id,dataset_name) values (t.taxon_name_id,t.dataset_name);
+		end loop;
+	end;
+	/
+sho err;
+
+exec proc_hierac_tax;
+
+select count(*) from temp_hierarcicized;
+select count(*) from hierarchical_taxonomy;
+
+
+
+
+
+UAM@ARCTEST> desc temp_ht
+ Name								   Null?    Type
+ ----------------------------------------------------------------- -------- --------------------------------------------
+ SCIENTIFIC_NAME						   NOT NULL VARCHAR2(255)
+ TAXON_NAME_ID							   NOT NULL NUMBER
+
+insert into temp_ht (scientific_name,taxon_name_id) (
+			select distinct
+				scientific_name,
+				taxon_name.taxon_name_id
+			from
+				taxon_name,
+				taxon_term
+			where
+				taxon_name.taxon_name_id=taxon_term.taxon_name_id and
+				taxon_term.source='Arctos' and
+				term_type='kingdom' and
+				taxon_name.taxon_name_id not in (select taxon_name_id from temp_hierarcicized)
+			);
+
+
+
 </cfif>
 <cfif action is "manageLocalTree">
 

			initTree();

			myTree.attachEvent("onDblClick", function(id){
			    $.getJSON("/component/test.cfc",
					{
						method : "getTaxTreeChild",

						}
					}
				);

				$('html,body').css('cursor','initial');
			});


