select count(*) from portal_elements, portal_pages where portal_pages.page_id = :page_id and portal_pages.page_id = portal_elements.page_id and portal_elements.region = :region select portal_elements.element_id as template_element_id from portal_elements, portal_pages, portals where portal_elements.page_id = portal_pages.page_id and portal_pages.portal_id = portals.template_id and portals.portal_id = (select portal_id from portal_pages where page_id = :page_id) and portal_elements.datasource_id = :datasource_id insert into portal_elements (element_id, datasource_id, name, page_id, region, sort_key, state, shadeable_p, hideable_p) select :element_id, :datasource_id, :name, :page_id, region, sort_key, state, shadeable_p, hideable_p from portal_elements where element_id = :template_element_id delete from portal_elements where element_id = :element_id select * from portal_elements where element_id = :element_id update portal_elements set datasource_id = :datasource_id, name = :name, page_id = :page_id, region = :region, sort_key = :sort_key, state = :state where element_id = :element_id select count(*) as count from portal_elements pe, portal_pages pp where pp.page_id = :page_id and pe.region = :region and pp.page_id = pe.page_id select portal_elements.element_id from portal_elements, portal_pages where portal_pages.portal_id = :portal_id and portal_elements.datasource_id = :datasource_id and portal_elements.page_id = portal_pages.page_id update portal_elements set sort_key = :dummy_sort_key where element_id = :element_id update portal_elements set sort_key = :sort_key where element_id = :other_element_id update portal_elements set sort_key = :other_sort_key where element_id = :element_id select pe.element_id from portal_elements pe, portal_datasources pd where pe.page_id = :page_id and pe.datasource_id = pd.datasource_id and pd.name = :datasource_name