diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2008-07-19 01:42:54 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2008-07-19 01:42:54 +0000 |
commit | 16d611821a3b6cba866ab596cd5a53b3533e68f8 (patch) | |
tree | 83772ee7be598dc1fe960d2c607413a215b93cc1 /src/java/com/healthmarketscience/jackcess/Database.java | |
parent | 030b1109019a49e70afe8ce83e4fcbcbd3ce0733 (diff) | |
download | jackcess-16d611821a3b6cba866ab596cd5a53b3533e68f8.tar.gz jackcess-16d611821a3b6cba866ab596cd5a53b3533e68f8.zip |
Add some more limit checking into table creation based on what access supports (max rows per table, max identifier lengths).
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@361 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience/jackcess/Database.java')
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Database.java | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 189c9cc..c45d998 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -489,15 +489,23 @@ public class Database public void createTable(String name, List<Column> columns) throws IOException { + validateIdentifierName(name, _format.MAX_TABLE_NAME_LENGTH, "table"); + if(getTable(name) != null) { throw new IllegalArgumentException( "Cannot create table with name of existing table"); } + if(columns.isEmpty()) { throw new IllegalArgumentException( "Cannot create table with no columns"); } - + if(columns.size() > _format.MAX_COLUMNS_PER_TABLE) { + throw new IllegalArgumentException( + "Cannot create table with more than " + + _format.MAX_COLUMNS_PER_TABLE + " columns"); + } + Set<String> colNames = new HashSet<String>(); // next, validate the column definitions for(Column column : columns) { @@ -945,6 +953,24 @@ public class Database public static boolean isReservedWord(String s) { return RESERVED_WORDS.contains(s.toLowerCase()); } + + /** + * Validates an identifier name. + */ + public static void validateIdentifierName(String name, + int maxLength, + String identifierType) + { + if((name == null) || (name.trim().length() == 0)) { + throw new IllegalArgumentException( + identifierType + " must have non-empty name"); + } + if(name.length() > maxLength) { + throw new IllegalArgumentException( + identifierType + " name is longer than max length of " + maxLength + + ": " + name); + } + } @Override public String toString() { |