aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorGravatar Victor Huesca <victor.huesca@bootlin.com>2019-08-13 15:13:17 +0200
committerGravatar Thomas Petazzoni <thomas.petazzoni@bootlin.com>2019-08-13 22:03:16 +0200
commit4737de3c1e8d5fbfa4c90ae9af517e8cc7065150 (patch)
tree16c0db4d82a0e786ad6c79fecfea2574a93fadc8 /web
parent65e79bbec5a365f355291f9f43c577f30f42abac (diff)
downloadbuildroot-test-4737de3c1e8d5fbfa4c90ae9af517e8cc7065150.tar.gz
buildroot-test-4737de3c1e8d5fbfa4c90ae9af517e8cc7065150.tar.bz2
web/db.inc.php: add support to test if the database supports a feature
This patch allows to test if the database supports a given feature. Any feature to be test against can be added by simply adding a new case to the switch. This patch allows to check if the database engine supports the 'intersect' SQL keyword. This keyword was implemented in mariadb 10.3.10 released in oct. 2018 Signed-off-by: Victor Huesca <victor.huesca@bootlin.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Diffstat (limited to 'web')
-rw-r--r--web/db.inc.php28
1 files changed, 26 insertions, 2 deletions
diff --git a/web/db.inc.php b/web/db.inc.php
index 99f83a2..0b6287a 100644
--- a/web/db.inc.php
+++ b/web/db.inc.php
@@ -54,6 +54,30 @@ class db
return $value;
}
-}
-?> \ No newline at end of file
+
+ // Test whereas the database supports a given feature
+ function has_feature($feature)
+ {
+ // Return -1 on v1 < v2, 0 on v1 = v2 and 1 on v1 > v2
+ $compare_versions = function($v1, $v2) {
+ for ($i = 0; $i < min(sizeof($v1), sizeof($v2)); $i++)
+ if ($v1[$i] != $v2[$i])
+ return $v1[$i] - $v2[$i];
+ return 0;
+ };
+
+ switch ($feature) {
+ case 'intersect': // intersect was introduced in mariadb version 10.3.10
+ $res = $this->query("select version() version;");
+ $ver = mysqli_fetch_object($res)->version;
+ preg_match("/^(\d+(?:\.\d+)*)-.+$/", $ver, $match);
+ $version = array_map(function ($v) { return (int)$v; }, explode('.', $match[1]));
+ return $compare_versions($version, array(10, 3, 10)) >= 0;
+
+ default:
+ throw new Exception("Unknown feature", 1);
+ }
+ }
+}
+?>