X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Fmaintenance_db.inc;h=81fc0abc0f764f8c4d140a13ad3bca26ec65c17d;hb=1d8bbcbf6bf6c663d83283be329758a936f863fa;hp=11914e02c519e98b69d8de9d46ff6b7a00797545;hpb=cef4b4de401511a4195b7b8ad04b47bec1895b20;p=fa-stable.git diff --git a/admin/db/maintenance_db.inc b/admin/db/maintenance_db.inc index 11914e02..81fc0abc 100644 --- a/admin/db/maintenance_db.inc +++ b/admin/db/maintenance_db.inc @@ -72,13 +72,14 @@ function write_config_db($new = false) $n = count($db_connections); $msg = " 0) + $table_sql[$tablename] = substr($table_sql[$tablename], 0, $def_pos); $out.=$table_sql[$tablename]; // add auto_increment value @@ -658,9 +609,6 @@ function db_export($conn, $filename, $zip='no', $comment='', $tbpref = TB_PREF) return false; } - // if (mysql_error()) return "DB_ERROR"; - //@mysql_close($con); - //if ($zip == "zip") // $zip = $time; if (save_to_file($backupfile, $zip, $out)) @@ -854,4 +802,39 @@ function create_comp_dirs($comp_path, $comp_subdirs) @fclose($f); } } + +// +// Checks $field existence in $table with given field $properties +// $table - table name without prefix +// $field - optional field name +// $properties - optional properties of field defined by MySQL: +// 'Type', 'Null', 'Key', 'Default', 'Extra' +// +function check_table($pref, $table, $field=null, $properties=null) +{ + $tables = @db_query("SHOW TABLES LIKE '".$pref.$table."'"); + if (!db_num_rows($tables)) + return 1; // no such table or error + + $fields = @db_query("SHOW COLUMNS FROM ".$pref.$table); + if (!isset($field)) + return 0; // table exists + + while( $row = db_fetch_assoc($fields)) + { + if ($row['Field'] == $field) + { + if (!isset($properties)) + return 0; + foreach($properties as $property => $value) + { + if ($row[$property] != $value) + return 3; // failed type/length check + } + return 0; // property check ok. + } + } + return 2; // field not found +} + ?> \ No newline at end of file