General Actions:
Log-in
Register
Wiki:
games
▼
:
Document Index
»
Space:
Admin
▼
:
Document Index
»
Page:
CheckDBEncoding
Search
en
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
WebHome
»
XWiki and MySQL Configuration Check
»
MySQL Encoding Check
Wiki source code of
MySQL Encoding Check
Last modified by
Administrator
on 2010/09/22 19:08
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: {{groovy}} 2: 3: println context.getDatabase() 4: println context.getOriginalDatabase() 5: def context2 = context.getContext(); 6: def store = xwiki.getXWiki().getStore().getStore(); 7: def wikilist = xwiki.isVirtual() ? xwiki.wikimanager.getAllWikis() : [ context.getOriginalDatabase() ]; 8: def indexes = xwiki.getDocument("Admin.CheckIndexesSQL").getContent().split("n") 9: 10: println "1.1 General db settings" 11: 12: try { 13: store.beginTransaction(context2); 14: def session = store.getSession(context2); 15: def connection = session.connection(); 16: def stmt = connection.createStatement(); 17: stmt.execute("show variables like 'character_set_%'"); 18: def rset = stmt.getResultSet(); 19: def result = null; 20: 21: while (rset.next()) { 22: def varname = rset.getString(1); 23: def varvalue = rset.getString(2); 24: if (varname!="character_sets_dir") { 25: println "* MYSQL encoding setting {{velocity filter="none"}} 26: ${varname}: ${varvalue}" 27: } 28: } 29: stmt.close(); 30: } catch (Exception e) { 31: println "* <font color='red'>Failed to check mysql encoding</font>: " + e.getMessage() 32: } finally { 33: store.endTransaction(context2, false); 34: } 35: 36: println "1.1 General db collation settings" 37: 38: try { 39: store.beginTransaction(context2); 40: def session = store.getSession(context2); 41: def connection = session.connection(); 42: def stmt = connection.createStatement(); 43: stmt.execute("show variables like 'collation%'"); 44: def rset = stmt.getResultSet(); 45: def result = null; 46: 47: while (rset.next()) { 48: def varname = rset.getString(1); 49: def varvalue = rset.getString(2); 50: println "* MYSQL collation setting ${varname}: ${varvalue}" 51: } 52: stmt.close(); 53: } catch (Exception e) { 54: println "* <font color='red'>Failed to check mysql encoding</font>: " + e.getMessage() 55: } finally { 56: store.endTransaction(context2, false); 57: } 58: 59: println "1.1 Encoding settings by wiki" 60: 61: if (!wikilist.contains("xwiki")) 62: wikilist.add(0, "xwiki") 63: for(wiki in wikilist) { 64: // check database encoding 65: try { 66: store.beginTransaction(context2); 67: def session = store.getSession(context2); 68: def connection = session.connection(); 69: def stmt = connection.createStatement(); 70: stmt.execute("show create database ${wiki}"); 71: def rset = stmt.getResultSet(); 72: def result = null; 73: try { 74: rset.first(); 75: result = rset.getString(2); 76: } catch (Exception e2) {} 77: 78: // println result 79: def i1 = result.indexOf("DEFAULT CHARACTER SET") 80: def i2 = result.indexOf("*", i1) 81: if (result!=null && i1!=-1) { 82: def enc = result.substring(i1 + 22, i2); 83: println "* database encoding of ${wiki} is ${enc}" 84: } else { 85: println "* <font color='red'>Could not find xwikidoc encoding for wiki ${wiki}</font>" 86: } 87: stmt.close(); 88: } catch (Exception e) { 89: println "* <font color='red'>Failed to check xwikidoc encoding for wiki ${wiki}</font>: " + e.getMessage() 90: } finally { 91: store.endTransaction(context2, false); 92: } 93: 94: // check xwikidoc table encoding 95: try { 96: store.beginTransaction(context2); 97: def session = store.getSession(context2); 98: def connection = session.connection(); 99: def stmt = connection.createStatement(); 100: stmt.execute("show create table ${wiki}.xwikidoc"); 101: def rset = stmt.getResultSet(); 102: def result = null; 103: try { 104: rset.first(); 105: result = rset.getString(2); 106: } catch (Exception e2) {} 107: 108: // println result 109: def i1 = -1; 110: def i2 = -1; 111: i1 = result.indexOf("DEFAULT CHARSET="); 112: if (i1!=-1) 113: i2 = result.indexOf(" ", i1 + 16); 114: if (result!=null && i1!=-1) { 115: def enc = (i2==-1) ? result.substring(i1 + 16) : result.substring(i1 + 8, i2); 116: println "* encoding of xwikidoc of ${wiki} is ${enc}" 117: } else { 118: println "* <font color='red'>Could not find xwikidoc encoding for wiki ${wiki}</font>" 119: } 120: 121: i1 = result.indexOf("COLLATE=") 122: if (i1!=-1) 123: i2 = result.indexOf(" ", i1+8) 124: if (result!=null && i1!=-1) { 125: def enc = (i2==-1) ? result.substring(i1 + 8) : result.substring(i1 + 8, i2); 126: println "* collation of xwikidoc of ${wiki} is ${enc}" 127: } else { 128: println "* <font color='red'>Could not find xwikidoc collation for wiki ${wiki}</font>" 129: } 130: 131: stmt.close(); 132: } catch (Exception e) { 133: println "* <font color='red'>Failed to check xwikidoc encoding or collation for wiki ${wiki} 134: {{/velocity}}</font>: " + e.getMessage() 135: } finally { 136: store.endTransaction(context2, false); 137: } 138: } 139: {{/groovy}}