Project

General

Profile

« Previous | Next » 

Revision 9567

inputs/GBIF/_MySQL/MySQL.data.sql.run: is_pkey_imported__int(): made pkey name configurable in $pkey_name

View differences:

inputs/GBIF/_MySQL/MySQL.data.sql.run
11 11
### is_pkey_imported()
12 12

  
13 13
table=raw_occurrence_record
14
pkey_name=id
14 15

  
15
is_pkey_imported__int() # usage: pkey=# is_pkey_imported__int
16
is_pkey_imported__int() # usage: pkey_name=... pkey=# is_pkey_imported__int
16 17
{
17
	echo_func; kw_params pkey; : "${pkey?}"; mk_table_esc
18
	echo_func; kw_params pkey_name pkey; : "${pkey_name?}" "${pkey?}"
18 19
	test "$pkey" || { log++ echo_run echo 0; return; }
19 20
	
21
	mk_table_esc
20 22
	use_local_remote
21
	data_only=1 mysql_ANSI <<<"SELECT COUNT(*) FROM $table_esc WHERE id = $pkey"
23
	data_only=1 mysql_ANSI \
24
<<<"SELECT COUNT(*) FROM $table_esc WHERE $pkey_name = $pkey"
22 25
}
23 26

  
24 27
func_override is_pkey_imported__int__no_cache
25 28
is_pkey_imported__int() # caches the last result for efficiency
26 29
{
27
	local cache_key="$(declare -p pkey) $*"; load_cache
30
	local cache_key="$(declare -p pkey_name pkey) $*"; load_cache
28 31
	if ! cached; then save_cache "$(${FUNCNAME}__no_cache "$@")" || return; fi
29 32
	echo_cached_value
30 33
}

Also available in: Unified diff