1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| ...
$('#start').click(function(){
var sql, tableNo = 0, colNo = 0;;
$('#cursor_int').width(0);
$('#cursor_ext').show();
$('#result td').html(' ');
$.ajaxSetup({async : false});
doSQL("SHOW TABLES",function(tablerows){
$.each(tablerows, function(key,table){
var target = colNo == 0 ? $('#result td').eq(0) : $('#result td').eq(1);
colNo++;
colNo %= 2;
// table est un tableau associatif à 1 dimension dont la clé est construite par le moteur de base de données
// Il est donc variable et doit être retrouvé à chaque fois.
var tablekey = Object.keys(table)[0];
var tablename = table[tablekey];
tableNo++;
$('#cursor_int').width(tableNo / tablerows.length * maxwidth)
// Vérification de la table
var html = '<br /><br /><strong>Vérification de la table : '+tablename+'</strong><br />\n';
target.html(target.html() + html);
doSQL("CHECK TABLE " + tablename, function(checkrows){
html = "État de la table : " + checkrows[0]['Msg_text'] + "<br />\n";
target.html(target.html() + html);
if(checkrows[0]['Msg_text'] != 'OK'){
// Table défectueuse : réparation
doSQL("REPAIR TABLE " + tablename, function(repairrows){
html =" Réparation de la table : " + repairrows[0]['Msg_text'] + "<br />\n";
target.html(target.html() + html);
doSQL("OPTIMIZE TABLE " + tablename, function(optirows){
html =" Optimisation de la table : " + optirows[0]['Msg_text'] + "\n";
target.html(target.html() + html);
});
});
}
else{
doSQL("OPTIMIZE TABLE " + tablename, function(optirows){
html =" Optimisation de la table : " + optirows[0]['Msg_text'] + "\n";
target.html(target.html() + html);
});
}
});
});
alert('Vérification et optimisation terminées.');
$.ajaxSetup({async : true});
});
}) |
Partager