Skip to content

Commit

Permalink
Merge pull request #15 from srtlg/fixes-for-mariadb-10.6
Browse files Browse the repository at this point in the history
Fixes for mariadb 10.6
  • Loading branch information
rudolphi authored Feb 22, 2022
2 parents 608d2d5 + e4fb1c3 commit 91c4798
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib_constants_tables_analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"versioning" => true, "recordCreationChange" => true,

"fields" => array(
"analytical_data_id" => array("type" => "INT UNSIGNED", "search" => "auto", "fk" => "analytical_data_id", ),
"analytical_data_id" => array("type" => "INT UNSIGNED", "search" => "auto", "fk" => "analytical_data", ),
"project_id" => array("type" => "INT UNSIGNED", "search" => "auto", "fk" => "project", ),
"reaction_id" => array("type" => "INT UNSIGNED", "search" => "auto", "fk" => "reaction", ),
"image_no" => array("type" => "INT", "search" => "auto", "index" => true, ), // 1,2,...
Expand Down Expand Up @@ -77,7 +77,7 @@
"analytical_data_raw_blob" => array("type" => "MEDIUMBLOB"), // rohdaten, zip
"analytical_data_blob" => array("type" => "MEDIUMBLOB", "flags" => FIELD_IMAGE, ), // bearbeitete daten, zip
"measured_by" => array("type" => "TINYTEXT", "search" => "auto"),
"solvent" => array("type" => "INT UNSIGNED", "search" => "auto", "fk" => "solvent", ), // (in particular for NMR), use this perhaps also for solvents used in reations
"solvent" => array("type" => "INT UNSIGNED", "search" => "auto"), // (in particular for NMR), use this perhaps also for solvents used in reations
"analytical_data_interpretation" => array("type" => "TEXT", "search" => "auto"),
"analytical_data_comment" => array("type" => "TEXT", "search" => "auto"),
"analytical_data_properties_blob" => array("type" => "MEDIUMBLOB"),
Expand Down Expand Up @@ -245,4 +245,4 @@
); // zB NMR, GC, GC-MS


?>
?>
45 changes: 39 additions & 6 deletions lib_root_funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,11 @@ function getColumn($name,$data) { // Array
if (isset($data["default"])) {
$dataType.=" DEFAULT ".$data["default"];
}

if (!empty($data["collate"])) {
$dataType.=" COLLATE ".$data["collate"];
}

if (!empty($data["fk"])) {
$dataType.=" REFERENCES ".$data["fk"]."(".getShortPrimary($data["fk"]).")";
}


$field_def=array(
"name" => $name,
"def" => $dataType,
Expand Down Expand Up @@ -439,6 +435,12 @@ function createDefaultTableEntries($tabname) {
break;
}
}
} elseif ($tabname == "person") {
$sql_query[]="SET SESSION sql_mode='NO_AUTO_VALUE_ON_ZERO';";
$sql_query[]="INSERT INTO ".$tabname." SET ".
"person_id=0,".
"username=\"root\"".
";";
}
performQueries($sql_query,$db);
}
Expand Down Expand Up @@ -474,6 +476,36 @@ function createViews() {
}
}

function createTableConstraint($tabname)
{
global $db,$tables;
$constraint_query = array();

$tabdata=& $tables[$tabname];
$constraint = 1;

if (is_array($tabdata["fields"])) foreach ($tabdata["fields"] as $name => $data) {
if (!empty($data["fk"])) {
$constraint_query [] =
"ALTER TABLE ".$tabname.
" ADD CONSTRAINT ".$tabname."_fk".$constraint.
" FOREIGN KEY (".$name.")".
" REFERENCES ".$data["fk"]."(".getShortPrimary($data["fk"]).")".
";";
$constraint++;
}
}
performQueries($constraint_query, $db);
}

function createConstraints() {
global $tables;
$tabnames=array_keys($tables);
foreach ($tabnames as $tabname) {
createTableConstraint($tabname);
}
}

function containsInvalidChars($text) {
if (preg_match("/^[a-zA-Z0-9_]+\$/",$text)) {
return false;
Expand Down Expand Up @@ -516,6 +548,7 @@ function setupInitTables($db_name) { // requires root
// Tabellen erstellen
createTables();
createViews();
createConstraints();
// Views erstellen (rely on tables)
setGVar("Version",currentVersion);
$version=currentVersion;
Expand Down

0 comments on commit 91c4798

Please sign in to comment.