From: James Ahlborn Date: Wed, 6 Apr 2011 03:29:03 +0000 (+0000) Subject: more tweaks to sort order reading in v1997; read code page info from db def page... X-Git-Tag: jackcess-1.2.4~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4523f0e90997ac50e948d0bbd69aa3a892f08611;p=jackcess.git more tweaks to sort order reading in v1997; read code page info from db def page and v1997 text columns git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@549 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index 13954cd..9636771 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -178,6 +178,8 @@ public class Column implements Comparable { private int _varLenTableIndex; /** the collating sort order for a text field */ private SortOrder _textSortOrder; + /** the code page for a text field (for certain db versions) */ + private short _textCodePage; /** the auto number generator for this column (if autonumber column) */ private AutoNumberGenerator _autoNumberGenerator; /** properties for this column, if any */ @@ -224,7 +226,11 @@ public class Column implements Comparable { } else if(_type.isTextual()) { // co-located w/ precision/scale _textSortOrder = readSortOrder( - buffer, offset + getFormat().OFFSET_COLUMN_PRECISION, getFormat()); + buffer, offset + getFormat().OFFSET_COLUMN_SORT_ORDER, getFormat()); + int cpOffset = getFormat().OFFSET_COLUMN_CODE_PAGE; + if(cpOffset >= 0) { + _textCodePage = buffer.getShort(offset + cpOffset); + } } byte flags = buffer.get(offset + getFormat().OFFSET_COLUMN_FLAGS); _variableLength = ((flags & FIXED_LEN_FLAG_MASK) == 0); @@ -366,6 +372,10 @@ public class Column implements Comparable { public void setTextSortOrder(SortOrder newTextSortOrder) { _textSortOrder = newTextSortOrder; } + + public short getTextCodePage() { + return _textCodePage; + } public void setLength(short length) { _columnLength = length; @@ -1427,6 +1437,9 @@ public class Column implements Comparable { } if(_type.isTextual()) { rtn.append("\n\tText Sort order: " + _textSortOrder); + if(_textCodePage > 0) { + rtn.append("\n\tText Code Page: " + _textCodePage); + } } rtn.append("\n\n"); return rtn.toString(); diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 46a148d..3691e22 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -278,7 +278,8 @@ public class Database /** Name of the system object that is the parent of all databases */ private static final String SYSTEM_OBJECT_NAME_DATABASES = "Databases"; /** Name of the system object that is the parent of all relationships */ - private static final String SYSTEM_OBJECT_NAME_RELATIONSHIPS = "Relationships"; + private static final String SYSTEM_OBJECT_NAME_RELATIONSHIPS = + "Relationships"; /** Name of the table that contains system access control entries */ private static final String TABLE_SYSTEM_ACES = "MSysACEs"; /** Name of the table that contains table relationships */ @@ -400,6 +401,8 @@ public class Database private TimeZone _timeZone; /** language sort order to be used for textual columns */ private Column.SortOrder _defaultSortOrder; + /** default code page to be used for textual columns (in some dbs) */ + private Short _defaultCodePage; /** the ordering used for table columns */ private Table.ColumnOrder _columnOrder; /** cache of in-use tables */ @@ -896,12 +899,32 @@ public class Database public Column.SortOrder getDefaultSortOrder() throws IOException { if(_defaultSortOrder == null) { - _pageChannel.readPage(_buffer, 0); - _defaultSortOrder = Column.readSortOrder( - _buffer, _format.OFFSET_SORT_ORDER, _format); + initRootPageInfo(); } return _defaultSortOrder; } + + /** + * @return the currently configured database default code page for textual + * data (may not be relevant to all database versions) + */ + public short getDefaultCodePage() throws IOException { + + if(_defaultCodePage == null) { + initRootPageInfo(); + } + return _defaultCodePage; + } + + /** + * Reads various config info from the db page 0. + */ + private void initRootPageInfo() throws IOException { + _pageChannel.readPage(_buffer, 0); + _defaultSortOrder = Column.readSortOrder( + _buffer, _format.OFFSET_SORT_ORDER, _format); + _defaultCodePage = _buffer.getShort(_format.OFFSET_CODE_PAGE); + } /** * @return a PropertyMaps instance decoded from the given bytes (always diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java index d1041a5..cfc5d97 100644 --- a/src/java/com/healthmarketscience/jackcess/JetFormat.java +++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java @@ -177,6 +177,7 @@ public abstract class JetFormat { public final int SIZE_PASSWORD; public final int OFFSET_SORT_ORDER; public final int SIZE_SORT_ORDER; + public final int OFFSET_CODE_PAGE; public final int OFFSET_ENCODING_KEY; public final int OFFSET_NEXT_TABLE_DEF_PAGE; public final int OFFSET_NUM_ROWS; @@ -198,6 +199,8 @@ public abstract class JetFormat { public final int OFFSET_COLUMN_NUMBER; public final int OFFSET_COLUMN_PRECISION; public final int OFFSET_COLUMN_SCALE; + public final int OFFSET_COLUMN_SORT_ORDER; + public final int OFFSET_COLUMN_CODE_PAGE; public final int OFFSET_COLUMN_FLAGS; public final int OFFSET_COLUMN_COMPRESSED_UNICODE; public final int OFFSET_COLUMN_LENGTH; @@ -305,6 +308,7 @@ public abstract class JetFormat { SIZE_PASSWORD = defineSizePassword(); OFFSET_SORT_ORDER = defineOffsetSortOrder(); SIZE_SORT_ORDER = defineSizeSortOrder(); + OFFSET_CODE_PAGE = defineOffsetCodePage(); OFFSET_ENCODING_KEY = defineOffsetEncodingKey(); OFFSET_NEXT_TABLE_DEF_PAGE = defineOffsetNextTableDefPage(); OFFSET_NUM_ROWS = defineOffsetNumRows(); @@ -326,6 +330,8 @@ public abstract class JetFormat { OFFSET_COLUMN_NUMBER = defineOffsetColumnNumber(); OFFSET_COLUMN_PRECISION = defineOffsetColumnPrecision(); OFFSET_COLUMN_SCALE = defineOffsetColumnScale(); + OFFSET_COLUMN_SORT_ORDER = defineOffsetColumnSortOrder(); + OFFSET_COLUMN_CODE_PAGE = defineOffsetColumnCodePage(); OFFSET_COLUMN_FLAGS = defineOffsetColumnFlags(); OFFSET_COLUMN_COMPRESSED_UNICODE = defineOffsetColumnCompressedUnicode(); OFFSET_COLUMN_LENGTH = defineOffsetColumnLength(); @@ -401,6 +407,7 @@ public abstract class JetFormat { protected abstract int defineSizePassword(); protected abstract int defineOffsetSortOrder(); protected abstract int defineSizeSortOrder(); + protected abstract int defineOffsetCodePage(); protected abstract int defineOffsetEncodingKey(); protected abstract int defineOffsetNextTableDefPage(); protected abstract int defineOffsetNumRows(); @@ -422,6 +429,8 @@ public abstract class JetFormat { protected abstract int defineOffsetColumnNumber(); protected abstract int defineOffsetColumnPrecision(); protected abstract int defineOffsetColumnScale(); + protected abstract int defineOffsetColumnSortOrder(); + protected abstract int defineOffsetColumnCodePage(); protected abstract int defineOffsetColumnFlags(); protected abstract int defineOffsetColumnCompressedUnicode(); protected abstract int defineOffsetColumnLength(); @@ -533,6 +542,8 @@ public abstract class JetFormat { @Override protected int defineSizeSortOrder() { return 2; } @Override + protected int defineOffsetCodePage() { return 60; } + @Override protected int defineOffsetEncodingKey() { return 62; } @Override protected int defineOffsetNextTableDefPage() { return 4; } @@ -573,6 +584,10 @@ public abstract class JetFormat { @Override protected int defineOffsetColumnScale() { return 12; } @Override + protected int defineOffsetColumnSortOrder() { return 9; } + @Override + protected int defineOffsetColumnCodePage() { return 11; } + @Override protected int defineOffsetColumnFlags() { return 13; } @Override protected int defineOffsetColumnCompressedUnicode() { return 16; } @@ -737,6 +752,8 @@ public abstract class JetFormat { @Override protected int defineSizeSortOrder() { return 4; } @Override + protected int defineOffsetCodePage() { return 60; } + @Override protected int defineOffsetEncodingKey() { return 62; } @Override protected int defineOffsetNextTableDefPage() { return 4; } @@ -777,6 +794,10 @@ public abstract class JetFormat { @Override protected int defineOffsetColumnScale() { return 12; } @Override + protected int defineOffsetColumnSortOrder() { return 11; } + @Override + protected int defineOffsetColumnCodePage() { return -1; } + @Override protected int defineOffsetColumnFlags() { return 15; } @Override protected int defineOffsetColumnCompressedUnicode() { return 16; }