From 4ed0049b1c1bead979de48dbc117740f5b47d4b9 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 6 Feb 2015 10:48:36 +0100 Subject: 0.1 Assign float values to nr. of working hours of assignments --- install/index.php | 2 +- install/upgrade.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 install/upgrade.php (limited to 'install') diff --git a/install/index.php b/install/index.php index 3921161..5d6b7fa 100644 --- a/install/index.php +++ b/install/index.php @@ -26,7 +26,7 @@ if (isset($_GET['create_tables'])) { `offerId` smallint(5) unsigned NOT NULL, `title` tinytext NOT NULL, `description` text NOT NULL, - `hours` smallint(5) unsigned NOT NULL, + `hours` float NOT NULL, `price_per_hour` float NOT NULL, `VAT_percentage` float NOT NULL, PRIMARY KEY (`id`), diff --git a/install/upgrade.php b/install/upgrade.php new file mode 100644 index 0000000..dd2f6b9 --- /dev/null +++ b/install/upgrade.php @@ -0,0 +1,53 @@ +. + */ + +require('../conf.php'); + +function lower_version($that, $this) { + $that = explode('.', $that); + $this = explode('.', $this); + while (count($that) < count($this)) $that[] = 0; + while (count($this) < count($that)) $this[] = 0; + + for ($i = 0; $i < count($this); $i++) { + if ($this[$i] > $that[$i]) { + return true; + } + } + return false; +} + +if (isset($_GET['upgrade']) && lower_version($_GET['upgrade'], '0.1')) { + try { + $_pdo->query("ALTER TABLE `assignment` CHANGE `hours` `hours` FLOAT UNSIGNED NOT NULL"); + } catch (PDOException $e) { + echo "Altering the database structure failed with a PDOException ({$e->getCode()}): {$e->getMessage()}
" . $e->getTraceAsString(); + } +} + +if (isset($_GET['upgrade'])) { + echo "
All done."; +} +?> + +

You're going to upgrade to version . What was your old version number?

+
+ + +
\ No newline at end of file -- cgit v1.2.3