From: James Ahlborn Date: Thu, 31 Mar 2011 03:58:26 +0000 (+0000) Subject: add method to grab default sort order X-Git-Tag: jackcess-1.2.4~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=72f50d3386f4432cec006e7167d0da1d1ae831c8;p=jackcess.git add method to grab default sort order git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@541 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 5915d2c..9fd6b3b 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -398,6 +398,8 @@ public class Database private Charset _charset; /** timezone to use when handling dates */ private TimeZone _timeZone; + /** language sort order to be used for textual columns */ + private Short _defaultSortOrder; /** the ordering used for table columns */ private Table.ColumnOrder _columnOrder; /** cache of in-use tables */ @@ -887,6 +889,19 @@ public class Database return _fileFormat; } + /** + * @return the currently configured database default language sort order for + * textual columns + */ + public short getDefaultSortOrder() throws IOException { + + if(_defaultSortOrder == null) { + _pageChannel.readPage(_buffer, 0); + _defaultSortOrder = _buffer.getShort(_format.OFFSET_SORT_ORDER); + } + return _defaultSortOrder; + } + /** * @return a PropertyMaps instance decoded from the given bytes (always * returns non-{@code null} result). diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java index dbe3e47..f319b24 100644 --- a/src/java/com/healthmarketscience/jackcess/JetFormat.java +++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java @@ -175,6 +175,7 @@ public abstract class JetFormat { public final int OFFSET_HEADER_DATE; public final int OFFSET_PASSWORD; public final int SIZE_PASSWORD; + public final int OFFSET_SORT_ORDER; public final int OFFSET_ENCODING_KEY; public final int OFFSET_NEXT_TABLE_DEF_PAGE; public final int OFFSET_NUM_ROWS; @@ -300,6 +301,7 @@ public abstract class JetFormat { OFFSET_HEADER_DATE = defineOffsetHeaderDate(); OFFSET_PASSWORD = defineOffsetPassword(); SIZE_PASSWORD = defineSizePassword(); + OFFSET_SORT_ORDER = defineOffsetSortOrder(); OFFSET_ENCODING_KEY = defineOffsetEncodingKey(); OFFSET_NEXT_TABLE_DEF_PAGE = defineOffsetNextTableDefPage(); OFFSET_NUM_ROWS = defineOffsetNumRows(); @@ -393,6 +395,7 @@ public abstract class JetFormat { protected abstract int defineOffsetHeaderDate(); protected abstract int defineOffsetPassword(); protected abstract int defineSizePassword(); + protected abstract int defineOffsetSortOrder(); protected abstract int defineOffsetEncodingKey(); protected abstract int defineOffsetNextTableDefPage(); protected abstract int defineOffsetNumRows(); @@ -520,6 +523,8 @@ public abstract class JetFormat { @Override protected int defineSizePassword() { return 20; } @Override + protected int defineOffsetSortOrder() { return 58; } + @Override protected int defineOffsetEncodingKey() { return 62; } @Override protected int defineOffsetNextTableDefPage() { return 4; } @@ -715,6 +720,8 @@ public abstract class JetFormat { @Override protected int defineSizePassword() { return 40; } @Override + protected int defineOffsetSortOrder() { return 110; } + @Override protected int defineOffsetEncodingKey() { return 62; } @Override protected int defineOffsetNextTableDefPage() { return 4; } diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index 367d669..7c1dbe3 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -1130,6 +1130,16 @@ public class DatabaseTest extends TestCase { db.close(); } } + + public void testDbSortOrder() throws Exception { + + for (final TestDB testDB : SUPPORTED_DBS_TEST_FOR_READ) { + + Database db = open(testDB); + assertEquals(Column.GENERAL_SORT_ORDER, db.getDefaultSortOrder()); + db.close(); + } + } static Object[] createTestRow(String col1Val) { return new Object[] {col1Val, "R", "McCune", 1234, (byte) 0xad, 555.66d,