added categoryKey to questionnaire schema and updated related functions for questionnaire handling; enhanced API to fetch client answers
This commit is contained in:
15
db_init.php
15
db_init.php
@ -6,7 +6,7 @@ require_once __DIR__ . '/common.php';
|
||||
define('QDB_PATH', __DIR__ . '/uploads/questionnaire_database');
|
||||
define('QDB_LOCK', __DIR__ . '/uploads/.qdb_lock');
|
||||
define('QDB_SCHEMA', __DIR__ . '/schema.sql');
|
||||
define('QDB_VERSION', 3);
|
||||
define('QDB_VERSION', 4);
|
||||
|
||||
/**
|
||||
* Decrypt the master DB file into a temp SQLite file, or create a fresh one
|
||||
@ -72,6 +72,19 @@ function qdb_open(bool $writable = false): array {
|
||||
if ($currentVersion < QDB_VERSION) {
|
||||
$pdo->exec("PRAGMA foreign_keys = OFF;");
|
||||
$pdo->exec($sql);
|
||||
if ($currentVersion < 4) {
|
||||
$cols = $pdo->query("PRAGMA table_info(questionnaire)")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$hasCategory = false;
|
||||
foreach ($cols as $col) {
|
||||
if (($col['name'] ?? '') === 'categoryKey') {
|
||||
$hasCategory = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$hasCategory) {
|
||||
$pdo->exec("ALTER TABLE questionnaire ADD COLUMN categoryKey TEXT NOT NULL DEFAULT ''");
|
||||
}
|
||||
}
|
||||
$pdo->exec("PRAGMA user_version = " . QDB_VERSION . ";");
|
||||
$pdo->exec("PRAGMA foreign_keys = ON;");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user