Skip to content

Commit

Permalink
Merge pull request #9 from umjammer/0.0.9
Browse files Browse the repository at this point in the history
0.0.9
  • Loading branch information
umjammer authored Oct 28, 2024
2 parents 495bbaf + d38567f commit 838fb6a
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 115 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ accessing Microsoft Access files directory and it's jdbc implementation (where c
as a jdbc

```java
DriverManager.registerDriver(new vavi.sql.mdb.jdbc.Driver());
conn = DriverManager.getConnection("jdbc:mdb:" + "foo/bar.mdb");
```

Expand All @@ -43,6 +42,7 @@ as a jdbc
* details (metadata, implementation of operator)
* memo: cut with 0 at the last?
* currency: implement in java Currency
* https://github.com/JavaMoney
* fuzzing
* https://github.com/mdbtools/mdbtools/tree/dev/src/fuzz
* https://github.com/CodeIntelligenceTesting/jazzer
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-sql-mdb</artifactId>
<version>0.0.8</version>
<version>0.0.9</version>

<name>Vavi SQL MDB API</name>
<organization>
Expand All @@ -28,15 +28,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.12.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<configuration>
<argLine>
-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties
Expand All @@ -52,7 +52,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.2</version>
<version>5.10.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -74,7 +74,7 @@
<dependency>
<groupId>com.github.umjammer</groupId>
<artifactId>vavi-commons</artifactId>
<version>1.1.13</version>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>com.github.jsqlparser</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vavi/apps/mdbtools/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public String getName() {
public boolean testSargs(MdbFile mdb, int offset, int len) {

for (Sarg sarg : sargs) {
if (sarg.testSarg(mdb, this, offset, len) == 0) {
if (!sarg.isSarg(mdb, this, offset, len)) {
// sarg didn't match, no sense going on
return false;
}
Expand Down
77 changes: 33 additions & 44 deletions src/main/java/vavi/apps/mdbtools/Currency.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@
* @author <a href="mailto:[email protected]">Naohide Sano</a> (nsano)
* @version 0.00 050408 nsano ported from mdbtool <br>
*/
public class Currency {
class Currency {

/** */
private static final int MAXPRECISION = 20;
private static final int MAX_PRECISION = 20;

/** */
public static String mdb_money_to_string(MdbFile mdb, int start) {
public static String moneyToString(byte[] buffer, int start) {
final int numberOfBytes = 8;
byte[] b = new byte[numberOfBytes];
System.arraycopy(mdb.getPageBuffer(), start, b, 0, numberOfBytes);
System.arraycopy(buffer, start, b, 0, numberOfBytes);

String s;
int[] multiplier = new int[MAXPRECISION];
int[] temp = new int[MAXPRECISION];
int[] product = new int[MAXPRECISION];
int[] multiplier = new int[MAX_PRECISION];
int[] temp = new int[MAX_PRECISION];
int[] product = new int[MAX_PRECISION];

int negative = 0;

Expand All @@ -54,67 +53,57 @@ public static String mdb_money_to_string(MdbFile mdb, int start) {

b[7] = 0;
for (int pos = 0; pos < numberOfBytes; pos++) {
multiply_byte(product, b[pos] & 0xff, multiplier);
multiplyByte(product, b[pos] & 0xff, multiplier);

System.arraycopy(multiplier, 0, temp, 0, MAXPRECISION);
System.arraycopy(multiplier, 0, temp, 0, MAX_PRECISION);
Arrays.fill(multiplier, 0);
multiply_byte(multiplier, 256, temp);
multiplyByte(multiplier, 256, temp);
}
if (negative != 0) {
s = "-" + array_to_string(product, 4);
} else {
s = array_to_string(product, 4);
}
return s;
return ((negative != 0) ? "-" : "") + arrayToString(product, 4);
}

private static int multiply_byte(int[] product, int num, int[] multiplier) {
int[] number = new int[3];
int i, top, j, start;

number[0] = num % 10;
number[1] = (num / 10) % 10;
number[2] = (num / 100) % 10;

for (top = MAXPRECISION - 1; top >= 0 && multiplier[top] == 0; top--)
;
start = 0;
for (i = 0; i <= top; i++) {
for (j = 0; j < 3; j++) {
private static void multiplyByte(int[] product, int num, int[] multiplier) {
int[] number = new int[] {
num % 10,
(num / 10) % 10,
(num / 100) % 10
};

int top = MAX_PRECISION - 1;
while (top >= 0 && multiplier[top] == 0)
top--;
int start = 0;
for (int i = 0; i <= top; i++) {
for (int j = 0; j < 3; j++) {
product[j + start] += multiplier[i] * number[j];
}
do_carry(product);
doCarry(product);
start++;
}
return 0;
}

private static int do_carry(int[] product) {
int j;

for (j = 0; j < MAXPRECISION; j++) {
private static void doCarry(int[] product) {
for (int j = 0; j < MAX_PRECISION; j++) {
if (product[j] > 9) {
product[j + 1] += product[j] / 10;
product[j] = product[j] % 10;
}
}
return 0;
}

static String array_to_string(int[] array, int scale) {
int top, i, j;

for (top = MAXPRECISION - 1; top >= 0 && top > scale && array[top] == 0; top--)
;
private static String arrayToString(int[] array, int scale) {
int top = MAX_PRECISION - 1;
while (top >= 0 && top > scale && array[top] == 0)
top--;

if (top == -1) {
return "0";
}

j = 0;
int j = 0;
char[] s = new char[100];
// TODO find a better number
for (i = top; i >= 0; i--) {
for (int i = top; i >= 0; i--) {
if (top + 1 - j == scale)
s[j++] = '.';
s[j++] = (char) (array[i] + '0');
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/vavi/apps/mdbtools/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,21 @@ enum Order {

/** */
public boolean testSargs(MdbFile mdb, int offset, int len) {
int c_offset = 0, c_len;
int cOffset = 0, cLen;

for (int i = 0; i < numberOfKeys; i++) {
c_offset++; // the per column null indicator/flags
cOffset++; // the per column null indicator/flags
Column col = table.columns.get(keyColNum[i] - 1);

// This will go away eventually

if (col.type == Column.Type.TEXT) {
c_len = 0;
while (mdb.readByte(offset + c_offset + c_len) != 0) {
c_len++;
cLen = 0;
while (mdb.readByte(offset + cOffset + cLen) != 0) {
cLen++;
}
} else {
c_len = col.size;
cLen = col.size;
//logger.log(Level.TRACE, "Only text types currently supported. How did we get here?");
}

Expand All @@ -217,7 +217,7 @@ public boolean testSargs(MdbFile mdb, int offset, int len) {

for (int j = 0; j < col.sargs.size(); j++) {
Sarg sarg = col.indexSargCache.get(j);
if (sarg.testSarg(mdb, col, offset + c_offset, c_len) == 0) {
if (!sarg.isSarg(mdb, col, offset + cOffset, cLen)) {
// sarg didn't match, no sense going on
return false;
}
Expand Down Expand Up @@ -251,7 +251,7 @@ private static int swapInt32(int l) {
}

/** */
void cacheSarg(Column col, Sarg sarg, Sarg idxSarg) {
private static void cacheSarg(Column col, Sarg sarg, Sarg idxSarg) {

switch (col.type) {
case TEXT:
Expand All @@ -269,7 +269,7 @@ void cacheSarg(Column col, Sarg sarg, Sarg idxSarg) {
}

/** */
void walk(Table table) throws IOException {
private void walk(Table table) throws IOException {
MdbFile mdb = table.catalogEntry.mdb;

if (numberOfKeys != 1) {
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/vavi/apps/mdbtools/MdbFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,27 +514,27 @@ void swapPageBuffer() {
System.arraycopy(tmpbuf, 0, altPageBuffer, 0, PAGE_SIZE);
}

/** */
@Deprecated
int readByte(int offset) {
int c = pageBuffer[offset] & 0xff;
return c;
}

/** */
@Deprecated
int read16Bit(byte[] buffer, int offset) {
int value = ((buffer[offset + 1] & 0xff) << 8) | (buffer[offset] & 0xff);
//logger.log(Level.TRACE, "offset: " + StringUtil.toHex4(offset) + "(" + offset + "): " + StringUtil.toHex4(value) + "(" + value + ")");
return value & 0xffff;
}

/** */
@Deprecated
int readShort(int offset) {
int i = read16Bit(pageBuffer, offset);

return i;
}

/** */
@Deprecated
int read24BitMsb(int offset) {
int l = 0;

Expand All @@ -546,7 +546,7 @@ int read24BitMsb(int offset) {
return l;
}

/** */
@Deprecated
int read24Bit(int offset) {
int l = 0;

Expand All @@ -558,7 +558,7 @@ int read24Bit(int offset) {
return l;
}

/** */
@Deprecated
int read32Bit(byte[] buffer, int offset) {
long l = 0;

Expand All @@ -571,13 +571,14 @@ int read32Bit(byte[] buffer, int offset) {
return (int) (l & 0xffff_ffffL);
}

/** */
@Deprecated
int readInt(int offset) {
int l = read32Bit(pageBuffer, offset);
return l;
}

/** TODO */
@Deprecated
float readFloat(int offset) {
byte[] b = new byte[4];
System.arraycopy(pageBuffer, offset, b, 0, 4);
Expand All @@ -598,6 +599,7 @@ float readFloat(int offset) {
}

/** TODO */
@Deprecated
double readDouble(int offset) {
byte[] b = new byte[8];
System.arraycopy(pageBuffer, offset, b, 0, 8);
Expand Down Expand Up @@ -763,7 +765,7 @@ int index_find_next(Index index, List<IndexPage> pages, int[] page, int[] row) t
// stats

/** */
void stats_on() {
void setStatsOn() {
if (stats == null) {
stats = new Statistics();
}
Expand All @@ -772,7 +774,7 @@ void stats_on() {
}

/** */
void stats_off() {
void setStatsOff() {
if (stats == null) {
return;
}
Expand All @@ -781,7 +783,7 @@ void stats_off() {
}

/** */
void dump_stats() {
void dumpStats() {
if (stats == null) {
return;
}
Expand Down
Loading

0 comments on commit 838fb6a

Please sign in to comment.