General Actions:
Log-in
Register
Wiki:
Main wiki
▼
:
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/24 19:35
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: <% 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 ${varname}: ${varvalue}" 26: } 27: } 28: stmt.close(); 29: } catch (Exception e) { 30: println "* <font color='red'>Failed to check mysql encoding</font>: " + e.getMessage() 31: } finally { 32: store.endTransaction(context2, false); 33: } 34: 35: println "1.1 General db collation settings" 36: 37: try { 38: store.beginTransaction(context2); 39: def session = store.getSession(context2); 40: def connection = session.connection(); 41: def stmt = connection.createStatement(); 42: stmt.execute("show variables like 'collation%'"); 43: def rset = stmt.getResultSet(); 44: def result = null; 45: 46: while (rset.next()) { 47: def varname = rset.getString(1); 48: def varvalue = rset.getString(2); 49: println "* MYSQL collation setting ${varname}: ${varvalue}" 50: } 51: stmt.close(); 52: } catch (Exception e) { 53: println "* <font color='red'>Failed to check mysql encoding</font>: " + e.getMessage() 54: } finally { 55: store.endTransaction(context2, false); 56: } 57: 58: println "1.1 Encoding settings by wiki" 59: 60: if (!wikilist.contains("xwiki")) 61: wikilist.add(0, "xwiki") 62: for(wiki in wikilist) { 63: // check database encoding 64: try { 65: store.beginTransaction(context2); 66: def session = store.getSession(context2); 67: def connection = session.connection(); 68: def stmt = connection.createStatement(); 69: stmt.execute("show create database ${wiki}"); 70: def rset = stmt.getResultSet(); 71: def result = null; 72: try { 73: rset.first(); 74: result = rset.getString(2); 75: } catch (Exception e2) {} 76: 77: // println result 78: def i1 = result.indexOf("DEFAULT CHARACTER SET") 79: def i2 = result.indexOf("*", i1) 80: if (result!=null && i1!=-1) { 81: def enc = result.substring(i1 + 22, i2); 82: println "* database encoding of ${wiki} is ${enc}" 83: } else { 84: println "* <font color='red'>Could not find xwikidoc encoding for wiki ${wiki}</font>" 85: } 86: stmt.close(); 87: } catch (Exception e) { 88: println "* <font color='red'>Failed to check xwikidoc encoding for wiki ${wiki}</font>: " + e.getMessage() 89: } finally { 90: store.endTransaction(context2, false); 91: } 92: 93: // check xwikidoc table encoding 94: try { 95: store.beginTransaction(context2); 96: def session = store.getSession(context2); 97: def connection = session.connection(); 98: def stmt = connection.createStatement(); 99: stmt.execute("show create table ${wiki}.xwikidoc"); 100: def rset = stmt.getResultSet(); 101: def result = null; 102: try { 103: rset.first(); 104: result = rset.getString(2); 105: } catch (Exception e2) {} 106: 107: // println result 108: def i1 = -1; 109: def i2 = -1; 110: i1 = result.indexOf("DEFAULT CHARSET="); 111: if (i1!=-1) 112: i2 = result.indexOf(" ", i1 + 16); 113: if (result!=null && i1!=-1) { 114: def enc = (i2==-1) ? result.substring(i1 + 16) : result.substring(i1 + 8, i2); 115: println "* encoding of xwikidoc of ${wiki} is ${enc}" 116: } else { 117: println "* <font color='red'>Could not find xwikidoc encoding for wiki ${wiki}</font>" 118: } 119: 120: i1 = result.indexOf("COLLATE=") 121: if (i1!=-1) 122: i2 = result.indexOf(" ", i1+8) 123: if (result!=null && i1!=-1) { 124: def enc = (i2==-1) ? result.substring(i1 + 8) : result.substring(i1 + 8, i2); 125: println "* collation of xwikidoc of ${wiki} is ${enc}" 126: } else { 127: println "* <font color='red'>Could not find xwikidoc collation for wiki ${wiki}</font>" 128: } 129: 130: stmt.close(); 131: } catch (Exception e) { 132: println "* <font color='red'>Failed to check xwikidoc encoding or collation for wiki ${wiki}</font>: " + e.getMessage() 133: } finally { 134: store.endTransaction(context2, false); 135: } 136: } 137: %>