1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.healthmarketscience.jackcess.impl;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Comparator;
22 import java.util.List;
23 import java.util.Map;
24
25 import com.healthmarketscience.jackcess.Column;
26 import com.healthmarketscience.jackcess.Cursor;
27 import com.healthmarketscience.jackcess.DataType;
28 import com.healthmarketscience.jackcess.Database;
29 import com.healthmarketscience.jackcess.Table;
30 import junit.framework.TestCase;
31 import static com.healthmarketscience.jackcess.TestUtil.*;
32 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
33 import static com.healthmarketscience.jackcess.DatabaseBuilder.*;
34
35
36
37
38
39 public class BigIntTest extends TestCase
40 {
41
42 public BigIntTest(String name) throws Exception {
43 super(name);
44 }
45
46 public void testBigInt() throws Exception {
47
48 for (final Database.FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
49 JetFormat format = DatabaseImpl.getFileFormatDetails(fileFormat)
50 .getFormat();
51
52 if(!format.isSupportedDataType(DataType.BIG_INT)) {
53 continue;
54 }
55
56 Database db = create(fileFormat);
57
58 Table t = newTable("Test")
59 .addColumn(newColumn("id", DataType.LONG)
60 .setAutoNumber(true))
61 .addColumn(newColumn("data1", DataType.TEXT))
62 .addColumn(newColumn("num1", DataType.BIG_INT))
63 .addIndex(newIndex("idx").addColumns("num1"))
64 .toTable(db);
65
66 long[] vals = new long[] {
67 0L, -10L, 3844L, -45309590834L, 50392084913L, 65000L, -6489273L};
68
69 List<Map<String, Object>> expectedTable =
70 new ArrayList<Map<String, Object>>();
71
72 int idx = 1;
73 for(long lng : vals) {
74 t.addRow(Column.AUTO_NUMBER, "" + lng, lng);
75
76 expectedTable.add(createExpectedRow(
77 "id", idx++,
78 "data1", "" + lng,
79 "num1", lng));
80 }
81
82 Collections.sort(expectedTable, (r1, r2) -> {
83 Long l1 = (Long)r1.get("num1");
84 Long l2 = (Long)r2.get("num1");
85 return l1.compareTo(l2);
86 });
87
88 Cursor c = t.newCursor().setIndexByName("idx").toIndexCursor();
89
90 assertCursor(expectedTable, c);
91
92 db.close();
93 }
94 }
95 }