summaryrefslogtreecommitdiffstats
path: root/src/java/com/healthmarketscience/jackcess/Database.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/healthmarketscience/jackcess/Database.java')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java28
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() {