Project

General

Profile

« Previous | Next » 

Revision 10827

lib/sh/db.sh: mk_select(): added support for ORDER BY

View differences:

lib/sh/db.sh
45 45
cols2list() # usage: cols2list col...
46 46
{ echo_func; cmd=esc_name foreach_arg; delim=', ' join "$@"; }
47 47

  
48
mk_select() # usage: {query=... | table=... [cols=...] [filter=...]} mk_select
48
mk_select() # usage: {query=... | table=... [cols=...] [filter=...] \
49
# [order_by=...]} mk_select
49 50
{
50 51
	echo_func; kw_params query table cols filter; mk_table_esc
51
	if is_array cols; then cols="$(cols2list "${cols[@]}")"; fi
52
	if is_array cols    ; then cols="$(    cols2list "${cols[@]}"    )"; fi
53
	if is_array order_by; then order_by="$(cols2list "${order_by[@]}")"; fi
52 54
	echo "$(rtrim "${query:-SELECT ${cols:-*} ${cols:+
53 55
}FROM $table_esc
54 56
${filter:+WHERE $filter
57
}${order_by:+ORDER BY $order_by
55 58
}}")\
56 59
$(limit)"
57 60
}

Also available in: Unified diff