*** misc/hsqldb/src/org/hsqldb/Constraint.java	Tue Apr 11 16:40:53 2006
--- misc/build/hsqldb/src/org/hsqldb/Constraint.java	Mon Aug  7 10:48:26 2006
***************
*** 111,123 ****
      int              constType;
  
      /**
!      *  Constructor declaration for UNIQUE
       */
!     Constraint(HsqlName name, Table t, Index index) {
  
          core           = new ConstraintCore();
          constName      = name;
!         constType      = UNIQUE;
          core.mainTable = t;
          core.mainIndex = index;
          /* fredt - in unique constraints column list for iColMain is the
--- 111,123 ----
      int              constType;
  
      /**
!      *  Constructor declaration for PK and UNIQUE
       */
!     Constraint(HsqlName name, Table t, Index index, int type) {
  
          core           = new ConstraintCore();
          constName      = name;
!         constType      = type;
          core.mainTable = t;
          core.mainIndex = index;
          /* fredt - in unique constraints column list for iColMain is the
***************
*** 179,195 ****
      }
  
      /**
-      * PK constraint constructor
-      */
-     Constraint(HsqlName name, int[] cols) {
- 
-         core              = new ConstraintCore();
-         constName         = name;
-         constType         = PRIMARY_KEY;
-         core.mainColArray = cols;
-     }
- 
-     /**
       * temp constraint constructor
       */
      Constraint(HsqlName name, int[] mainCols, Table refTable, int[] refCols,
--- 179,184 ----
*** misc/hsqldb/src/org/hsqldb/DatabaseCommandInterpreter.java	Mon Jul 17 00:29:34 2006
--- misc/build/hsqldb/src/org/hsqldb/DatabaseCommandInterpreter.java	Mon Aug  7 10:48:26 2006
***************
*** 1238,1245 ****
                  }
  
                  Constraint newconstraint =
!                     new Constraint(primaryConst.constName,
!                                    primaryConst.core.mainColArray);
  
                  t.addConstraint(newconstraint);
                  database.schemaManager.registerConstraintName(
--- 1238,1245 ----
                  }
  
                  Constraint newconstraint =
!                     new Constraint(primaryConst.constName, t, t.getPrimaryIndex(),
!                                    Constraint.PRIMARY_KEY);
  
                  t.addConstraint(newconstraint);
                  database.schemaManager.registerConstraintName(
*** misc/hsqldb/src/org/hsqldb/Index.java	Fri Jul 21 15:37:43 2006
--- misc/build/hsqldb/src/org/hsqldb/Index.java	Mon Aug  7 10:48:26 2006
***************
*** 101,107 ****
      private final HsqlName indexName;
      final boolean[]        colCheck;
      private final int[]    colIndex;
!     private final int[]    colType;
      final int[]            pkCols;
      final int[]            pkTypes;
      private final boolean  isUnique;    // DDL uniqueness
--- 101,107 ----
      private final HsqlName indexName;
      final boolean[]        colCheck;
      private final int[]    colIndex;
!     private final int[]    colTypes;
      final int[]            pkCols;
      final int[]            pkTypes;
      private final boolean  isUnique;    // DDL uniqueness
***************
*** 116,121 ****
--- 116,122 ----
          null);
      IndexRowIterator updatableIterators;
      final boolean    onCommitPreserve;
+     final Table      table;
  
      /**
       * Constructor declaration
***************
*** 131,147 ****
       * @param visColumns count of visible columns
       */
      Index(Database database, HsqlName name, Table table, int[] column,
!             int[] type, boolean isPk, boolean unique, boolean constraint,
              boolean forward, int[] pkcols, int[] pktypes, boolean temp) {
  
!         indexName    = name;
!         colIndex     = column;
!         colType      = type;
!         pkCols       = pkcols;
!         pkTypes      = pktypes;
!         isUnique     = unique;
!         isConstraint = constraint;
!         isForward    = forward;
          useRowId = (!isUnique && pkCols.length == 0)
                     || (colIndex.length == 0);
          colCheck = table.getNewColumnCheckList();
--- 132,149 ----
       * @param visColumns count of visible columns
       */
      Index(Database database, HsqlName name, Table table, int[] column,
!             int[] colTypes, boolean isPk, boolean unique, boolean constraint,
              boolean forward, int[] pkcols, int[] pktypes, boolean temp) {
  
!         this.table     = table;
!         this.indexName = name;
!         this.colIndex  = column;
!         this.colTypes  = colTypes;
!         this.pkCols    = pkcols;
!         this.pkTypes   = pktypes;
!         isUnique       = unique;
!         isConstraint   = constraint;
!         isForward      = forward;
          useRowId = (!isUnique && pkCols.length == 0)
                     || (colIndex.length == 0);
          colCheck = table.getNewColumnCheckList();
***************
*** 203,209 ****
       * Returns the array containing column indexes for index
       */
      int[] getColumnTypes() {
!         return colType;    // todo: this gives back also primary key field(s)!
      }
  
      /**
--- 205,227 ----
       * Returns the array containing column indexes for index
       */
      int[] getColumnTypes() {
!         return colTypes;    // todo: this gives back also primary key field(s)!
!     }
! 
!     String getColumnNameList() {
! 
!         String columnNameList = "";
! 
!         for (int j = 0; j < colIndex.length; ++j) {
!             columnNameList +=
!                 table.getColumn(colIndex[j]).columnName.statementName;
! 
!             if (j < colIndex.length - 1) {
!                 columnNameList += ",";
!             }
!         }
! 
!         return columnNameList;
      }
  
      /**
***************
*** 297,304 ****
              compare = compareRowForInsert(session, row, n.getRow());
  
              if (compare == 0) {
!                 throw Trace.error(Trace.VIOLATION_OF_UNIQUE_INDEX,
!                                   indexName.name);
              }
  
              isleft = compare < 0;
--- 315,334 ----
              compare = compareRowForInsert(session, row, n.getRow());
  
              if (compare == 0) {
!                 int    errorCode = Trace.VIOLATION_OF_UNIQUE_INDEX;
!                 String name      = indexName.statementName;
! 
!                 if (isConstraint) {
!                     Constraint c =
!                         table.getUniqueOrPKConstraintForIndex(this);
! 
!                     name      = c.getName().name;
!                     errorCode = Trace.VIOLATION_OF_UNIQUE_CONSTRAINT;
!                 }
! 
!                 throw Trace.error(errorCode, new Object[] {
!                     name, getColumnNameList()
!                 });
              }
  
              isleft = compare < 0;
***************
*** 848,854 ****
              boolean t =
                  Column.compare(
                      collation, value, x.getData()[colIndex[0]],
!                     colType[0]) >= iTest;
  
              if (t) {
                  Node r = x.getRight();
--- 878,884 ----
              boolean t =
                  Column.compare(
                      collation, value, x.getData()[colIndex[0]],
!                     colTypes[0]) >= iTest;
  
              if (t) {
                  Node r = x.getRight();
***************
*** 879,885 ****
          while (x != null) {
              Object colvalue = x.getData()[colIndex[0]];
              int result = Column.compare(collation, value, colvalue,
!                                         colType[0]);
  
              if (result >= iTest) {
                  x = next(x);
--- 909,915 ----
          while (x != null) {
              Object colvalue = x.getData()[colIndex[0]];
              int result = Column.compare(collation, value, colvalue,
!                                         colTypes[0]);
  
              if (result >= iTest) {
                  x = next(x);
***************
*** 914,920 ****
  
          while (x != null) {
              boolean t = Column.compare(
!                 collation, null, x.getData()[colIndex[0]], colType[0]) >= 0;
  
              if (t) {
                  Node r = x.getRight();
--- 944,950 ----
  
          while (x != null) {
              boolean t = Column.compare(
!                 collation, null, x.getData()[colIndex[0]], colTypes[0]) >= 0;
  
              if (t) {
                  Node r = x.getRight();
***************
*** 1146,1152 ****
                              Object[] b) throws HsqlException {
  
          int i = Column.compare(collation, a[rowColMap[0]], b[colIndex[0]],
!                                colType[0]);
  
          if (i != 0) {
              return i;
--- 1176,1182 ----
                              Object[] b) throws HsqlException {
  
          int i = Column.compare(collation, a[rowColMap[0]], b[colIndex[0]],
!                                colTypes[0]);
  
          if (i != 0) {
              return i;
***************
*** 1156,1162 ****
  
          for (int j = 1; j < fieldcount; j++) {
              i = Column.compare(collation, a[rowColMap[j]], b[colIndex[j]],
!                                colType[j]);
  
              if (i != 0) {
                  return i;
--- 1186,1192 ----
  
          for (int j = 1; j < fieldcount; j++) {
              i = Column.compare(collation, a[rowColMap[j]], b[colIndex[j]],
!                                colTypes[j]);
  
              if (i != 0) {
                  return i;
***************
*** 1214,1220 ****
          for (; j < colIndex.length; j++) {
              Object currentvalue = a[colIndex[j]];
              int i = Column.compare(collation, currentvalue, b[colIndex[j]],
!                                    colType[j]);
  
              if (i != 0) {
                  return i;
--- 1244,1250 ----
          for (; j < colIndex.length; j++) {
              Object currentvalue = a[colIndex[j]];
              int i = Column.compare(collation, currentvalue, b[colIndex[j]],
!                                    colTypes[j]);
  
              if (i != 0) {
                  return i;
*** misc/hsqldb/src/org/hsqldb/Table.java	Wed Jun 28 23:47:11 2006
--- misc/build/hsqldb/src/org/hsqldb/Table.java	Mon Aug  7 10:48:26 2006
***************
*** 488,500 ****
       * @param  index
       * @return
       */
!     Constraint getUniqueConstraintForIndex(Index index) {
  
          for (int i = 0, size = constraintList.length; i < size; i++) {
              Constraint c = constraintList[i];
  
              if (c.getMainIndex() == index
!                     && c.getType() == Constraint.UNIQUE) {
                  return c;
              }
          }
--- 488,501 ----
       * @param  index
       * @return
       */
!     Constraint getUniqueOrPKConstraintForIndex(Index index) {
  
          for (int i = 0, size = constraintList.length; i < size; i++) {
              Constraint c = constraintList[i];
  
              if (c.getMainIndex() == index
!                     && (c.getType() == Constraint.UNIQUE
!                         || c.getType() == Constraint.PRIMARY_KEY)) {
                  return c;
              }
          }
***************
*** 1498,1508 ****
  
          int newindexNo = createIndexStructureGetNo(column, name, unique,
              constraint, forward);
!         Index       newindex     = indexList[newindexNo];
!         Index       primaryindex = getPrimaryIndex();
!         RowIterator it           = primaryindex.firstRow(session);
!         int         rowCount     = 0;
!         int         error        = 0;
  
          try {
              while (it.hasNext()) {
--- 1499,1509 ----
  
          int newindexNo = createIndexStructureGetNo(column, name, unique,
              constraint, forward);
!         Index         newindex     = indexList[newindexNo];
!         Index         primaryindex = getPrimaryIndex();
!         RowIterator   it           = primaryindex.firstRow(session);
!         int           rowCount     = 0;
!         HsqlException error        = null;
  
          try {
              while (it.hasNext()) {
***************
*** 1521,1529 ****
  
              return newindex;
          } catch (java.lang.OutOfMemoryError e) {
!             error = Trace.OUT_OF_MEMORY;
          } catch (HsqlException e) {
!             error = Trace.VIOLATION_OF_UNIQUE_INDEX;
          }
  
          // backtrack on error
--- 1522,1533 ----
  
              return newindex;
          } catch (java.lang.OutOfMemoryError e) {
!             error = Trace.error(Trace.OUT_OF_MEMORY);
          } catch (HsqlException e) {
!             error = Trace.error(Trace.VIOLATION_OF_UNIQUE_INDEX,
!                                 new Object[] {
!                 newindex.getName().statementName, newindex.getColumnNameList()
!             });
          }
  
          // backtrack on error
***************
*** 1547,1553 ****
  
          setBestRowIdentifiers();
  
!         throw Trace.error(error);
      }
  
      /**
--- 1551,1557 ----
  
          setBestRowIdentifiers();
  
!         throw error;
      }
  
      /**
***************
*** 2031,2044 ****
                  indexList[i].insert(null, row, i);
              }
          } catch (HsqlException e) {
-             Index   index        = indexList[i];
-             boolean isconstraint = index.isConstraint;
  
!             if (isconstraint) {
!                 throw Trace.error(Trace.VIOLATION_OF_UNIQUE_CONSTRAINT,
!                                   index.getName().name);
              }
  
              throw e;
          }
      }
--- 2035,2051 ----
                  indexList[i].insert(null, row, i);
              }
          } catch (HsqlException e) {
  
!             // unique index violation - rollback insert
!             for (--i; i >= 0; i--) {
!                 Node n = row.getNode(i);
! 
!                 indexList[i].delete(null, n);
              }
  
+             row.delete();
+             removeRowFromStore(row);
+ 
              throw e;
          }
      }
***************
*** 3294,3301 ****
                  indexList[i].insert(session, row, i);
              }
          } catch (HsqlException e) {
-             Index   index        = indexList[i];
-             boolean isconstraint = index.isConstraint;
  
              // unique index violation - rollback insert
              for (--i; i >= 0; i--) {
--- 3301,3306 ----
***************
*** 3307,3320 ****
              row.delete();
              removeRowFromStore(row);
  
-             if (isconstraint) {
-                 Constraint c    = getUniqueConstraintForIndex(index);
-                 String     name = c == null ? index.getName().name
-                                             : c.getName().name;
- 
-                 throw Trace.error(Trace.VIOLATION_OF_UNIQUE_CONSTRAINT, name);
-             }
- 
              throw e;
          }
      }
--- 3312,3317 ----
*** misc/hsqldb/src/org/hsqldb/TableWorks.java	Tue Apr 11 16:56:40 2006
--- misc/build/hsqldb/src/org/hsqldb/TableWorks.java	Mon Aug  7 10:48:26 2006
***************
*** 224,230 ****
                  table.getSchemaName(), false);
          addOrDropPrimaryKey(cols, false);
  
!         Constraint newconstraint = new Constraint(name, cols);
  
          table.addConstraint(newconstraint);
          table.database.schemaManager.registerConstraintName(name.name,
--- 224,231 ----
                  table.getSchemaName(), false);
          addOrDropPrimaryKey(cols, false);
  
!         Constraint newconstraint = new Constraint(name, table,
!             table.getPrimaryIndex(), Constraint.PRIMARY_KEY);
  
          table.addConstraint(newconstraint);
          table.database.schemaManager.registerConstraintName(name.name,
***************
*** 286,293 ****
          // create an autonamed index
          HsqlName indexname = table.database.nameManager.newAutoName("IDX",
              name.name);
!         Index      index = createIndex(col, indexname, true, true, false);
!         Constraint newconstraint = new Constraint(name, table, index);
  
          table.addConstraint(newconstraint);
          table.database.schemaManager.registerConstraintName(name.name,
--- 287,295 ----
          // create an autonamed index
          HsqlName indexname = table.database.nameManager.newAutoName("IDX",
              name.name);
!         Index index = createIndex(col, indexname, true, true, false);
!         Constraint newconstraint = new Constraint(name, table, index,
!             Constraint.UNIQUE);
  
          table.addConstraint(newconstraint);
          table.database.schemaManager.registerConstraintName(name.name,
***************
*** 488,495 ****
  
          if (column.isPrimaryKey()) {
              HsqlName pkNameAdd = tn.makeSysPKName();
!             Constraint newconstraint = new Constraint(pkNameAdd,
!                 new int[]{ colIndex });
  
              table.addConstraint(newconstraint);
              table.database.schemaManager.registerConstraintName(
--- 490,497 ----
  
          if (column.isPrimaryKey()) {
              HsqlName pkNameAdd = tn.makeSysPKName();
!             Constraint newconstraint = new Constraint(pkNameAdd, table,
!                 table.getPrimaryIndex(), Constraint.PRIMARY_KEY);
  
              table.addConstraint(newconstraint);
              table.database.schemaManager.registerConstraintName(
*** misc/hsqldb/src/org/hsqldb/persist/TextCache.java	Mon Jul 24 13:20:45 2006
--- misc/build/hsqldb/src/org/hsqldb/persist/TextCache.java	Tue Oct 31 09:06:28 2006
***************
*** 479,485 ****
                      wasNormal = true;
                      complete  = wasCR;
                      wasCR     = false;
!                     hasQuote  = !hasQuote;
                      break;
  
                  case CR_CHAR :
--- 479,487 ----
                      wasNormal = true;
                      complete  = wasCR;
                      wasCR     = false;
!                     if (isQuoted) {
!                         hasQuote  = !hasQuote;
!                     }
                      break;
  
                  case CR_CHAR :
*** misc/hsqldb/src/org/hsqldb/resources/sql-error-messages.properties	Thu Jun 15 13:15:06 2006
--- misc/build/hsqldb/src/org/hsqldb/resources/sql-error-messages.properties	Mon Aug  7 10:50:25 2006
***************
*** 10,16 ****
  006=22012 Division by zero
  007=22019 Invalid escape character
  008=23000 Integrity constraint violation
! 009=23000 Violation of unique index
  010=23000 Attempt to insert null into a non-nullable column
  011=37000 Unexpected token
  012=37000 Unexpected end of command
--- 10,16 ----
  006=22012 Division by zero
  007=22019 Invalid escape character
  008=23000 Integrity constraint violation
! 009=23000 Violation of unique index $$: duplicate value(s) for column(s) $$
  010=23000 Attempt to insert null into a non-nullable column
  011=37000 Unexpected token
  012=37000 Unexpected end of command
***************
*** 105,111 ****
  101=\u0020$$ table: $$
  102=duplicate column in list
  103=table has no primary key
! 104=23000 Unique constraint violation
  105=S0021 missing DEFAULT value on column $$
  106=S1000 Not a condition
  107=attempt to connect while db opening /closing
--- 105,111 ----
  101=\u0020$$ table: $$
  102=duplicate column in list
  103=table has no primary key
! 104=23000 Violation of unique constraint $$: duplicate value(s) for column(s) $$
  105=S0021 missing DEFAULT value on column $$
  106=S1000 Not a condition
  107=attempt to connect while db opening /closing
*** misc/hsqldb/build/build.xml Sun Oct 23 18:54:00 2005
--- misc/build/hsqldb/build/build.xml   Tue May 30 16:22:33 2006
***************
*** 16,28 ****
     <property file='build/build.properties'/>
     <property name="hsqldb.version" value="1.8.0"/>
  
!    <tstamp>
!        <format property="_tmpstamp" pattern="yyyy/MM/dd-hh:mm:ss"
!                locale="en"/>
!    </tstamp>
! 
!    <property name="build.label" value="private-${_tmpstamp}"/>
!    <property name="build.vendor" value="${user.name}"/>
     <property name="hsqldb.title" value="HSQLDB"/>
     <property name="hsqldb.vendor" value="The HSQLDB Development Group"/>
     <property name="src" value="${basedir}/src"/>
--- 16,23 ----
     <property file='build/build.properties'/>
     <property name="hsqldb.version" value="1.8.0"/>
  
!    <property name="build.label" value="replace-me"/>
!    <property name="build.vendor" value="OpenOffice.org"/>
     <property name="hsqldb.title" value="HSQLDB"/>
     <property name="hsqldb.vendor" value="The HSQLDB Development Group"/>
     <property name="src" value="${basedir}/src"/>
