db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r377019 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql: MSSqlBuilder.java MSSqlModelReader.java MSSqlPlatform.java
Date Sat, 11 Feb 2006 19:22:53 GMT
Author: tomdz
Date: Sat Feb 11 11:22:51 2006
New Revision: 377019

URL: http://svn.apache.org/viewcvs?rev=377019&view=rev
Log:
Enhanced/fixed Sql Server platform

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java?rev=377019&r1=377018&r2=377019&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlBuilder.java Sat Feb
11 11:22:51 2006
@@ -263,4 +263,20 @@
         print(identifier);
         print("'");
     }
+
+    // TODO: DROP default is done via selecting the name of the constraint for column avalue
of table toundtrip
+    //
+    // SELECT name 
+    // FROM sysobjects so JOIN sysconstraints sc
+    // ON so.id = sc.constid 
+    // WHERE object_name(so.parent_obj) = 'roundtrip' 
+    // AND so.xtype = 'D'
+    // AND sc.colid = 
+    //   (SELECT colid FROM syscolumns 
+    //    WHERE id = object_id('roundtrip') AND 
+    //    name = 'avalue')
+    //
+    // and then using this in
+    //
+    // ALTER TABLE roundtrip DROP CONSTRAINT ...
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java?rev=377019&r1=377018&r2=377019&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java Sat
Feb 11 11:22:51 2006
@@ -75,32 +75,48 @@
         }
     }
 
+
+    /**
+     * {@inheritDoc}
+     */
+	protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
+	{
+        Table table = super.readTable(metaData, values);
+
+        // Sql Server does not return the auto-increment status via the database metadata
+        determineAutoIncrementFromResultSetMetaData(table, table.getColumns());
+        return table;
+	}
+
     /**
      * {@inheritDoc}
      */
 	protected boolean isInternalPrimaryKeyIndex(Table table, Index index)
 	{
-		// Sql Server generates an index "[pk name in uppercase]__[table name]__[hex number]"
-		// TODO: test with multiple pks
-		StringBuffer pkIndexName = new StringBuffer();
-		Column[]     pks         = table.getPrimaryKeyColumns();
+		// Sql Server generates an index "PK__[table name]__[hex number]"
+		StringBuilder pkIndexName = new StringBuilder();
+		Column[]      pks         = table.getPrimaryKeyColumns();
 
 		if (pks.length > 0)
 		{
-			for (int idx = 0; idx < pks.length; idx++)
-			{
-				pkIndexName.append(pks[idx].getName());
-			}
-			pkIndexName.append("__");
+			pkIndexName.append("PK__");
 			pkIndexName.append(table.getName());
 			pkIndexName.append("__");
 
-			return index.getName().toUpperCase().startsWith(pkIndexName.toString().toUpperCase());
-		}
-		else
-		{
-			return false;
+			if (index.getName().toUpperCase().startsWith(pkIndexName.toString().toUpperCase()))
+			{
+				// if its an index for the pk, then its columns have to be the pk columns
+				for (int idx = 0; idx < pks.length; idx++)
+				{
+					if (!pks[idx].getName().equals(index.getColumn(idx).getName()))
+					{
+						return false;
+					}
+				}
+				return true;
+			}
 		}
+		return false;
 	}
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java?rev=377019&r1=377018&r2=377019&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java Sat Feb
11 11:22:51 2006
@@ -78,6 +78,11 @@
         info.addNativeTypeMapping("BOOLEAN",  "BIT",   "BIT");
         info.addNativeTypeMapping("DATALINK", "IMAGE", "LONGVARBINARY");
 
+        info.addDefaultSize(Types.CHAR,       254);
+        info.addDefaultSize(Types.VARCHAR,    254);
+        info.addDefaultSize(Types.BINARY,     254);
+        info.addDefaultSize(Types.VARBINARY,  254);
+
         setSqlBuilder(new MSSqlBuilder(info));
         setModelReader(new MSSqlModelReader(info));
     }



Mime
View raw message