summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Index.java26
-rw-r--r--src/java/com/healthmarketscience/jackcess/JetFormat.java15
2 files changed, 34 insertions, 7 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java
index b629049..f72377a 100644
--- a/src/java/com/healthmarketscience/jackcess/Index.java
+++ b/src/java/com/healthmarketscience/jackcess/Index.java
@@ -1540,17 +1540,31 @@ public abstract class Index implements Comparable<Index> {
boolean isNegative = ((valueBytes[0] & 0x80) != 0);
// bit twiddling rules:
- // isAsc && !isNeg => setReverseSignByte
- // isAsc && isNeg => flipBytes, setReverseSignByte
- // !isAsc && !isNeg => flipBytes, setReverseSignByte
- // !isAsc && isNeg => setReverseSignByte
+ // isAsc && !isNeg => setReverseSignByte => FF 00 00 ...
+ // isAsc && isNeg => flipBytes, setReverseSignByte => 00 FF FF ...
+ // !isAsc && !isNeg => flipBytes, setReverseSignByte => FF FF FF ...
+ // !isAsc && isNeg => setReverseSignByte => 00 00 00 ...
+ // v2007 bit twiddling rules:
+ // isAsc && !isNeg => setSignByte 0xFF => FF 00 00 ...
+ // isAsc && isNeg => setSignByte 0xFF, flipBytes => 00 FF FF ...
+ // !isAsc && !isNeg => setSignByte 0xFF => FF 00 00 ...
+ // !isAsc && isNeg => setSignByte 0xFF, flipBytes => 00 FF FF ...
+
+ boolean alwaysRevFirstByte = getColumn().getFormat().REVERSE_FIRST_BYTE_IN_DESC_NUMERIC_INDEXES;
+ if(alwaysRevFirstByte) {
+ // reverse the sign byte (before any byte flipping)
+ valueBytes[0] = (byte)0xFF;
+ }
+
if(isNegative == isAscending()) {
flipBytes(valueBytes);
}
- // reverse the sign byte (after any previous byte flipping)
- valueBytes[0] = (isNegative ? (byte)0x00 : (byte)0xFF);
+ if(!alwaysRevFirstByte) {
+ // reverse the sign byte (after any previous byte flipping)
+ valueBytes[0] = (isNegative ? (byte)0x00 : (byte)0xFF);
+ }
bout.write(valueBytes);
}
diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java
index afb1804..62ce992 100644
--- a/src/java/com/healthmarketscience/jackcess/JetFormat.java
+++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java
@@ -130,6 +130,8 @@ public abstract class JetFormat {
public final int MAX_TABLE_NAME_LENGTH;
public final int MAX_COLUMN_NAME_LENGTH;
public final int MAX_INDEX_NAME_LENGTH;
+
+ public final boolean REVERSE_FIRST_BYTE_IN_DESC_NUMERIC_INDEXES;
public final Charset CHARSET;
@@ -230,7 +232,8 @@ public abstract class JetFormat {
MAX_TABLE_NAME_LENGTH = defineMaxTableNameLength();
MAX_COLUMN_NAME_LENGTH = defineMaxColumnNameLength();
MAX_INDEX_NAME_LENGTH = defineMaxIndexNameLength();
-
+
+ REVERSE_FIRST_BYTE_IN_DESC_NUMERIC_INDEXES = defineReverseFirstByteInDescNumericIndexes();
CHARSET = defineCharset();
}
@@ -305,6 +308,8 @@ public abstract class JetFormat {
protected abstract Charset defineCharset();
+ protected abstract boolean defineReverseFirstByteInDescNumericIndexes();
+
@Override
public String toString() {
return _name;
@@ -449,6 +454,9 @@ public abstract class JetFormat {
protected int defineMaxIndexNameLength() { return 64; }
@Override
+ protected boolean defineReverseFirstByteInDescNumericIndexes() { return false; }
+
+ @Override
protected Charset defineCharset() { return Charset.forName("UTF-16LE"); }
}
@@ -462,5 +470,10 @@ public abstract class JetFormat {
private Jet5Format() {
super("VERSION_5");
}
+
+ @Override
+ protected boolean defineReverseFirstByteInDescNumericIndexes() { return true; }
+
}
+
}