From 9ee1363f992bebf26566ac182ad74c152da0289d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96sterreicher?= Date: Mon, 25 May 2009 15:45:18 +0000 Subject: [PATCH] --- system/checkdb.php | 108 ++++++++++++++++++++++++++++------------ system/database.inc.php | 31 +++++++++++- 2 files changed, 106 insertions(+), 33 deletions(-) diff --git a/system/checkdb.php b/system/checkdb.php index 19b3acddf..e7a1835ad 100644 --- a/system/checkdb.php +++ b/system/checkdb.php @@ -1,5 +1,5 @@ , - * Andreas Oesterreicher and - * Rudolf Hangl . + * Andreas Oesterreicher , + * Rudolf Hangl and + * Gerald Simane-Sequens */ /* * Script zur Pruefung der Datenbank @@ -26,22 +27,23 @@ * verglichen und eventuelle Aenderungen werden angezeigt. */ -require_once('../vilesci/config.inc.php'); +require_once('../config/system.config.inc.php'); require_once('database.inc.php'); require_once('../include/functions.inc.php'); require_once('../include/benutzerberechtigung.class.php'); // Datenbank Verbindung -if (!$conn = pg_pconnect(CONN_STRING)) +if (!$conn = pg_pconnect('host='.DB_HOST.' port='.DB_PORT.' dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD)) die('Es konnte keine Verbindung zum Server aufgebaut werden!'.pg_last_error($conn)); $uid=get_uid(); -$rechte = new benutzerberechtigung($conn); +/* +$rechte = new benutzerberechtigung(); $rechte->getBerechtigungen($uid); if(!$rechte->isBerechtigt('admin')) die('Sie haben keine Berechtigung für diese Seite'); - +*/ echo ' @@ -72,7 +74,7 @@ function disableSchemas() for(i=0;i '; -echo '

Datenbank Prüfung


'; +echo '

Datenbank Prüfung

'; $obj=array(); $obj['']=array(); $obj['']['error']=false; @@ -263,6 +265,7 @@ foreach ($tabellen AS $tabelle) // echo $schemas[$tabelle['schemaid']]['caption'].'.'.$tabelle['caption'].'.'.$attribut['caption'].' wurde erfolgreich hinzugefuegt!
'; $obj[$schemas[$tabelle['schemaid']]['caption']]['tables'][$tabelle['caption']]['attribute'][$attribut['caption']]['qry']=$sql_query; $obj[$schemas[$tabelle['schemaid']]['caption']]['error']=true; + $obj[$schemas[$tabelle['schemaid']]['caption']]['tables'][$tabelle['caption']]['error']=true; } $obj[$schemas[$tabelle['schemaid']]['caption']]['tables'][$tabelle['caption']]['attribute'][$attribut['caption']]['datatype']=$datatypes[$attribut['datatypeid']]['caption']; $obj[$schemas[$tabelle['schemaid']]['caption']]['tables'][$tabelle['caption']]['attribute'][$attribut['caption']]['attribute']=$attribut; @@ -274,8 +277,8 @@ foreach ($tabellen AS $tabelle) flush(); $i++; } -/* -echo '

Pruefe Constraints!

'; + +//echo '

Pruefe Constraints!

'; function getTablenameFromAttributIDs($attr) { @@ -315,23 +318,48 @@ foreach ($relations AS $relation) { foreach ($relation['foreignkeys'] AS $foreignkey) { + $sql_query=''; $parenttable=getTablenameFromAttributIDs($foreignkey['attrparent']); $childtable=getTablenameFromAttributIDs($foreignkey['attrchild']); $parentattr=getAttributesnameFromAttributIDs($foreignkey['attrparent']); $childattr=getAttributesnameFromAttributIDs($foreignkey['attrchild']); //$constrname=str_replace('.','_',); - $sql_query='ALTER TABLE '.$childtable.' ADD CONSTRAINT '.$relation['caption'].' FOREIGN KEY ('.$childattr.') REFERENCES '.$parenttable.' ('.$parentattr.') '; - $sql_query.='ON UPDATE CASCADE ON DELETE RESTRICT;'; + + list($schema, $tablename) = explode(".", $childtable); + + $qry = "SELECT * FROM pg_constraint WHERE contype='f' AND conrelid=( + SELECT oid FROM pg_class WHERE relname='".$tablename."' AND relnamespace=( + SELECT oid FROM pg_namespace WHERE nspname='".$schema."')) + AND conname='".$relation['caption']."'"; + if($result = pg_query($conn, $qry)) + { + if(pg_num_rows($result)==0) + { + $sql_query='ALTER TABLE '.$childtable.' ADD CONSTRAINT '.$relation['caption'].' FOREIGN KEY ('.$childattr.') REFERENCES '.$parenttable.' ('.$parentattr.') '; + $sql_query.='ON UPDATE CASCADE ON DELETE RESTRICT;'.$tablename.'/'.$schema; + + if(isset($obj[$schema]) && + isset($obj[$schema]['tables'][$tablename]) && + isset($obj[$schema]['tables'][$tablename]['attribute']) && + isset($obj[$schema]['tables'][$tablename]['attribute'][$childattr]['qry'])) + $obj[$schema]['tables'][$tablename]['attribute'][$childattr]['qry'].=$sql_query; + else + $obj[$schema]['tables'][$tablename]['attribute'][$childattr]['qry']=$sql_query; + $obj[$schema]['error']=true; + $obj[$schema]['tables'][$tablename]['error']=true; + } + } + //if (refintegritychildupdate) // $sql_query.=' - echo $sql_query.'
'; + //echo $sql_query.'
'; } } flush(); $i++; } - +/* echo '

Gegenpruefung!

