From debfc92ee0263d726c4bb9587351e7f9f2f8aef3 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 26 Apr 2018 11:13:12 +0200 Subject: lib/mysql-functions: mysql_add_package_source: insert-select -> select + insert --- lib/mysql-functions | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/mysql-functions b/lib/mysql-functions index 359caf3..6739485 100755 --- a/lib/mysql-functions +++ b/lib/mysql-functions @@ -109,6 +109,7 @@ mysql_add_package_source() { local repo_path local commit_time local pkgbuild + local upstream_package_repository_id if grep -qx 'PKGBUILD_mod = \S\+' "${srcinfo_file}"; then uses_modification=1 @@ -148,11 +149,31 @@ mysql_add_package_source() { fi printf 'I' >&2 + upstream_package_repository_id=$( + { + printf 'SELECT `upstream_repositories`.`id`' + printf ' FROM `upstream_repositories`' + printf ' WHERE `upstream_repositories`.`name` = from_base64("%s")' \ + "$( + printf '%s' "${upstream_package_repository}" | \ + base64 -w0 + )" + printf ' LIMIT 1;\n' + } | \ + mysql_run_query + ) + + if [ -z "${upstream_package_repository_id}" ]; then + >&2 printf 'Cannot find upstream package repository "%s" in the database.\n' \ + "${upstream_package_repository}" + exit 2 + fi + { printf 'INSERT IGNORE INTO package_sources' printf ' (`pkgbase`,`git_revision`,`mod_git_revision`,`upstream_package_repository`,`uses_upstream`,`uses_modification`,`commit_time`)' - printf ' SELECT' - printf ' from_base64("%s"),' \ + printf ' VALUES (' + printf 'from_base64("%s"),' \ "$( printf '%s' "${pkgbase}" | \ base64 -w0 @@ -165,14 +186,12 @@ mysql_add_package_source() { printf '%s' "${mod_git_revision}" | \ base64 -w0 )" - printf ' `upstream_repositories`.`id`,%s,%s,from_unixtime(%s)' \ - "${uses_upstream}" "${uses_modification}" "${commit_time}" - printf ' FROM `upstream_repositories`' - printf ' WHERE `upstream_repositories`.`name` = from_base64("%s");' \ - "$( - printf '%s' "${upstream_package_repository}" | \ - base64 -w0 - )" + printf '%s,' \ + "${upstream_package_repository_id}" \ + "${uses_upstream}" \ + "${uses_modification}" + printf 'from_unixtime(%s));\n' \ + "${commit_time}" } | \ mysql_run_query printf 'J' >&2 -- cgit v1.2.3-70-g09d2