summaryrefslogtreecommitdiffstats
path: root/src/java/com/healthmarketscience/jackcess/Database.java
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2006-09-08 18:48:32 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2006-09-08 18:48:32 +0000
commitabd574dd1afe6bf7bb33f5e05c9ecfec624401bd (patch)
tree1759bb5ba8abb5960d8f86974188718772042b38 /src/java/com/healthmarketscience/jackcess/Database.java
parentd89f63cae748a3e4f51185e392607ecd63c71a15 (diff)
downloadjackcess-abd574dd1afe6bf7bb33f5e05c9ecfec624401bd.tar.gz
jackcess-abd574dd1afe6bf7bb33f5e05c9ecfec624401bd.zip
clean up lots of cruft around datatypes; add more sanity checking on table creation; fix free space calculations
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@105 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience/jackcess/Database.java')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java
index b7240cf..ffed46a 100644
--- a/src/java/com/healthmarketscience/jackcess/Database.java
+++ b/src/java/com/healthmarketscience/jackcess/Database.java
@@ -356,6 +356,20 @@ public class Database
throw new IllegalArgumentException(
"Cannot create table with name of existing table");
}
+ if(columns.isEmpty()) {
+ throw new IllegalArgumentException(
+ "Cannot create table with no columns");
+ }
+
+ Set<String> colNames = new HashSet<String>();
+ // next, validate the column definitions
+ for(Column column : columns) {
+ column.validate();
+ if(!colNames.add(column.getName().toUpperCase())) {
+ throw new IllegalArgumentException("duplicate column name: " +
+ column.getName());
+ }
+ }
//We are creating a new page at the end of the db for the tdef.
int pageNumber = _pageChannel.getPageCount();
@@ -454,7 +468,7 @@ public class Database
buffer.putShort((short) 0);
}
buffer.putShort(columnNumber); //Column Number again
- if(col.getType() == DataType.NUMERIC) {
+ if(col.getType().getHasScalePrecision()) {
buffer.put((byte) col.getPrecision()); // numeric precision
buffer.put((byte) col.getScale()); // numeric scale
} else {
@@ -478,9 +492,13 @@ public class Database
buffer.putShort((short) 0);
} else {
buffer.putShort(fixedOffset);
- fixedOffset += col.getType().getSize();
+ fixedOffset += col.getType().getFixedSize();
+ }
+ if(!col.getType().isLongValue()) {
+ buffer.putShort(col.getLength()); //Column length
+ } else {
+ buffer.putShort((short)0x0000); // unused
}
- buffer.putShort(col.getLength()); //Column length
if (LOG.isDebugEnabled()) {
LOG.debug("Creating new column def block\n" + ByteUtil.toHexString(
buffer, position, _format.SIZE_COLUMN_DEF_BLOCK));
@@ -598,6 +616,7 @@ public class Database
List<Column> columns = new LinkedList<Column>();
int textCount = 0;
int totalSize = 0;
+ // FIXME, there is some ugly (and broken) logic here...
for (int i = 1; i <= md.getColumnCount(); i++) {
DataType accessColumnType = DataType.fromSQLType(md.getColumnType(i));
switch (accessColumnType) {