'; $sql_query="SELECT schemaname,tablename FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema' AND schemaname != 'sync' AND schemaname != 'papaya';"; if (!$result=@pg_query($conn,$sql_query)) @@ -376,7 +404,7 @@ function querybox($title, $qry, $id) if(strlen($qry)>50) { $cols=55; - $rows = strlen($qry)/50; + $rows = strlen($qry)/50+1; if($rows>10) $rows = 10; @@ -396,6 +424,8 @@ $out_schema.= '
'; $out_schema.= '
Schema
'; $out_schema.= ''; +$gesamtqry = ''; + foreach ($obj as $schema=>$value) { @@ -406,6 +436,7 @@ foreach ($obj as $schema=>$value) { if(isset($value['qry']) && $value['qry']!='') { + $gesamtqry .= $value['qry']."\n"; $out_schema_data.=querybox($schema, $value['qry'], 'schema.'.$schema); $img = "exclamation.png"; } @@ -413,8 +444,8 @@ foreach ($obj as $schema=>$value) { $img = "error_go.png"; } - $out_schema.= ''; - $out_schema.= ''; + $out_schema.= ''; + $out_schema.= ''; @@ -422,7 +453,7 @@ foreach ($obj as $schema=>$value) else { $out_schema.= ''; - $out_schema.= ''; + $out_schema.= ''; } $out_schema.= ''; @@ -439,16 +470,25 @@ foreach ($obj as $schema=>$value) $out_tbl.= ''; if(isset($tabvalue['qry']) && $tabvalue['qry']!='') { - $out_tbl.= ''; - $out_tbl.= ''; + $gesamtqry .= $tabvalue['qry']."\n"; + $out_tbl.= ''; + $out_tbl.= ''; - $out_tbl_data.=querybox($tables, $tabvalue['qry'], 'table.'.$tables); + $out_tbl_data.=querybox($tables, $tabvalue['qry'], 'table.'.$schema.$tables); } else { - $out_tbl.= ''; - $out_tbl.= ''; + if(isset($tabvalue['error']) && $tabvalue['error']) + { + $out_tbl.= ''; + $out_tbl.= ''; + } + else + { + $out_tbl.= ''; + $out_tbl.= ''; + } } $out_tbl.= ''; @@ -456,7 +496,7 @@ foreach ($obj as $schema=>$value) if(isset($tabvalue['attribute'])) { $out_att.= "\n"; - $out_att.= '
'.$schema.''.$schema.''.$schema.''.$schema.'
'.$tables.''.$tables.''.$tables.''.$tables.''.$tables.'
'; @@ -465,17 +505,18 @@ foreach ($obj as $schema=>$value) $out_att.= ''; if(isset($attvalue['qry']) && $attvalue['qry']!='') { - $out_att.= ''; - $out_att.= ''; + $gesamtqry .= $attvalue['qry']."\n"; + $out_att.= ''; + $out_att.= ''; - $out_att_data.=querybox($attrib, $attvalue['qry'], 'attrib.'.$attrib); + $out_att_data.=querybox($attrib, $attvalue['qry'], 'attrib.'.$schema.$tables.$attrib); } else { $out_att.= ''; - $out_att.= ''; - $out_att.= ''; - $out_att.= ''; + $out_att.= ''; + $out_att.= ''; @@ -495,7 +536,10 @@ foreach ($obj as $schema=>$value) $out_schema.= '
'.$attrib.''.$attrib.''.$attrib.' '.$attvalue['datatype'].($attvalue['attribute']['length']!=''?' ('.$attvalue['attribute']['length'].')':'').' '. + $out_att.= ''.$attrib.' '.$attvalue['datatype'].($attvalue['attribute']['length']!=''?' ('.$attvalue['attribute']['length'].')':'').' '. ($attvalue['attribute']['unique']=='1'?'U':''). ($attvalue['attribute']['notnull']=='1'?'NN':''). '
'; $out_schema.= '
'; +echo 'Gesamtsystem aktualisieren
'; + echo $out_schema; +echo querybox('Gesamtsystem aktualisieren',$gesamtqry, 'schema.gesamtqry'); echo $out_schema_data; echo $out_tbl; echo $out_tbl_data; diff --git a/system/database.inc.php b/system/database.inc.php index 030cef54d..5010dea34 100644 --- a/system/database.inc.php +++ b/system/database.inc.php @@ -27,7 +27,14 @@ $schemas=array "comments" => "" , "ordinal" => "0" ), - + '{3A7F9B8D-001E-4D33-8FD0-0558492DBD41}' => array + ( + "id" => "{3A7F9B8D-001E-4D33-8FD0-0558492DBD41}" , + "name" => "foo" , + "caption" => "foo" , + "comments" => "" , + "ordinal" => "0" + ), '{A0178E89-8366-4582-834F-E124208C684D}' => array ( "id" => "{A0178E89-8366-4582-834F-E124208C684D}" , @@ -45807,6 +45814,28 @@ $datatypes['{3DD56C5A-B10A-4E02-8CB2-C7B4880B63DD}']=array "comments" => "", "ordinal" => "0" ); +$datatypes['{E62BD1D3-18CA-4571-9A16-606FF04DC894}']=array +( + "id" => "{E62BD1D3-18CA-4571-9A16-606FF04DC894}", + "name" => "Numeric", + "caption" => "numeric", + "length" => "0", + "default" => "'0'" , + "comments" => "", + "ordinal" => "0" +); +$datatypes['{36A9DD5B-49C4-4BB7-86DB-2D4BCCAF58AF}']=array +( + "id" => "{36A9DD5B-49C4-4BB7-86DB-2D4BCCAF58AF}", + "name" => "Real", + "caption" => "real", + "length" => "0", + "default" => "'0'" , + "comments" => "", + "ordinal" => "0" +); + + $datatypes['']=array ( "id" => "",