Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/mysql-functions
blob: d9962a94513bd965ed14df1518db1f9eb0f1003f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh

# contains functions used to access mysql db

# shellcheck disable=SC2039

mysql_command='mysql buildmaster -e'

# mysql_add_package_source $pkgbase $pkgver $pkgrel $git_revision $mod_git_revision $upstream_package_repository

# shellcheck disable=SC2016,SC2086
mysql_add_package_source() {
  local names='pkgbase pkgver pkgrel git_revision mod_git_revision upstream_package_repository'
  local values;
  for _ in ${names}; do
    values="${values}$(
      printf '%s' "$1" | \
        base64 -w0
    ) "
    shift
  done
  values="${values% }"

  ${mysql_command} "$(
    printf 'INSERT IGNORE INTO package_sources'
    {
      printf ' ('
      printf '`%s`, ' ${names}
      printf ') SELECT'
      printf ' from_base64("%s"), ' ${values% *}
      printf ' `upstream_repositories`.`id`'
      printf ' FROM `upstream_repositories`'
      printf ' WHERE `upstream_repositories`.`name` = from_base64("%s");' \
        "${values##* }"
    } | \
      sed 's|, )|)|g'
  )"
}

# mysql_add_binary_package $pkgbase $git_revision $mod_git_revision $upstream_package_repository $pkgname $sub_pkgrel $architecture $repository

# shellcheck disable=SC2016,SC2086,SC2154
mysql_add_binary_package() {
  local names='pkgbase git_revision mod_git_revision upstream_package_repository pkgname sub_pkgrel architecture repository'
  local name
  for name in ${names}; do
    eval 'local '"${name}"
    eval "${name}"'=$(
      printf "%s" "$1" |
        base64 -w0
    )'
    shift
  done

  ${mysql_command} "$(
    printf 'INSERT IGNORE INTO binary_packages'
    {
      printf ' ('
      printf '`%s`, ' 'sub_pkgrel' 'pkgname' 'package_source' 'repository' 'architecture'
      printf ') SELECT'
      printf ' from_base64("%s"), ' "${sub_pkgrel}" "${pkgname}"
      printf ' `%s`.`id`,' 'package_sources' 'repositories' 'architectures'
      printf ' FROM'
      printf ' `%s` JOIN' 'package_sources' 'repositories' 'architectures'
      printf ' `upstream_repositories` ON `package_sources`.`upstream_package_repository` = `upstream_repositories`.`id`'
      printf ' WHERE'
      printf ' `%s`.`name` = from_base64("%s") AND' \
        'repositories' "${repository}" \
        'architectures' "${architecture}"
      printf ' `package_sources`.`%s` = from_base64("%s") AND' \
        'pkgbase' "${pkgbase}" \
        'git_revision' "${git_revision}" \
        'mod_git_revision' "${mod_git_revision}"
      printf ' `upstream_repositories`.`name` = from_base64("%s")' \
        "${upstream_package_repository}"
    } | \
      sed '
        s|, )|)|g
        s|, FROM| FROM|g
      '
  )"
}

# mysql_show_binary_package $pkgname $pkgver $pkgrel $sub_pkgrel

# shellcheck disable=SC2016,SC2086,SC2154
mysql_show_binary_package() {
  local names='pkgname pkgver pkgrel sub_pkgrel'
  local name
  for name in ${names}; do
    eval 'local '"${name}"
    eval "${name}"'=$(
      printf "%s" "$1" |
        base64 -w0
    )'
    shift
  done

  local joint
  ${mysql_command} "$(
    {
      printf 'SELECT'
      printf ' `%s`.`%s`,' \
        'repositories' 'name' \
        'binary_packages' 'pkgname' \
        'package_sources' 'pkgver' \
        'package_sources' 'pkgrel' \
        'binary_packages' 'sub_pkgrel' \
        'architectures' 'name' \
        'package_sources' 'pkgbase' \
        'package_sources' 'git_revision' \
        'package_sources' 'mod_git_revision' \
        'upstream_repositories' 'name'
      printf ' FROM `binary_packages`'
      for joint in \
        'architectures:binary_packages:architecture' \
        'package_sources:binary_packages:package_source' \
        'repositories:binary_packages:repository' \
        'upstream_repositories:package_sources:upstream_package_repository'; do
        printf ' JOIN `%s` ON `%s`.`id` =' \
          "${joint%%:*}" "${joint%%:*}"
        joint="${joint#*:}"
        printf ' `%s`.`%s`' \
          "${joint%:*}" "${joint#*:}"
      done
      printf ' WHERE'
      printf ' `%s`.`%s` = from_base64("%s") AND' \
        'binary_packages' 'pkgname' "${pkgname}" \
        'binary_packages' 'sub_pkgrel' "${sub_pkgrel}" \
        'package_sources' 'pkgver' "${pkgver}" \
        'package_sources' 'pkgrel' "${pkgrel}"
      printf ';'
    } | \
      sed '
        s|, FROM| FROM|g
        s|AND;|;|g
      '
  )" --html
}