diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2018-02-08 00:42:25 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2018-02-08 00:42:25 +0000 |
commit | 2cca13b956cbb56dc19f49c454ccee9b239059c5 (patch) | |
tree | 8be6d971cdc24fcd056792a79c03c893c251a346 /src/test | |
parent | 25b31c99f9d0802b3f4a2c66b9e1cf7e7fed1068 (diff) | |
parent | 71d884e1ad50d415ad781a217f64ee57c31b8081 (diff) | |
download | jackcess-2cca13b956cbb56dc19f49c454ccee9b239059c5.tar.gz jackcess-2cca13b956cbb56dc19f49c454ccee9b239059c5.zip |
merge trunk changes through r1138
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1139 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test')
3 files changed, 133 insertions, 3 deletions
diff --git a/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java b/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java index 89ab4c4..69eb7c6 100644 --- a/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java @@ -68,13 +68,15 @@ public class PropertiesTest extends TestCase assertSame(colMap, maps.get("TESTCOL")); assertEquals("testcol", colMap.getName()); - defMap.put("foo", DataType.TEXT, (byte)0, "bar"); - defMap.put("baz", DataType.LONG, (byte)1, 13); + defMap.put("foo", DataType.TEXT, "bar", false); + defMap.put("baz", DataType.LONG, 13, true); assertFalse(defMap.isEmpty()); assertEquals(2, defMap.getSize()); + assertFalse(defMap.get("foo").isDdl()); + assertTrue(defMap.get("baz").isDdl()); - colMap.put("buzz", DataType.BOOLEAN, (byte)0, Boolean.TRUE); + colMap.put("buzz", DataType.BOOLEAN, Boolean.TRUE, true); assertFalse(colMap.isEmpty()); assertEquals(1, colMap.getSize()); diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/BigIntTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/BigIntTest.java new file mode 100644 index 0000000..143ac9b --- /dev/null +++ b/src/test/java/com/healthmarketscience/jackcess/impl/BigIntTest.java @@ -0,0 +1,102 @@ +/* +Copyright (c) 2017 James Ahlborn + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package com.healthmarketscience.jackcess.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; + +import com.healthmarketscience.jackcess.Column; +import com.healthmarketscience.jackcess.ColumnBuilder; +import com.healthmarketscience.jackcess.Cursor; +import com.healthmarketscience.jackcess.CursorBuilder; +import com.healthmarketscience.jackcess.DataType; +import com.healthmarketscience.jackcess.Database; +import com.healthmarketscience.jackcess.IndexBuilder; +import com.healthmarketscience.jackcess.Table; +import com.healthmarketscience.jackcess.TableBuilder; +import junit.framework.TestCase; +import static com.healthmarketscience.jackcess.TestUtil.*; +import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; + +/** + * + * @author James Ahlborn + */ +public class BigIntTest extends TestCase +{ + + public BigIntTest(String name) throws Exception { + super(name); + } + + public void testBigInt() throws Exception { + + for (final Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + JetFormat format = DatabaseImpl.getFileFormatDetails(fileFormat) + .getFormat(); + + if(!format.isSupportedDataType(DataType.BIG_INT)) { + continue; + } + + Database db = create(fileFormat); + + Table t = new TableBuilder("Test") + .addColumn(new ColumnBuilder("id", DataType.LONG) + .setAutoNumber(true)) + .addColumn(new ColumnBuilder("data1", DataType.TEXT)) + .addColumn(new ColumnBuilder("num1", DataType.BIG_INT)) + .addIndex(new IndexBuilder("idx").addColumns("num1")) + .toTable(db); + + long[] vals = new long[] { + 0L, -10L, 3844L, -45309590834L, 50392084913L, 65000L, -6489273L}; + + List<Map<String, Object>> expectedTable = + new ArrayList<Map<String, Object>>(); + + int idx = 1; + for(long lng : vals) { + t.addRow(Column.AUTO_NUMBER, "" + lng, lng); + + expectedTable.add(createExpectedRow( + "id", idx++, + "data1", "" + lng, + "num1", lng)); + } + + Collections.sort(expectedTable, new Comparator<Map<String, Object>>() { + public int compare( + Map<String, Object> r1, + Map<String, Object> r2) { + Long l1 = (Long)r1.get("num1"); + Long l2 = (Long)r2.get("num1"); + return l1.compareTo(l2); + } + }); + + Cursor c = new CursorBuilder(t).setIndexByName("idx").toIndexCursor(); + + assertCursor(expectedTable, c); + + db.close(); + } + } +} diff --git a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java index b302985..1ed17b7 100644 --- a/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/impl/JetFormatTest.java @@ -5,11 +5,13 @@ import java.io.IOException; import java.io.InputStream; import java.nio.channels.FileChannel; import java.nio.channels.NonWritableChannelException; +import java.sql.SQLException; import java.util.ArrayList; import java.util.EnumSet; import java.util.List; import java.util.Set; +import com.healthmarketscience.jackcess.DataType; import com.healthmarketscience.jackcess.Database; import static com.healthmarketscience.jackcess.Database.*; import com.healthmarketscience.jackcess.DatabaseBuilder; @@ -265,6 +267,30 @@ public class JetFormatTest extends TestCase { } } + public void testSqlTypes() throws Exception { + + JetFormat v2000 = JetFormat.VERSION_4; + for(DataType dt : DataType.values()) { + if(v2000.isSupportedDataType(dt)) { + Integer sqlType = null; + try { + sqlType = dt.getSQLType(); + } catch(SQLException ignored) {} + + if(sqlType != null) { + assertEquals(dt, DataType.fromSQLType(sqlType)); + } + } + } + + assertEquals(DataType.LONG, DataType.fromSQLType(java.sql.Types.BIGINT)); + assertEquals(DataType.BIG_INT, DataType.fromSQLType( + java.sql.Types.BIGINT, 0, Database.FileFormat.V2016)); + assertEquals(java.sql.Types.BIGINT, DataType.BIG_INT.getSQLType()); + assertEquals(DataType.MEMO, DataType.fromSQLType( + java.sql.Types.VARCHAR, 1000)); + } + public static void transferDbFrom(FileChannel channel, InputStream in) throws IOException { |