From 148263e48022b5a7213068b118c9ac7bf024d47a Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 15 Jun 2006 12:10:37 +0000 Subject: [PATCH] more fixes for writing MEMO/OLE git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@56 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/DataType.java | 4 +-- .../healthmarketscience/jackcess/Table.java | 16 ++++----- .../jackcess/DatabaseTest.java | 36 ++++++++++++++++--- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/java/com/healthmarketscience/jackcess/DataType.java b/src/java/com/healthmarketscience/jackcess/DataType.java index 85358ec..5d07cb6 100644 --- a/src/java/com/healthmarketscience/jackcess/DataType.java +++ b/src/java/com/healthmarketscience/jackcess/DataType.java @@ -48,8 +48,8 @@ public enum DataType { SHORT_DATE_TIME((byte) 0x08, Types.TIMESTAMP, 8), BINARY((byte) 0x09, Types.BINARY, 255, true), TEXT((byte) 0x0A, Types.VARCHAR, 50 * 2, true), - OLE((byte) 0x0B, Types.LONGVARBINARY, 12), - MEMO((byte) 0x0C, Types.LONGVARCHAR, 12), + OLE((byte) 0x0B, Types.LONGVARBINARY, 12, true), + MEMO((byte) 0x0C, Types.LONGVARCHAR, 12, true), UNKNOWN_0D((byte) 0x0D), GUID((byte) 0x0F, null, 16), NUMERIC((byte) 0x10, Types.NUMERIC, 17); diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index f3fbe43..c09792e 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -375,14 +375,14 @@ public class Table { * is much more efficient than calling addRow multiple times. * @param rows List of Object[] row values */ - public void addRows(List rows) throws IOException { + public void addRows(List rows) throws IOException { ByteBuffer dataPage = _pageChannel.createPageBuffer(); ByteBuffer[] rowData = new ByteBuffer[rows.size()]; - Iterator iter = rows.iterator(); + Iterator iter = rows.iterator(); for (int i = 0; iter.hasNext(); i++) { rowData[i] = createRow((Object[]) iter.next()); } - List pageNumbers = _ownedPages.getPageNumbers(); + List pageNumbers = _ownedPages.getPageNumbers(); int pageNumber; int rowSize; if (pageNumbers.size() == 0) { @@ -428,9 +428,9 @@ public class Table { rowCount * _format.SIZE_ROW_LOCATION, rowLocation); dataPage.position(rowLocation); dataPage.put(rowData[i]); - iter = _indexes.iterator(); - while (iter.hasNext()) { - Index index = (Index) iter.next(); + Iterator indIter = _indexes.iterator(); + while (indIter.hasNext()) { + Index index = (Index) indIter.next(); index.addRow((Object[]) rows.get(i), pageNumber, (byte) rowCount); } } @@ -440,11 +440,11 @@ public class Table { ByteBuffer tdefPage = _pageChannel.createPageBuffer(); _pageChannel.readPage(tdefPage, _tableDefPageNumber); tdefPage.putInt(_format.OFFSET_NUM_ROWS, ++_rowCount); - iter = _indexes.iterator(); + Iterator indIter = _indexes.iterator(); for (int i = 0; i < _indexes.size(); i++) { tdefPage.putInt(_format.OFFSET_INDEX_DEF_BLOCK + i * _format.SIZE_INDEX_DEFINITION + 4, _rowCount); - Index index = (Index) iter.next(); + Index index = (Index) indIter.next(); index.update(); } _pageChannel.writePage(tdefPage, _tableDefPageNumber); diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index a2d1ba1..84f5a22 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -67,7 +67,7 @@ public class DatabaseTest extends TestCase { assertEquals(1, db.getTableNames().size()); Table table = db.getTable("Table1"); - Map row = table.getNextRow(); + Map row = table.getNextRow(); assertEquals("abcdefg", row.get("A")); assertEquals("hijklmnop", row.get("B")); assertEquals(new Byte((byte) 2), row.get("C")); @@ -112,7 +112,7 @@ public class DatabaseTest extends TestCase { table.addRow(row); } for (int i = 0; i < count; i++) { - Map readRow = table.getNextRow(); + Map readRow = table.getNextRow(); assertEquals(row[0], readRow.get("A")); assertEquals(row[1], readRow.get("B")); assertEquals(row[2], readRow.get("C")); @@ -136,7 +136,7 @@ public class DatabaseTest extends TestCase { Table table = db.getTable("Test"); table.addRows(rows); for (int i = 0; i < count; i++) { - Map readRow = table.getNextRow(); + Map readRow = table.getNextRow(); assertEquals(row[0], readRow.get("A")); assertEquals(row[1], readRow.get("B")); assertEquals(row[2], readRow.get("C")); @@ -188,8 +188,7 @@ public class DatabaseTest extends TestCase { public void testReadMemo() throws Exception { Database db = Database.open(new File("test/data/test2.mdb")); - String tableName = "MSP_PROJECTS"; - Table table = db.getTable(tableName); + Table table = db.getTable("MSP_PROJECTS"); Map row = table.getNextRow(); assertEquals("Jon Iles this is a a vawesrasoih aksdkl fas dlkjflkasjd flkjaslkdjflkajlksj dfl lkasjdf lkjaskldfj lkas dlk lkjsjdfkl; aslkdf lkasjkldjf lka skldf lka sdkjfl;kasjd falksjdfljaslkdjf laskjdfk jalskjd flkj aslkdjflkjkjasljdflkjas jf;lkasjd fjkas dasdf asd fasdf asdf asdmhf lksaiyudfoi jasodfj902384jsdf9 aw90se fisajldkfj lkasj dlkfslkd jflksjadf as", row.get("PROJ_PROP_AUTHOR")); assertEquals("T", row.get("PROJ_PROP_COMPANY")); @@ -197,6 +196,33 @@ public class DatabaseTest extends TestCase { assertEquals("Project1", row.get("PROJ_PROP_TITLE")); } + public void testWriteMemo() throws Exception { + + Database db = create(); + + List columns = new ArrayList(); + Column col = new Column(); + col.setName("A"); + col.setType(DataType.TEXT); + columns.add(col); + col = new Column(); + col.setName("B"); + col.setType(DataType.MEMO); + columns.add(col); + db.createTable("test", columns); + + String testStr = "This is a test"; + + Table table = db.getTable("Test"); + table.addRow(new Object[]{testStr, testStr}); + + Map row = table.getNextRow(); + + assertEquals(testStr, row.get("A")); + assertEquals(testStr, row.get("B")); + + } + public void testMissingFile() throws Exception { File bogusFile = new File("fooby-dooby.mdb"); assertTrue(!bogusFile.exists()); -- 2.39.5