*** misc/hsqldb/src/org/hsqldb/Collation.java	Thu Mar 24 14:14:06 2005
--- misc/build/hsqldb/src/org/hsqldb/Collation.java	Thu Mar 24 14:36:55 2005
***************
*** 1 ****
! dummy
--- 1,197 ----
! /* Copyright (c) 2001-2005, The HSQL Development Group
!  * All rights reserved.
!  *
!  * Redistribution and use in source and binary forms, with or without
!  * modification, are permitted provided that the following conditions are met:
!  *
!  * Redistributions of source code must retain the above copyright notice, this
!  * list of conditions and the following disclaimer.
!  *
!  * Redistributions in binary form must reproduce the above copyright notice,
!  * this list of conditions and the following disclaimer in the documentation
!  * and/or other materials provided with the distribution.
!  *
!  * Neither the name of the HSQL Development Group nor the names of its
!  * contributors may be used to endorse or promote products derived from this
!  * software without specific prior written permission.
!  *
!  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
!  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
!  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
!  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
!  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
!  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
!  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
!  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
!  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
!  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!  */
! 
! 
! package org.hsqldb;
! 
! import org.hsqldb.lib.*;
! 
! import java.util.Locale;
! import java.text.Collator;
! 
! public class Collation {
! 
!     static final HashMap nameToJavaName = new HashMap(101);
! 
!     static {
!         nameToJavaName.put("Afrikaans", "af-ZA");
!         nameToJavaName.put("Amharic", "am-ET");
!         nameToJavaName.put("Arabic", "ar");
!         nameToJavaName.put("Assamese", "as-IN");
!         nameToJavaName.put("Azerbaijani_Latin", "az-AZ");
!         nameToJavaName.put("Azerbaijani_Cyrillic", "az-cyrillic");
!         nameToJavaName.put("Belarusian", "be-BY");
!         nameToJavaName.put("Bulgarian", "bg-BG");
!         nameToJavaName.put("Bengali", "bn-IN");
!         nameToJavaName.put("Tibetan", "bo-CN");
!         nameToJavaName.put("Bosnian", "bs-BA");
!         nameToJavaName.put("Catalan", "ca-ES");
!         nameToJavaName.put("Czech", "cs-CZ");
!         nameToJavaName.put("Welsh", "cy-GB");
!         nameToJavaName.put("Danish", "da-DK");
!         nameToJavaName.put("German", "de-DE");
!         nameToJavaName.put("Greek", "el-GR");
!         nameToJavaName.put("Latin1_General", "en-US");
!         nameToJavaName.put("Spanish", "es-ES");
!         nameToJavaName.put("Estonian", "et-EE");
!         nameToJavaName.put("Basque", "eu");
!         nameToJavaName.put("Finnish", "fi-FI");
!         nameToJavaName.put("French", "fr-FR");
!         nameToJavaName.put("Guarani", "gn-PY");
!         nameToJavaName.put("Gujarati", "gu-IN");
!         nameToJavaName.put("Hausa", "ha-NG");
!         nameToJavaName.put("Hebrew", "he-IL");
!         nameToJavaName.put("Hindi", "hi-IN");
!         nameToJavaName.put("Croatian", "hr-HR");
!         nameToJavaName.put("Hungarian", "hu-HU");
!         nameToJavaName.put("Armenian", "hy-AM");
!         nameToJavaName.put("Indonesian", "id-ID");
!         nameToJavaName.put("Igbo", "ig-NG");
!         nameToJavaName.put("Icelandic", "is-IS");
!         nameToJavaName.put("Italian", "it-IT");
!         nameToJavaName.put("Inuktitut", "iu-CA");
!         nameToJavaName.put("Japanese", "ja-JP");
!         nameToJavaName.put("Georgian", "ka-GE");
!         nameToJavaName.put("Kazakh", "kk-KZ");
!         nameToJavaName.put("Khmer", "km-KH");
!         nameToJavaName.put("Kannada", "kn-IN");
!         nameToJavaName.put("Korean", "ko-KR");
!         nameToJavaName.put("Konkani", "kok-IN");
!         nameToJavaName.put("Kashmiri", "ks");
!         nameToJavaName.put("Kirghiz", "ky-KG");
!         nameToJavaName.put("Lao", "lo-LA");
!         nameToJavaName.put("Lithuanian", "lt-LT");
!         nameToJavaName.put("Latvian", "lv-LV");
!         nameToJavaName.put("Maori", "mi-NZ");
!         nameToJavaName.put("Macedonian", "mk-MK");
!         nameToJavaName.put("Malayalam", "ml-IN");
!         nameToJavaName.put("Mongolian", "mn-MN");
!         nameToJavaName.put("Manipuri", "mni-IN");
!         nameToJavaName.put("Marathi", "mr-IN");
!         nameToJavaName.put("Malay", "ms-MY");
!         nameToJavaName.put("Maltese", "mt-MT");
!         nameToJavaName.put("Burmese", "my-MM");
!         nameToJavaName.put("Danish_Norwegian", "nb-NO");
!         nameToJavaName.put("Nepali", "ne-NP");
!         nameToJavaName.put("Dutch", "nl-NL");
!         nameToJavaName.put("Norwegian", "nn-NO");
!         nameToJavaName.put("Oriya", "or-IN");
!         nameToJavaName.put("Punjabi", "pa-IN");
!         nameToJavaName.put("Polish", "pl-PL");
!         nameToJavaName.put("Pashto", "ps-AF");
!         nameToJavaName.put("Portuguese", "pt-PT");
!         nameToJavaName.put("Romanian", "ro-RO");
!         nameToJavaName.put("Russian", "ru-RU");
!         nameToJavaName.put("Sanskrit", "sa-IN");
!         nameToJavaName.put("Sindhi", "sd-IN");
!         nameToJavaName.put("Slovak", "sk-SK");
!         nameToJavaName.put("Slovenian", "sl-SI");
!         nameToJavaName.put("Somali", "so-SO");
!         nameToJavaName.put("Albanian", "sq-AL");
!         nameToJavaName.put("Serbian_Cyrillic", "sr-YU");
!         nameToJavaName.put("Serbian_Latin", "sh-BA");
!         nameToJavaName.put("Swedish", "sv-SE");
!         nameToJavaName.put("Swahili", "sw-KE");
!         nameToJavaName.put("Tamil", "ta-IN");
!         nameToJavaName.put("Telugu", "te-IN");
!         nameToJavaName.put("Tajik", "tg-TJ");
!         nameToJavaName.put("Thai", "th-TH");
!         nameToJavaName.put("Turkmen", "tk-TM");
!         nameToJavaName.put("Tswana", "tn-BW");
!         nameToJavaName.put("Turkish", "tr-TR");
!         nameToJavaName.put("Tatar", "tt-RU");
!         nameToJavaName.put("Ukrainian", "uk-UA");
!         nameToJavaName.put("Urdu", "ur-PK");
!         nameToJavaName.put("Uzbek_Latin", "uz-UZ");
!         nameToJavaName.put("Venda", "ven-ZA");
!         nameToJavaName.put("Vietnamese", "vi-VN");
!         nameToJavaName.put("Yoruba", "yo-NG");
!         nameToJavaName.put("Chinese", "zh-CN");
!         nameToJavaName.put("Zulu", "zu-ZA");
!     }
! 
!     String   name;
!     Collator collator;
! 
!     public org.hsqldb.lib.Iterator getCollationsIterator() {
!         return nameToJavaName.keySet().iterator();
!     }
! 
!     public org.hsqldb.lib.Iterator getLocalesIterator() {
!         return nameToJavaName.values().iterator();
!     }
! 
!     public void setCollationAsLocale() {
! 
!         Locale locale   = Locale.getDefault();
!         String language = locale.getDisplayLanguage(Locale.ENGLISH);
! 
!         try {
!             setCollation(language);
!         } catch (HsqlException e) {}
!     }
! 
!     void setCollation(String name) throws HsqlException {
! 
!         String jname = (String) Collation.nameToJavaName.get(name);
! 
!         if (jname == null) {
!             throw Trace.error(Trace.INVALID_COLLATION_NAME_NO_SUBCLASS);
!         }
! 
!         this.name = name;
! 
!         String[] parts    = StringUtil.split(jname, "-");
!         String   language = parts[0];
!         String   country  = parts.length == 2 ? parts[1]
!                                               : "";
!         Locale   l        = new Locale(language, country);
! 
!         collator = Collator.getInstance(l);
!     }
! 
!     /**
!      * returns -1, 0 or +1
!      */
!     int compare(String a, String b) {
! 
!         int i;
! 
!         if (collator == null) {
!             i = a.compareTo(b);
!         } else {
!             i = collator.compare(a, b);
!         }
! 
!         return (i == 0) ? 0
!                         : (i < 0 ? -1
!                                  : 1);
!     }
! }
*** misc/hsqldb/src/org/hsqldb/Column.java	Wed Mar  2 14:50:45 2005
--- misc/build/hsqldb/src/org/hsqldb/Column.java	Thu Mar 24 14:18:00 2005
***************
*** 90,100 ****
  // java.lang.Number values and new functions to choose type for promotion
  // fredt@users 20020401 - patch 455757 by galena@users (Michiel de Roo)
  // interpretation of TINYINT as Byte instead of Short
- // fredt@users 20020130 - patch 505356 by daniel_fiser@users
- // use of the current locale for string comparison (instead of posix)
- // turned off by default but can be applied accross the database by defining
- // sql.compare_in_locale=true in database.properties file
- // changes marked separately
  // fredt@users 20020130 - patch 491987 by jimbag@users
  // support for sql standard char and varchar. size is maintained as
  // defined in the DDL and trimming and padding takes place accordingly
--- 90,95 ----
***************
*** 203,208 ****
--- 198,211 ----
          return newCol;
      }
  
+     void setType(Column other) {
+ 
+         isNullable = other.isNullable;
+         colType    = other.colType;
+         colSize    = other.colSize;
+         colScale   = other.colScale;
+     }
+ 
      /**
       *  Is this the identity column in the table.
       *
***************
*** 627,639 ****
          }
      }
  
! // fredt@users 20020130 - patch 505356 by daniel_fiser@users
! // modified for performance and made optional
!     static boolean sql_compare_in_locale = false;
! 
!     public static void setCompareInLocal(boolean value) {
!         sql_compare_in_locale = value;
!     }
  
      /**
       *  Compare a with b and return int value as result.
--- 630,647 ----
          }
      }
  
! // boucherb@users 2003-09-25
! // TODO:  Maybe use //#ifdef tag or reflective static method attribute
! // instantiation to take advantage of String.compareToIgnoreCase when
! // available (JDK 1.2 and greater) during ANT build. That or perhaps
! // consider using either local character-wise comparison or first converting
! // to lower case and then to upper case. Sun states that the JDK 1.2 introduced
! // String.compareToIngnorCase() comparison involves calling
! // Character.toLowerCase(Character.toUpperCase()) on compared characters,
! // to correctly handle some caveats concering using only the one operation or
! // the other outside the ascii character range.
! // fredt@users 20020130 - patch 418022 by deforest@users
! // use of rtrim() to mimic SQL92 behaviour
  
      /**
       *  Compare a with b and return int value as result.
***************
*** 644,650 ****
       * @return result 1 if a>b, 0 if a=b, -1 if b>a
       * @throws  HsqlException
       */
!     static int compare(Object a, Object b, int type) throws HsqlException {
  
          int i = 0;
  
--- 652,659 ----
       * @return result 1 if a>b, 0 if a=b, -1 if b>a
       * @throws  HsqlException
       */
!     static int compare(Session session, Object a, Object b,
!                        int type) throws HsqlException {
  
          int i = 0;
  
***************
*** 670,713 ****
  
              case Types.VARCHAR :
              case Types.LONGVARCHAR :
!                 if (sql_compare_in_locale) {
!                     i = JavaSystem.CompareInLocale((String) a, (String) b);
!                 } else {
!                     i = ((String) a).compareTo((String) b);
!                 }
!                 break;
  
- // fredt@users 20020130 - patch 418022 by deforest@users
- // use of rtrim() to mimic SQL92 behaviour
              case Types.CHAR :
!                 if (sql_compare_in_locale) {
!                     i = JavaSystem.CompareInLocale(Library.rtrim((String) a),
!                                                    Library.rtrim((String) b));
!                 } else {
!                     i = (Library.rtrim((String) a)).compareTo(
!                         Library.rtrim((String) b));
!                 }
!                 break;
  
- // boucherb@users 2003-09-25
- // TODO:  Maybe use //#ifdef tag or reflective static method attribute
- // instantiation to take advantage of String.compareToIgnoreCase when
- // available (JDK 1.2 and greater) during ANT build. That or perhaps
- // consider using either local character-wise comparison or first converting
- // to lower case and then to upper case. Sun states that the JDK 1.2 introduced
- // String.compareToIngnorCase() comparison involves calling
- // Character.toLowerCase(Character.toUpperCase()) on compared characters,
- // to correctly handle some caveats concering using only the one operation or
- // the other outside the ascii character range.
              case Types.VARCHAR_IGNORECASE :
!                 if (sql_compare_in_locale) {
!                     i = JavaSystem.CompareInLocale(
!                         ((String) a).toUpperCase(),
!                         ((String) b).toUpperCase());
!                 } else {
!                     i = JavaSystem.CompareIngnoreCase((String) a, (String) b);
!                 }
!                 break;
  
              case Types.TINYINT :
              case Types.SMALLINT :
--- 679,694 ----
  
              case Types.VARCHAR :
              case Types.LONGVARCHAR :
!                 return session.database.collation.compare((String) a,
!                         (String) b);
  
              case Types.CHAR :
!                 return session.database.collation.compare(
!                     Library.rtrim((String) a), Library.rtrim((String) b));
  
              case Types.VARCHAR_IGNORECASE :
!                 return session.database.collation.compare(
!                     ((String) a).toUpperCase(), ((String) b).toUpperCase());
  
              case Types.TINYINT :
              case Types.SMALLINT :
***************
*** 1072,1083 ****
                          return o;
                      }
  
!                     if (o instanceof java.sql.Time) {
                          return HsqlDateTime.getTimeString((java.sql.Time) o,
                                                            null);
                      }
  
!                     if (o instanceof java.sql.Timestamp) {
                          return HsqlDateTime.getTimestampString(
                              (java.sql.Timestamp) o, null);
                      }
--- 1053,1064 ----
                          return o;
                      }
  
!                     if (o instanceof Time) {
                          return HsqlDateTime.getTimeString((java.sql.Time) o,
                                                            null);
                      }
  
!                     if (o instanceof Timestamp) {
                          return HsqlDateTime.getTimestampString(
                              (java.sql.Timestamp) o, null);
                      }
***************
*** 1093,1103 ****
                      break;
  
                  case Types.TIME :
!                     if (o instanceof java.sql.Time) {
                          return HsqlDateTime.getNormalisedTime((Time) o);
                      }
  
!                     if (o instanceof java.sql.Timestamp) {
                          return HsqlDateTime.getNormalisedTime((Timestamp) o);
                      }
  
--- 1074,1084 ----
                      break;
  
                  case Types.TIME :
!                     if (o instanceof Time) {
                          return HsqlDateTime.getNormalisedTime((Time) o);
                      }
  
!                     if (o instanceof Timestamp) {
                          return HsqlDateTime.getNormalisedTime((Timestamp) o);
                      }
  
***************
*** 1112,1122 ****
                      break;
  
                  case Types.TIMESTAMP :
!                     if (o instanceof java.sql.Timestamp) {
                          return o;
                      }
  
!                     if (o instanceof java.sql.Time) {
                          return HsqlDateTime.getNormalisedTimestamp((Time) o);
                      }
  
--- 1093,1103 ----
                      break;
  
                  case Types.TIMESTAMP :
!                     if (o instanceof Timestamp) {
                          return o;
                      }
  
!                     if (o instanceof Time) {
                          return HsqlDateTime.getNormalisedTimestamp((Time) o);
                      }
  
***************
*** 1136,1142 ****
                              (java.sql.Date) o);
                      }
  
!                     if (o instanceof java.sql.Timestamp) {
                          return HsqlDateTime.getNormalisedDate((Timestamp) o);
                      }
  
--- 1117,1123 ----
                              (java.sql.Date) o);
                      }
  
!                     if (o instanceof Timestamp) {
                          return HsqlDateTime.getNormalisedDate((Timestamp) o);
                      }
  
***************
*** 1144,1150 ****
                          return HsqlDateTime.dateValue((String) o);
                      }
  
!                     if (o instanceof java.sql.Time) {
                          throw Trace.error(Trace.INVALID_CONVERSION,
                                            Types.getTypeString(type));
                      }
--- 1125,1131 ----
                          return HsqlDateTime.dateValue((String) o);
                      }
  
!                     if (o instanceof Time) {
                          throw Trace.error(Trace.INVALID_CONVERSION,
                                            Types.getTypeString(type));
                      }
***************
*** 1425,1431 ****
  
              case Types.NUMERIC :
              case Types.DECIMAL :
!                 if (!(o instanceof Number)) {
                      o = convertObject(o, type);
                  }
  
--- 1406,1412 ----
  
              case Types.NUMERIC :
              case Types.DECIMAL :
!                 if (!(o instanceof BigDecimal)) {
                      o = convertObject(o, type);
                  }
  
***************
*** 1692,1698 ****
       * @param  type java.sql.Types int for a numeric type
       * @return relative width
       */
!     private static int getNumTypeWidth(int type) {
  
          switch (type) {
  
--- 1673,1679 ----
       * @param  type java.sql.Types int for a numeric type
       * @return relative width
       */
!     static int getNumTypeWidth(int type) {
  
          switch (type) {
  
*** misc/hsqldb/src/org/hsqldb/CompiledStatement.java	Wed Mar  2 14:50:45 2005
--- misc/build/hsqldb/src/org/hsqldb/CompiledStatement.java	Thu Mar 24 14:18:00 2005
***************
*** 383,392 ****
                                                                   : 0);
  
              if (sq.isInPredicate) {
!                 r.removeDuplicates(1);
              }
  
!             t.insert(r);
  
              sq.isMaterialised = true;
          }
--- 383,392 ----
                                                                   : 0);
  
              if (sq.isInPredicate) {
!                 r.removeDuplicates(session, 1);
              }
  
!             t.insertResult(session, r);
  
              sq.isMaterialised = true;
          }
*** misc/hsqldb/src/org/hsqldb/Constraint.java	Wed Mar  2 14:50:45 2005
--- misc/build/hsqldb/src/org/hsqldb/Constraint.java	Thu Mar 24 14:18:00 2005
***************
*** 344,349 ****
--- 344,360 ----
          return false;
      }
  
+     boolean hasColumn(int colIndex) {
+ 
+         if (constType == MAIN) {
+             return ArrayUtil.find(core.mainColArray, colIndex) != -1;
+         } else if (constType == FOREIGN_KEY) {
+             return ArrayUtil.find(core.mainColArray, colIndex) != -1;
+         }
+ 
+         return false;
+     }
+ 
  // fredt@users 20020225 - patch 1.7.0 by fredt - duplicate constraints
  
      /**
***************
*** 520,547 ****
              return core.refIndex.emptyIterator();
          }
  
- /*
-         // there must be no record in the 'slave' table
-         // sebastian@scienion -- dependent on forDelete | forUpdate
-         boolean noaction = forDelete ? core.deleteAction == NO_ACTION
-                                      : core.updateAction == NO_ACTION;
- 
-         if (noaction) {
-             if (core.refIndex.exists(row, core.mainColArray)) {
-                 throw Trace.error(Trace.INTEGRITY_CONSTRAINT_VIOLATION,
-                                   Trace.Constraint_violation, new Object[] {
-                     core.fkName.name, core.refTable.getName().name
-                 });
-             } else {
-                 return core.refIndex.emptyIterator();
-             }
-         } else {
-             return delete
-                    ? core.refIndex.findFirstRowForDelete(row,
-                        core.mainColArray)
-                    : core.refIndex.findFirstRow(row, core.mainColArray);
-         }
- */
          return delete
                 ? core.refIndex.findFirstRowForDelete(session, row,
                     core.mainColArray)
--- 531,536 ----
***************
*** 582,596 ****
       * table. Also returns true if any column covered by the foreign key
       * constraint has a null value.
       */
!     private static boolean hasReferencedRow(Object[] rowdata,
!             int[] rowColArray, Index mainIndex) throws HsqlException {
  
          if (Index.isNull(rowdata, rowColArray)) {
              return true;
          }
  
          // else a record must exist in the main index
!         return mainIndex.exists(null, rowdata, rowColArray);
      }
  
      /**
--- 571,586 ----
       * table. Also returns true if any column covered by the foreign key
       * constraint has a null value.
       */
!     private static boolean hasReferencedRow(Session session,
!             Object[] rowdata, int[] rowColArray,
!             Index mainIndex) throws HsqlException {
  
          if (Index.isNull(rowdata, rowColArray)) {
              return true;
          }
  
          // else a record must exist in the main index
!         return mainIndex.exists(session, rowdata, rowColArray);
      }
  
      /**
***************
*** 598,607 ****
       * checks all rows of a table to ensure they all have a corresponding
       * row in the main table.
       */
!     static void checkReferencedRows(Table table, int[] rowColArray,
                                      Index mainIndex) throws HsqlException {
  
!         RowIterator it = table.rowIterator(null);
  
          while (true) {
              Row row = it.next();
--- 588,598 ----
       * checks all rows of a table to ensure they all have a corresponding
       * row in the main table.
       */
!     static void checkReferencedRows(Session session, Table table,
!                                     int[] rowColArray,
                                      Index mainIndex) throws HsqlException {
  
!         RowIterator it = table.rowIterator(session);
  
          while (true) {
              Row row = it.next();
***************
*** 612,618 ****
  
              Object[] rowdata = row.getData();
  
!             if (!Constraint.hasReferencedRow(rowdata, rowColArray,
                                               mainIndex)) {
                  String colvalues = "";
  
--- 603,609 ----
  
              Object[] rowdata = row.getData();
  
!             if (!Constraint.hasReferencedRow(session, rowdata, rowColArray,
                                               mainIndex)) {
                  String colvalues = "";
  
*** misc/hsqldb/src/org/hsqldb/Database.java	Wed Mar  2 14:50:45 2005
--- misc/build/hsqldb/src/org/hsqldb/Database.java	Thu Mar 24 14:18:00 2005
***************
*** 74,79 ****
--- 74,80 ----
  import org.hsqldb.lib.FileUtil;
  import org.hsqldb.lib.HashMap;
  import org.hsqldb.lib.HsqlArrayList;
+ import org.hsqldb.lib.StringUtil;
  import org.hsqldb.persist.HsqlDatabaseProperties;
  import org.hsqldb.persist.HsqlProperties;
  import org.hsqldb.persist.Logger;
***************
*** 152,157 ****
--- 153,159 ----
      private HashMap                hAlias;
      private boolean                bIgnoreCase;
      private boolean                bReferentialIntegrity;
+     public TxManager               txManager;
      public SessionManager          sessionManager;
      private HsqlDatabaseProperties databaseProperties;
      HsqlNameManager                nameManager;
***************
*** 160,165 ****
--- 162,168 ----
      DatabaseObjectNames            constraintNameList;
      public SequenceManager         sequenceManager;
      CompiledStatementManager       compiledStatementManager;
+     public Collation               collation;
  
      //
      public static final int DATABASE_ONLINE       = 1;
***************
*** 288,293 ****
--- 291,298 ----
              bReferentialIntegrity = true;
              sysUser               = userManager.createSysUser();
              sessionManager        = new SessionManager(this, sysUser);
+             txManager             = new TxManager();
+             collation             = new Collation();
              dInfo = DatabaseInformation.newDatabaseInformation(this);
  
              if (sType != DatabaseManager.S_MEM) {
*** misc/hsqldb/src/org/hsqldb/DatabaseCommandInterpreter.java	Wed Mar  2 14:50:46 2005
--- misc/build/hsqldb/src/org/hsqldb/DatabaseCommandInterpreter.java	Thu Mar 24 14:18:00 2005
***************
*** 752,787 ****
  // --
      }
  
      /**
       *  Responsible for handling the creation of table columns during the
       *  process of executing CREATE TABLE DDL statements.
       *
!      *  @param  t target table
       *  @return a Column object with indicated attributes
       *  @throws  HsqlException
       */
!     private Column processCreateColumn(Table t) throws HsqlException {
  
          boolean    isIdentity        = false;
          long       identityStart     = database.firstIdentity;
          long       identityIncrement = 1;
          boolean    isPrimaryKey      = false;
-         String     columnName;
-         boolean    isQuoted;
          String     typeName;
          int        type;
          int        length      = 0;
          int        scale       = 0;
          boolean    isNullable  = true;
          Expression defaultExpr = null;
!         String     token       = tokenizer.getString();
! 
!         columnName = token;
! 
!         Trace.check(!columnName.equals(Table.DEFAULT_PK),
!                     Trace.COLUMN_ALREADY_EXISTS, columnName);
  
-         isQuoted = tokenizer.wasQuotedIdentifier();
          typeName = tokenizer.getString();
          type     = Types.getTypeNr(typeName);
  
--- 752,791 ----
  // --
      }
  
+     private Column processCreateColumn() throws HsqlException {
+ 
+         String  token      = tokenizer.getString();
+         String  columnName = token;
+         boolean isQuoted   = tokenizer.wasQuotedIdentifier();
+         HsqlName hsqlName = database.nameManager.newHsqlName(columnName,
+             isQuoted);
+ 
+         return processCreateColumn(hsqlName);
+     }
+ 
      /**
       *  Responsible for handling the creation of table columns during the
       *  process of executing CREATE TABLE DDL statements.
       *
!      *  @param  hsqlName name of the column
       *  @return a Column object with indicated attributes
       *  @throws  HsqlException
       */
!     private Column processCreateColumn(HsqlName hsqlName)
!     throws HsqlException {
  
          boolean    isIdentity        = false;
          long       identityStart     = database.firstIdentity;
          long       identityIncrement = 1;
          boolean    isPrimaryKey      = false;
          String     typeName;
          int        type;
          int        length      = 0;
          int        scale       = 0;
          boolean    isNullable  = true;
          Expression defaultExpr = null;
!         String     token;
  
          typeName = tokenizer.getString();
          type     = Types.getTypeNr(typeName);
  
***************
*** 820,825 ****
--- 824,833 ----
              tokenizer.getThis(Token.T_CLOSEBRACKET);
          }
  
+         if (type == Types.FLOAT && length > 53) {
+             throw Trace.error(Trace.NUMERIC_VALUE_OUT_OF_RANGE);
+         }
+ 
          token = tokenizer.getString();
  
          if (token.equals(Token.T_DEFAULT)) {
***************
*** 891,900 ****
              throw Trace.error(Trace.UNEXPECTED_TOKEN, Token.T_DEFAULT);
          }
  
!         return new Column(
!             database.nameManager.newHsqlName(columnName, isQuoted),
!             isNullable, type, length, scale, isIdentity, identityStart,
!             identityIncrement, isPrimaryKey, defaultExpr);
      }
  
      /**
--- 899,907 ----
              throw Trace.error(Trace.UNEXPECTED_TOKEN, Token.T_DEFAULT);
          }
  
!         return new Column(hsqlName, isNullable, type, length, scale,
!                           isIdentity, identityStart, identityIncrement,
!                           isPrimaryKey, defaultExpr);
      }
  
      /**
***************
*** 1179,1185 ****
                  break;
              }
  
!             Column newcolumn = processCreateColumn(t);
  
              t.addColumn(newcolumn);
  
--- 1186,1192 ----
                  break;
              }
  
!             Column newcolumn = processCreateColumn();
  
              t.addColumn(newcolumn);
  
***************
*** 1212,1226 ****
  
              Constraint primaryConst = (Constraint) tempConstraints.get(0);
  
!             if (primaryConst.constName != null) {
!                 database.indexNameList.addName(primaryConst.constName.name,
!                                                t.getName(),
!                                                Trace.INDEX_ALREADY_EXISTS);
!                 database.constraintNameList.addName(
!                     primaryConst.constName.name, t.getName(),
!                     Trace.CONSTRAINT_ALREADY_EXISTS);
              }
  
              t.createPrimaryKey(primaryConst.constName,
                                 primaryConst.core.mainColArray, true);
  
--- 1219,1234 ----
  
              Constraint primaryConst = (Constraint) tempConstraints.get(0);
  
!             if (primaryConst.constName == null) {
!                 primaryConst.constName = t.makeSysPKName();
              }
  
+             database.indexNameList.addName(primaryConst.constName.name,
+                                            t.getName(),
+                                            Trace.INDEX_ALREADY_EXISTS);
+             database.constraintNameList.addName(
+                 primaryConst.constName.name, t.getName(),
+                 Trace.CONSTRAINT_ALREADY_EXISTS);
              t.createPrimaryKey(primaryConst.constName,
                                 primaryConst.core.mainColArray, true);
  
***************
*** 1699,1709 ****
                  return;
              }
              default : {
!                 throw Trace.error(Trace.UNEXPECTED_TOKEN, token);
              }
          }
      }
  
      /**
       * Responsible for handling tail of ALTER COLUMN ... RENAME ...
       * @param t table
--- 1707,1727 ----
                  return;
              }
              default : {
!                 tokenizer.back();
!                 processAlterColumnType(t, column);
              }
          }
      }
  
+     private void processAlterColumnType(Table table,
+                                         Column oldCol) throws HsqlException {
+ 
+         Column     newCol = processCreateColumn(oldCol.columnName);
+         TableWorks tw     = new TableWorks(session, table);
+ 
+         tw.reTypeColumn(oldCol, newCol);
+     }
+ 
      /**
       * Responsible for handling tail of ALTER COLUMN ... RENAME ...
       * @param t table
***************
*** 2115,2120 ****
--- 2133,2153 ----
  
                  break;
              }
+             case Token.DATABASE : {
+                 session.checkAdmin();
+                 session.checkDDLWrite();
+                 tokenizer.getThis(Token.T_COLLATION);
+ 
+                 String cname = tokenizer.getIdentifier();
+ 
+                 if (!tokenizer.wasQuotedIdentifier()) {
+                     throw Trace.error(Trace.INVALID_IDENTIFIER);
+                 }
+ 
+                 database.collation.setCollation(cname);
+ 
+                 break;
+             }
              default : {
                  throw Trace.error(Trace.UNEXPECTED_TOKEN, token);
              }
***************
*** 2534,2540 ****
  
          String token;
          int    colindex = t.getColumnCount();
!         Column column   = processCreateColumn(t);
  
          checkAddColumn(t, column);
  
--- 2567,2573 ----
  
          String token;
          int    colindex = t.getColumnCount();
!         Column column   = processCreateColumn();
  
          checkAddColumn(t, column);
  
***************
*** 2551,2557 ****
  
          TableWorks tableWorks = new TableWorks(session, t);
  
!         tableWorks.addOrDropColumn(column, colindex, 1);
  
          return;
      }
--- 2584,2590 ----
  
          TableWorks tableWorks = new TableWorks(session, t);
  
!         tableWorks.addDropRetypeColumn(column, colindex, 1);
  
          return;
      }
***************
*** 2578,2584 ****
  
          TableWorks tableWorks = new TableWorks(session, t);
  
!         tableWorks.addOrDropColumn(null, colindex, -1);
      }
  
      /**
--- 2611,2617 ----
  
          TableWorks tableWorks = new TableWorks(session, t);
  
!         tableWorks.addDropRetypeColumn(null, colindex, -1);
      }
  
      /**
*** misc/hsqldb/src/org/hsqldb/DatabaseInformationFull.java	Wed Mar  2 14:50:46 2005
--- misc/build/hsqldb/src/org/hsqldb/DatabaseInformationFull.java	Thu Mar 24 14:18:00 2005
***************
*** 289,295 ****
              row[ialias_schem]        = schem;
              row[ialias]              = alias;
  
!             t.insert(row);
          }
  
          // must have create/alter table rights to see domain aliases
--- 289,295 ----
              row[ialias_schem]        = schem;
              row[ialias]              = alias;
  
!             t.insertSys(row);
          }
  
          // must have create/alter table rights to see domain aliases
***************
*** 320,326 ****
                  row[ialias_schem]        = schem;
                  row[ialias]              = alias;
  
!                 t.insert(row);
              }
          }
  
--- 320,326 ----
                  row[ialias_schem]        = schem;
                  row[ialias]              = alias;
  
!                 t.insertSys(row);
              }
          }
  
***************
*** 451,457 ****
              row[ifree_count] = ValuePool.getInt(cache.getFreeBlockCount());
              row[ifree_pos]   = ValuePool.getLong(cache.getFileFreePos());
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 451,457 ----
              row[ifree_count] = ValuePool.getInt(cache.getFreeBlockCount());
              row[ifree_pos]   = ValuePool.getLong(cache.getFileFreePos());
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 573,579 ****
                  row[iprivilege] = privilege;
                  row[iis_grntbl] = isGrantable;
  
!                 t.insert(row);
              }
  
              classNames = ns.iterateAccessibleTriggerClassNames(granteeUser);
--- 573,579 ----
                  row[iprivilege] = privilege;
                  row[iis_grntbl] = isGrantable;
  
!                 t.insertSys(row);
              }
  
              classNames = ns.iterateAccessibleTriggerClassNames(granteeUser);
***************
*** 596,602 ****
                  row[iprivilege] = privilege;
                  row[iis_grntbl] = isGrantable;
  
!                 t.insert(row);
              }
          }
  
--- 596,602 ----
                  row[iprivilege] = privilege;
                  row[iis_grntbl] = isGrantable;
  
!                 t.insertSys(row);
              }
          }
  
***************
*** 656,708 ****
          row[0] = "SESSION_ID";
          row[1] = String.valueOf(session.getId());
  
!         t.insert(row);
  
          row    = t.getEmptyRowData();
          row[0] = "AUTOCOMMIT";
          row[1] = session.isAutoCommit() ? "TRUE"
                                          : "FALSE";
  
!         t.insert(row);
  
          row    = t.getEmptyRowData();
          row[0] = "USER";
          row[1] = session.getUsername();
  
!         t.insert(row);
  
          row    = t.getEmptyRowData();
          row[0] = "SESSION_READONLY";
          row[1] = session.isReadOnly() ? "TRUE"
                                        : "FALSE";
  
!         t.insert(row);
  
          row    = t.getEmptyRowData();
          row[0] = "DATABASE_READONLY";
          row[1] = database.databaseReadOnly ? "TRUE"
                                             : "FALSE";
  
!         t.insert(row);
  
          // fredt - value set by SET MAXROWS in SQL, not Statement.setMaxRows()
          row    = t.getEmptyRowData();
          row[0] = "MAXROWS";
          row[1] = String.valueOf(session.getSQLMaxRows());
  
!         t.insert(row);
  
          row    = t.getEmptyRowData();
          row[0] = "DATABASE";
          row[1] = database.getURI();
  
!         t.insert(row);
  
          row    = t.getEmptyRowData();
          row[0] = "IDENTITY";
          row[1] = String.valueOf(session.getLastIdentity());
  
!         t.insert(row);
          t.setDataReadOnly(true);
  
          return t;
--- 656,708 ----
          row[0] = "SESSION_ID";
          row[1] = String.valueOf(session.getId());
  
!         t.insertSys(row);
  
          row    = t.getEmptyRowData();
          row[0] = "AUTOCOMMIT";
          row[1] = session.isAutoCommit() ? "TRUE"
                                          : "FALSE";
  
!         t.insertSys(row);
  
          row    = t.getEmptyRowData();
          row[0] = "USER";
          row[1] = session.getUsername();
  
!         t.insertSys(row);
  
          row    = t.getEmptyRowData();
          row[0] = "SESSION_READONLY";
          row[1] = session.isReadOnly() ? "TRUE"
                                        : "FALSE";
  
!         t.insertSys(row);
  
          row    = t.getEmptyRowData();
          row[0] = "DATABASE_READONLY";
          row[1] = database.databaseReadOnly ? "TRUE"
                                             : "FALSE";
  
!         t.insertSys(row);
  
          // fredt - value set by SET MAXROWS in SQL, not Statement.setMaxRows()
          row    = t.getEmptyRowData();
          row[0] = "MAXROWS";
          row[1] = String.valueOf(session.getSQLMaxRows());
  
!         t.insertSys(row);
  
          row    = t.getEmptyRowData();
          row[0] = "DATABASE";
          row[1] = database.getURI();
  
!         t.insertSys(row);
  
          row    = t.getEmptyRowData();
          row[0] = "IDENTITY";
          row[1] = String.valueOf(session.getLastIdentity());
  
!         t.insertSys(row);
          t.setDataReadOnly(true);
  
          return t;
***************
*** 741,747 ****
       *     <LI>hsqldb.nio_data_file - whether cache uses nio mapped buffers
       *     <LI>hsqldb.original_version -
       *     <LI>hsqldb.schemas - whether to report synthetic schema values for compatibility
-      *     <LI>sql.compare_in_locale - is JVM Locale used in collations?
       *     <LI>sql.enforce_size - column length specifications enforced (truncate/pad)?
       *     <LI>sql.enforce_strict_size - column length specifications enforced strictly (raise exception on overflow)?
       *     <LI>textdb.all_quoted - default policy regarding whether to quote all character field values
--- 741,746 ----
***************
*** 823,829 ****
          row[ivalue] = props.getProperty("hsqldb.catalogs", "false");
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // hsqldb.schemas
          row         = t.getEmptyRowData();
--- 822,828 ----
          row[ivalue] = props.getProperty("hsqldb.catalogs", "false");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // hsqldb.schemas
          row         = t.getEmptyRowData();
***************
*** 833,839 ****
          row[ivalue] = props.getProperty("hsqldb.schemas", "false");
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // sql.enforce_size
          row         = t.getEmptyRowData();
--- 832,838 ----
          row[ivalue] = props.getProperty("hsqldb.schemas", "false");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // sql.enforce_size
          row         = t.getEmptyRowData();
***************
*** 843,849 ****
          row[ivalue] = props.getProperty("sql.enforce_size", "false");
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // sql.enforce_strict_size
          row         = t.getEmptyRowData();
--- 842,848 ----
          row[ivalue] = props.getProperty("sql.enforce_size", "false");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // sql.enforce_strict_size
          row         = t.getEmptyRowData();
***************
*** 853,869 ****
          row[ivalue] = props.getProperty("sql.enforce_strict_size", "false");
          row[iclass] = "boolean";
  
!         t.insert(row);
! 
!         // sql.compare_in_locale
!         row         = t.getEmptyRowData();
!         row[iscope] = scope;
!         row[ins]    = nameSpace;
!         row[iname]  = "sql.compare_in_locale";
!         row[ivalue] = props.getProperty("sql.compare_in_locale", "false");
!         row[iclass] = "boolean";
! 
!         t.insert(row);
  
          // hsqldb.files_readonly
          row         = t.getEmptyRowData();
--- 852,858 ----
          row[ivalue] = props.getProperty("sql.enforce_strict_size", "false");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // hsqldb.files_readonly
          row         = t.getEmptyRowData();
***************
*** 873,879 ****
          row[ivalue] = props.getProperty("hsqldb.files_readonly", "false");
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // hsqldb.first_identity
          row         = t.getEmptyRowData();
--- 862,868 ----
          row[ivalue] = props.getProperty("hsqldb.files_readonly", "false");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // hsqldb.first_identity
          row         = t.getEmptyRowData();
***************
*** 883,889 ****
          row[ivalue] = props.getProperty("hsqldb.first_identity", "0");
          row[iclass] = "int";
  
!         t.insert(row);
  
          // hsqldb.compatible_version
          row         = t.getEmptyRowData();
--- 872,878 ----
          row[ivalue] = props.getProperty("hsqldb.first_identity", "0");
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // hsqldb.compatible_version
          row         = t.getEmptyRowData();
***************
*** 893,899 ****
          row[ivalue] = props.getProperty("hsqldb.compatible_version");
          row[iclass] = "java.lang.String";
  
!         t.insert(row);
  
          // hsqldb.cache_version
          row         = t.getEmptyRowData();
--- 882,888 ----
          row[ivalue] = props.getProperty("hsqldb.compatible_version");
          row[iclass] = "java.lang.String";
  
!         t.insertSys(row);
  
          // hsqldb.cache_version
          row         = t.getEmptyRowData();
***************
*** 903,909 ****
          row[ivalue] = props.getProperty(HsqlDatabaseProperties.CACHE_VERSION);
          row[iclass] = "java.lang.String";
  
!         t.insert(row);
  
          // hsqldb.original_version
          row         = t.getEmptyRowData();
--- 892,898 ----
          row[ivalue] = props.getProperty(HsqlDatabaseProperties.CACHE_VERSION);
          row[iclass] = "java.lang.String";
  
!         t.insertSys(row);
  
          // hsqldb.original_version
          row         = t.getEmptyRowData();
***************
*** 913,919 ****
          row[ivalue] = props.getProperty("hsqldb.original_version");
          row[iclass] = "java.lang.String";
  
!         t.insert(row);
  
          // hsqldb.cache_scale
          row         = t.getEmptyRowData();
--- 902,908 ----
          row[ivalue] = props.getProperty("hsqldb.original_version");
          row[iclass] = "java.lang.String";
  
!         t.insertSys(row);
  
          // hsqldb.cache_scale
          row         = t.getEmptyRowData();
***************
*** 923,929 ****
          row[ivalue] = props.getProperty("hsqldb.cache_scale");
          row[iclass] = "int";
  
!         t.insert(row);
  
          // hsqldb.cache_file_scale
          row         = t.getEmptyRowData();
--- 912,918 ----
          row[ivalue] = props.getProperty("hsqldb.cache_scale");
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // hsqldb.cache_file_scale
          row         = t.getEmptyRowData();
***************
*** 934,940 ****
              props.getProperty(HsqlDatabaseProperties.CACHE_FILE_SCALE);
          row[iclass] = "int";
  
!         t.insert(row);
  
          // hsqldb.cache_size_scale
          row         = t.getEmptyRowData();
--- 923,929 ----
              props.getProperty(HsqlDatabaseProperties.CACHE_FILE_SCALE);
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // hsqldb.cache_size_scale
          row         = t.getEmptyRowData();
***************
*** 944,950 ****
          row[ivalue] = props.getProperty("hsqldb.cache_size_scale");
          row[iclass] = "int";
  
!         t.insert(row);
  
          // hsqldb.max_nio_scale
          row         = t.getEmptyRowData();
--- 933,939 ----
          row[ivalue] = props.getProperty("hsqldb.cache_size_scale");
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // hsqldb.max_nio_scale
          row         = t.getEmptyRowData();
***************
*** 954,960 ****
          row[ivalue] = props.getProperty("hsqldb.max_nio_scale");
          row[iclass] = "int";
  
!         t.insert(row);
  
          // hsqldb.nio_data_file
          row         = t.getEmptyRowData();
--- 943,949 ----
          row[ivalue] = props.getProperty("hsqldb.max_nio_scale");
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // hsqldb.nio_data_file
          row         = t.getEmptyRowData();
***************
*** 964,970 ****
          row[ivalue] = props.getProperty("hsqldb.nio_data_file");
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // textdb.all_quoted
          row         = t.getEmptyRowData();
--- 953,959 ----
          row[ivalue] = props.getProperty("hsqldb.nio_data_file");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // textdb.all_quoted
          row         = t.getEmptyRowData();
***************
*** 974,980 ****
          row[ivalue] = props.getProperty("textdb.all_quoted", "false");
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // textdb.cache_scale
          row         = t.getEmptyRowData();
--- 963,969 ----
          row[ivalue] = props.getProperty("textdb.all_quoted", "false");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // textdb.cache_scale
          row         = t.getEmptyRowData();
***************
*** 984,990 ****
          row[ivalue] = props.getProperty("textdb.cache_scale", "10");
          row[iclass] = "int";
  
!         t.insert(row);
  
          // textdb.cache_size_scale
          row         = t.getEmptyRowData();
--- 973,979 ----
          row[ivalue] = props.getProperty("textdb.cache_scale", "10");
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // textdb.cache_size_scale
          row         = t.getEmptyRowData();
***************
*** 994,1000 ****
          row[ivalue] = props.getProperty("textdb.cache_size_scale", "12");
          row[iclass] = "int";
  
!         t.insert(row);
  
          // textdb.ignore_first
          row         = t.getEmptyRowData();
--- 983,989 ----
          row[ivalue] = props.getProperty("textdb.cache_size_scale", "12");
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // textdb.ignore_first
          row         = t.getEmptyRowData();
***************
*** 1004,1010 ****
          row[ivalue] = props.getProperty("textdb.ignore_first", "false");
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // textdb.quoted
          row         = t.getEmptyRowData();
--- 993,999 ----
          row[ivalue] = props.getProperty("textdb.ignore_first", "false");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // textdb.quoted
          row         = t.getEmptyRowData();
***************
*** 1014,1020 ****
          row[ivalue] = props.getProperty("textdb.quoted", "true");
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // textdb.fs
          row         = t.getEmptyRowData();
--- 1003,1009 ----
          row[ivalue] = props.getProperty("textdb.quoted", "true");
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // textdb.fs
          row         = t.getEmptyRowData();
***************
*** 1032,1038 ****
          row[ivalue] = props.getProperty("textdb.vs", ",");
          row[iclass] = "java.lang.String";
  
!         t.insert(row);
  
          // textdb.lvs
          row         = t.getEmptyRowData();
--- 1021,1027 ----
          row[ivalue] = props.getProperty("textdb.vs", ",");
          row[iclass] = "java.lang.String";
  
!         t.insertSys(row);
  
          // textdb.lvs
          row         = t.getEmptyRowData();
***************
*** 1042,1048 ****
          row[ivalue] = props.getProperty("textdb.lvs", ",");
          row[iclass] = "java.lang.String";
  
!         t.insert(row);
  
          // textdb.encoding
          row         = t.getEmptyRowData();
--- 1031,1037 ----
          row[ivalue] = props.getProperty("textdb.lvs", ",");
          row[iclass] = "java.lang.String";
  
!         t.insertSys(row);
  
          // textdb.encoding
          row         = t.getEmptyRowData();
***************
*** 1052,1058 ****
          row[ivalue] = props.getProperty("textdb.encoding", "ASCII");
          row[iclass] = "java.lang.String";
  
!         t.insert(row);
  
          // hsqldb.gc_interval
          row         = t.getEmptyRowData();
--- 1041,1047 ----
          row[ivalue] = props.getProperty("textdb.encoding", "ASCII");
          row[iclass] = "java.lang.String";
  
!         t.insertSys(row);
  
          // hsqldb.gc_interval
          row         = t.getEmptyRowData();
***************
*** 1062,1068 ****
          row[ivalue] = props.getProperty("hsqldb.gc_interval", "0");
          row[iclass] = "int";
  
!         t.insert(row);
  
          // Now get a snapshot of the properties that may change over
          // the lifetime of the session
--- 1051,1057 ----
          row[ivalue] = props.getProperty("hsqldb.gc_interval", "0");
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // Now get a snapshot of the properties that may change over
          // the lifetime of the session
***************
*** 1077,1083 ****
          row[ivalue] = "" + database.logger.getLogSize();
          row[iclass] = "int";
  
!         t.insert(row);
  
          row         = t.getEmptyRowData();
          row[iscope] = scope;
--- 1066,1072 ----
          row[ivalue] = "" + database.logger.getLogSize();
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          row         = t.getEmptyRowData();
          row[iscope] = scope;
***************
*** 1092,1098 ****
  
          row[iclass] = "java.lang.String";
  
!         t.insert(row);
  
          // write delay
          row         = t.getEmptyRowData();
--- 1081,1087 ----
  
          row[iclass] = "java.lang.String";
  
!         t.insertSys(row);
  
          // write delay
          row         = t.getEmptyRowData();
***************
*** 1102,1108 ****
          row[ivalue] = "" + database.logger.getWriteDelay();
          row[iclass] = "int";
  
!         t.insert(row);
  
          // ignore case
          row         = t.getEmptyRowData();
--- 1091,1097 ----
          row[ivalue] = "" + database.logger.getWriteDelay();
          row[iclass] = "int";
  
!         t.insertSys(row);
  
          // ignore case
          row         = t.getEmptyRowData();
***************
*** 1113,1119 ****
                                                : "false";
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // referential integrity
          row         = t.getEmptyRowData();
--- 1102,1108 ----
                                                : "false";
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // referential integrity
          row         = t.getEmptyRowData();
***************
*** 1124,1130 ****
                                                          : "false";
          row[iclass] = "boolean";
  
!         t.insert(row);
  
          // debug
          // oj@openoffice.org
--- 1113,1119 ----
                                                          : "false";
          row[iclass] = "boolean";
  
!         t.insertSys(row);
  
          // debug
          // oj@openoffice.org
***************
*** 1135,1141 ****
          row[ivalue] = "" + database.logger.appLog.getLevel();
          row[iclass] = "int";
  
!         t.insert(row);
          t.setDataReadOnly(true);
  
          return t;
--- 1124,1130 ----
          row[ivalue] = "" + database.logger.appLog.getLevel();
          row[iclass] = "int";
  
!         t.insertSys(row);
          t.setDataReadOnly(true);
  
          return t;
***************
*** 1224,1230 ****
                  ValuePool.getLong(s.getLastIdentity().longValue());
              row[it_size] = ValuePool.getInt(s.getTransactionSize());
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 1213,1219 ----
                  ValuePool.getLong(s.getLastIdentity().longValue());
              row[it_size] = ValuePool.getInt(s.getTransactionSize());
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 1426,1432 ****
                  row[iid] = ValuePool.getBoolean(table.isDescDataSource());
              }
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 1415,1421 ----
                  row[iid] = ValuePool.getBoolean(table.isDescDataSource());
              }
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 1504,1510 ****
                  ' ').append("a.").append("TABLE_NAME").append('=').append(
                  "b.").append("TABLE_NAME").toString());
  
!         t.insert(rs);
          t.setDataReadOnly(true);
  
          return t;
--- 1493,1499 ----
                  ' ').append("a.").append("TABLE_NAME").append('=').append(
                  "b.").append("TABLE_NAME").toString());
  
!         t.insertSys(rs);
          t.setDataReadOnly(true);
  
          return t;
***************
*** 1693,1699 ****
                      row[iaction_type]       = actionType;
                      row[itrigger_body]      = triggerBody;
  
!                     t.insert(row);
                  }
              }
          }
--- 1682,1688 ----
                      row[iaction_type]       = actionType;
                      row[itrigger_body]      = triggerBody;
  
!                     t.insertSys(row);
                  }
              }
          }
***************
*** 2010,2016 ****
              row[iiupd]  = "NO";
              row[ivalid] = Boolean.TRUE;
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 1999,2005 ----
              row[iiupd]  = "NO";
              row[ivalid] = Boolean.TRUE;
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 2369,2375 ****
              "select 'SYS', 'PUBLIC', SEQUENCE_CATALOG, SEQUENCE_SCHEMA, "
              + "SEQUENCE_NAME, 'SEQUENCE', 'FALSE' from  SYSTEM_SEQUENCES");
  
!         t.insert(rs);
          t.setDataReadOnly(true);
  
          return t;
--- 2358,2364 ----
              "select 'SYS', 'PUBLIC', SEQUENCE_CATALOG, SEQUENCE_SCHEMA, "
              + "SEQUENCE_NAME, 'SEQUENCE', 'FALSE' from  SYSTEM_SEQUENCES");
  
!         t.insertSys(rs);
          t.setDataReadOnly(true);
  
          return t;
***************
*** 2518,2524 ****
                      });
                  }
  
!                 result.removeDuplicates();
  
                  iterator = result.iterator();
  
--- 2507,2514 ----
                      });
                  }
  
!                 result.removeDuplicates(
!                     database.sessionManager.getSysSession());
  
                  iterator = result.iterator();
  
***************
*** 2533,2539 ****
                      row[itab_name]   = resultRow[2];
                      row[itab_col]    = resultRow[3];
  
!                     t.insert(row);
                  }
              }
          }
--- 2523,2529 ----
                      row[itab_name]   = resultRow[2];
                      row[itab_col]    = resultRow[3];
  
!                     t.insertSys(row);
                  }
              }
          }
***************
*** 2692,2698 ****
                      row[ir_schem]    = ns.getSchemaName(method);
                      row[ir_name] = DINameSpace.getMethodSpecificName(method);
  
!                     t.insert(row);
                  }
              }
          }
--- 2682,2688 ----
                      row[ir_schem]    = ns.getSchemaName(method);
                      row[ir_name] = DINameSpace.getMethodSpecificName(method);
  
!                     t.insertSys(row);
                  }
              }
          }
***************
*** 2764,2770 ****
              + "CONSTRAINT_NAME, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME "
              + "from SYSTEM_CHECK_COLUMN_USAGE");
  
!         t.insert(rs);
          t.setDataReadOnly(true);
  
          return t;
--- 2754,2760 ----
              + "CONSTRAINT_NAME, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME "
              + "from SYSTEM_CHECK_COLUMN_USAGE");
  
!         t.insertSys(rs);
          t.setDataReadOnly(true);
  
          return t;
***************
*** 2949,2955 ****
                  row[iis_defr]    = "NO";
                  row[iinit_defr]  = "NO";
  
!                 t.insert(row);
              }
  
              constraints     = table.getConstraints();
--- 2939,2945 ----
                  row[iis_defr]    = "NO";
                  row[iinit_defr]  = "NO";
  
!                 t.insertSys(row);
              }
  
              constraints     = table.getConstraints();
***************
*** 3008,3014 ****
              row[iis_defr]    = "NO";
              row[iinit_defr]  = "NO";
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 2998,3004 ----
              row[iis_defr]    = "NO";
              row[iinit_defr]  = "NO";
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 3079,3085 ****
              + "VIEW_NAME, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME "
              + "from SYSTEM_VIEW_COLUMN_USAGE");
  
!         t.insert(rs);
          t.setDataReadOnly(true);
  
          return t;
--- 3069,3075 ----
              + "VIEW_NAME, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME "
              + "from SYSTEM_VIEW_COLUMN_USAGE");
  
!         t.insertSys(rs);
          t.setDataReadOnly(true);
  
          return t;
***************
*** 3227,3233 ****
                  });
              }
  
!             result.removeDuplicates();
  
              iterator = result.iterator();
  
--- 3217,3223 ----
                  });
              }
  
!             result.removeDuplicates(database.sessionManager.getSysSession());
  
              iterator = result.iterator();
  
***************
*** 3242,3248 ****
                  row[it_name]  = resultRow[2];
                  row[it_cname] = resultRow[3];
  
!                 t.insert(row);
              }
          }
  
--- 3232,3238 ----
                  row[it_name]  = resultRow[2];
                  row[it_cname] = resultRow[3];
  
!                 t.insertSys(row);
              }
          }
  
***************
*** 3392,3398 ****
                  row[ir_schem] = ns.getSchemaName(method);
                  row[ir_name]  = DINameSpace.getMethodSpecificName(method);
  
!                 t.insert(row);
              }
          }
  
--- 3382,3388 ----
                  row[ir_schem] = ns.getSchemaName(method);
                  row[ir_name]  = DINameSpace.getMethodSpecificName(method);
  
!                 t.insertSys(row);
              }
          }
  
***************
*** 3473,3479 ****
          row[isn]        = specificName;
          row[iseq]       = sequence;
  
!         t.insert(row);
  
          if (l != null) {
              int size = l.size();
--- 3463,3469 ----
          row[isn]        = specificName;
          row[iseq]       = sequence;
  
!         t.insertSys(row);
  
          if (l != null) {
              int size = l.size();
***************
*** 3497,3503 ****
                  row[isn]        = specificName;
                  row[iseq]       = sequence;
  
!                 t.insert(row);
              }
          }
      }
--- 3487,3493 ----
                  row[isn]        = specificName;
                  row[iseq]       = sequence;
  
!                 t.insertSys(row);
              }
          }
      }
***************
*** 3560,3566 ****
          row[iporigin]      = origin;
          row[isn]           = specificName;
  
!         t.insert(row);
  
          if (l != null) {
              int size = l.size();
--- 3550,3556 ----
          row[iporigin]      = origin;
          row[isn]           = specificName;
  
!         t.insertSys(row);
  
          if (l != null) {
              int size = l.size();
***************
*** 3579,3585 ****
                  row[iporigin]      = "ALIAS";
                  row[isn]           = specificName;
  
!                 t.insert(row);
              }
          }
      }
--- 3569,3575 ----
                  row[iporigin]      = "ALIAS";
                  row[isn]           = specificName;
  
!                 t.insertSys(row);
              }
          }
      }
*** misc/hsqldb/src/org/hsqldb/DatabaseInformationMain.java	Wed Mar  2 14:50:47 2005
--- misc/build/hsqldb/src/org/hsqldb/DatabaseInformationMain.java	Thu Mar 24 14:18:00 2005
***************
*** 864,870 ****
                  row[inullable]       = ti.getColNullability(i);
                  row[iinKey]          = inKey;
  
!                 t.insert(row);
              }
          }
  
--- 864,870 ----
                  row[inullable]       = ti.getColNullability(i);
                  row[iinKey]          = inKey;
  
!                 t.insertSys(row);
              }
          }
  
***************
*** 912,918 ****
              row    = t.getEmptyRowData();
              row[0] = (String) catalogs.next();
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 912,918 ----
              row    = t.getEmptyRowData();
              row[0] = (String) catalogs.next();
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 985,991 ****
              + "a.GRANTOR, a.GRANTEE, a.PRIVILEGE, a.IS_GRANTABLE "
              + "from  SYSTEM_TABLEPRIVILEGES a, SYSTEM_COLUMNS b where a.TABLE_NAME = b.TABLE_NAME;");
  
!         t.insert(rs);
          t.setDataReadOnly(true);
  
          return t;
--- 985,991 ----
              + "a.GRANTOR, a.GRANTEE, a.PRIVILEGE, a.IS_GRANTABLE "
              + "from  SYSTEM_TABLEPRIVILEGES a, SYSTEM_COLUMNS b where a.TABLE_NAME = b.TABLE_NAME;");
  
!         t.insertSys(rs);
          t.setDataReadOnly(true);
  
          return t;
***************
*** 1144,1150 ****
                  row[iis_nullable]       = ti.getColIsNullable(i);
                  row[itype_sub]          = ti.getColDataTypeSub(i);
  
!                 t.insert(row);
              }
          }
  
--- 1144,1150 ----
                  row[iis_nullable]       = ti.getColIsNullable(i);
                  row[itype_sub]          = ti.getColDataTypeSub(i);
  
!                 t.insertSys(row);
              }
          }
  
***************
*** 1360,1366 ****
                  row[ipk_name]        = pkName;
                  row[ideferrability]  = deferrability;
  
!                 t.insert(row);
              }
          }
  
--- 1360,1366 ----
                  row[ipk_name]        = pkName;
                  row[ideferrability]  = deferrability;
  
!                 t.insertSys(row);
              }
          }
  
***************
*** 1531,1537 ****
                      row[ipages]            = pages;
                      row[ifilter_condition] = filterCondition;
  
!                     t.insert(row);
                  }
              }
          }
--- 1531,1537 ----
                      row[ipages]            = pages;
                      row[ifilter_condition] = filterCondition;
  
!                     t.insertSys(row);
                  }
              }
          }
***************
*** 1649,1655 ****
                  row[ikey_seq]     = ValuePool.getInt(j + 1);
                  row[ipk_name]     = primaryKeyName;
  
!                 t.insert(row);
              }
          }
  
--- 1649,1655 ----
                  row[ikey_seq]     = ValuePool.getInt(j + 1);
                  row[ipk_name]     = primaryKeyName;
  
!                 t.insertSys(row);
              }
          }
  
***************
*** 1869,1875 ****
              row[0] = schemas.next();
              row[1] = ns.getCatalogName(row[0]);
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 1869,1875 ----
              row[0] = schemas.next();
              row[1] = ns.getCatalogName(row[0]);
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 2001,2007 ****
                      row[iprivilege]    = privilege;
                      row[iis_grantable] = isGrantable;
  
!                     t.insert(row);
                  }
              }
          }
--- 2001,2007 ----
                      row[iprivilege]    = privilege;
                      row[iis_grantable] = isGrantable;
  
!                     t.insertSys(row);
                  }
              }
          }
***************
*** 2132,2138 ****
              row[ihsqldb_type] = ti.getHsqlType();
              row[iread_only]   = ti.isReadOnly();
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 2132,2138 ----
              row[ihsqldb_type] = ti.getHsqlType();
              row[iread_only]   = ti.isReadOnly();
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 2196,2202 ****
              row    = t.getEmptyRowData();
              row[0] = tableTypes[i];
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 2196,2202 ----
              row    = t.getEmptyRowData();
              row[0] = tableTypes[i];
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 2303,2309 ****
              + "MAXIMUM_SCALE, SQL_DATA_TYPE, SQL_DATETIME_SUB, NUM_PREC_RADIX, TYPE_SUB "
              + "from SYSTEM_ALLTYPEINFO  where AS_TAB_COL = true;");
  
!         t.insert(rs);
          t.setDataReadOnly(true);
  
          return t;
--- 2303,2309 ----
              + "MAXIMUM_SCALE, SQL_DATA_TYPE, SQL_DATETIME_SUB, NUM_PREC_RADIX, TYPE_SUB "
              + "from SYSTEM_ALLTYPEINFO  where AS_TAB_COL = true;");
  
!         t.insertSys(rs);
          t.setDataReadOnly(true);
  
          return t;
***************
*** 2630,2636 ****
              //------------------------------------------
              row[itype_sub] = ti.getDataTypeSub();
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 2630,2636 ----
              //------------------------------------------
              row[itype_sub] = ti.getDataTypeSub();
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 2678,2684 ****
              row[0] = user.getName();
              row[1] = ValuePool.getBoolean(user.isAdmin());
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 2678,2684 ----
              row[0] = user.getName();
              row[1] = ValuePool.getBoolean(user.isAdmin());
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 2805,2811 ****
                  row[icons_clause] = constraint.core.check.getDDL();
              } catch (Exception e) {}
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 2805,2811 ----
                  row[icons_clause] = constraint.core.check.getDDL();
              } catch (Exception e) {}
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
***************
*** 2974,2980 ****
                  }
              }
  
!             t.insert(row);
          }
  
          t.setDataReadOnly(true);
--- 2974,2980 ----
                  }
              }
  
!             t.insertSys(row);
          }
  
          t.setDataReadOnly(true);
*** misc/hsqldb/src/org/hsqldb/DatabaseScript.java	Wed Mar  2 14:50:47 2005
--- misc/build/hsqldb/src/org/hsqldb/DatabaseScript.java	Thu Mar 24 14:18:00 2005
***************
*** 72,77 ****
--- 72,78 ----
  import org.hsqldb.lib.HsqlArrayList;
  import org.hsqldb.lib.IntValueHashMap;
  import org.hsqldb.lib.Iterator;
+ import org.hsqldb.lib.StringConverter;
  
  /**
   * Script generation.
***************
*** 247,252 ****
--- 248,262 ----
              addRow(r, "SET IGNORECASE TRUE");
          }
  
+         // collation for database
+         if (dDatabase.collation.name != null) {
+             String name =
+                 StringConverter.toQuotedString(dDatabase.collation.name, '"',
+                                                true);
+ 
+             addRow(r, "SET DATABASE COLLATION " + name);
+         }
+ 
          // aliases
          HashMap  h       = dDatabase.getAliasMap();
          HashMap  builtin = Library.getAliasMap();
*** misc/hsqldb/src/org/hsqldb/Expression.java	Wed Mar  2 14:50:48 2005
--- misc/build/hsqldb/src/org/hsqldb/Expression.java	Thu Mar 24 14:18:00 2005
***************
*** 375,380 ****
--- 375,382 ----
          this.dataType  = dataType;
          this.precision = precision;
          this.scale     = scale;
+ 
+         checkAggregate();
      }
  
      /**
***************
*** 384,395 ****
       * @param e2 operand 2
       * @param escape escape character
       */
!     Expression(Expression e, Expression e2, Character escape) {
  
          exprType   = LIKE;
          eArg       = e;
          eArg2      = e2;
!         likeObject = new Like(escape);
  
          checkAggregate();
      }
--- 386,398 ----
       * @param e2 operand 2
       * @param escape escape character
       */
!     Expression(Expression e, Expression e2, Character escape,
!                boolean hasCollation) {
  
          exprType   = LIKE;
          eArg       = e;
          eArg2      = e2;
!         likeObject = new Like(escape, hasCollation);
  
          checkAggregate();
      }
***************
*** 1875,1880 ****
--- 1878,1886 ----
  
          switch (exprType) {
  
+             case COLUMN :
+                 break;
+ 
              case FUNCTION :
                  function.resolveType();
  
***************
*** 2327,2340 ****
              exprType   = EQUAL;
              eArg2 = new Expression(Types.VARCHAR, likeObject.getRangeLow());
              likeObject = null;
!         } else if (likeObject.isEquivalentToNotNullPredicate()) {
! 
!             // X LIKE '%' <=>  X IS NOT NULL
!             exprType   = NOT;
!             eArg       = new Expression(IS_NULL, eArg, null);
!             eArg2      = null;
!             likeObject = null;
!         } else {
              if (eArg.exprType != Expression.COLUMN) {
  
                  // Then we are done here, since range predicates are
--- 2333,2340 ----
              exprType   = EQUAL;
              eArg2 = new Expression(Types.VARCHAR, likeObject.getRangeLow());
              likeObject = null;
!         } else if (likeObject.isEquivalentToNotNullPredicate()) {}
!         else {
              if (eArg.exprType != Expression.COLUMN) {
  
                  // Then we are done here, since range predicates are
***************
*** 2368,2381 ****
              if (likeObject.isEquivalentToBetweenPredicate()) {
  
                  // X LIKE 'abc%' <=> X >= 'abc' AND X <= 'abc' || max_collation_char
!                 larger  = Column.sql_compare_in_locale;
                  between = !larger;
                  like    = larger;
              } else if (likeObject
                      .isEquivalentToBetweenPredicateAugmentedWithLike()) {
  
                  // X LIKE 'abc%...' <=> X >= 'abc' AND X <= 'abc' || max_collation_char AND X LIKE 'abc%...'
!                 larger  = Column.sql_compare_in_locale;
                  between = !larger;
                  like    = true;
              }
--- 2368,2381 ----
              if (likeObject.isEquivalentToBetweenPredicate()) {
  
                  // X LIKE 'abc%' <=> X >= 'abc' AND X <= 'abc' || max_collation_char
!                 larger  = likeObject.hasCollation;
                  between = !larger;
                  like    = larger;
              } else if (likeObject
                      .isEquivalentToBetweenPredicateAugmentedWithLike()) {
  
                  // X LIKE 'abc%...' <=> X >= 'abc' AND X <= 'abc' || max_collation_char AND X LIKE 'abc%...'
!                 larger  = likeObject.hasCollation;
                  between = !larger;
                  like    = true;
              }
***************
*** 2400,2406 ****
                  Expression gte = new Expression(BIGGER_EQUAL, eArg, eFirst);
                  Expression lte = new Expression(SMALLER_EQUAL, eArg, eLast);
  
!                 eArg2 = new Expression(eArg, eArg2, likeObject.escapeChar);
                  eArg2.likeObject = likeObject;
                  eArg             = new Expression(AND, gte, lte);
                  exprType         = AND;
--- 2400,2407 ----
                  Expression gte = new Expression(BIGGER_EQUAL, eArg, eFirst);
                  Expression lte = new Expression(SMALLER_EQUAL, eArg, eLast);
  
!                 eArg2 = new Expression(eArg, eArg2, likeObject.escapeChar,
!                                        likeObject.hasCollation);
                  eArg2.likeObject = likeObject;
                  eArg             = new Expression(AND, gte, lte);
                  exprType         = AND;
***************
*** 2408,2414 ****
              } else if (larger) {
                  Expression gte = new Expression(BIGGER_EQUAL, eArg, eFirst);
  
!                 eArg2 = new Expression(eArg, eArg2, likeObject.escapeChar);
                  eArg2.likeObject = likeObject;
                  eArg             = gte;
                  exprType         = AND;
--- 2409,2416 ----
              } else if (larger) {
                  Expression gte = new Expression(BIGGER_EQUAL, eArg, eFirst);
  
!                 eArg2 = new Expression(eArg, eArg2, likeObject.escapeChar,
!                                        likeObject.hasCollation);
                  eArg2.likeObject = likeObject;
                  eArg             = gte;
                  exprType         = AND;
***************
*** 2868,2875 ****
                  String c = (String) Column.convertObject(leftValue,
                      Types.VARCHAR);
  
!                 return likeObject.compare(c) ? Boolean.TRUE
!                                              : Boolean.FALSE;
  
              case IN :
                  return eArg2.testValueList(session, leftValue);
--- 2870,2876 ----
                  String c = (String) Column.convertObject(leftValue,
                      Types.VARCHAR);
  
!                 return likeObject.compare(session, c);
  
              case IN :
                  return eArg2.testValueList(session, leftValue);
***************
*** 2935,2941 ****
              int valueType = eArg.isColumn() ? eArg.dataType
                                              : eArg2.dataType;
  
!             return compareValues(leftValue, rightValue, valueType, exprType)
                     ? Boolean.TRUE
                     : Boolean.FALSE;
          }
--- 2936,2942 ----
              int valueType = eArg.isColumn() ? eArg.dataType
                                              : eArg2.dataType;
  
!             return compareValues(session, leftValue, rightValue, valueType, exprType)
                     ? Boolean.TRUE
                     : Boolean.FALSE;
          }
***************
*** 2999,3005 ****
                                                             : eArg.getValue(
                                                                 session);
  
!                 ((SetFunction) currValue).add(newValue);
  
                  return currValue;
              }
--- 3000,3006 ----
                                                             : eArg.getValue(
                                                                 session);
  
!                 ((SetFunction) currValue).add(session, newValue);
  
                  return currValue;
              }
***************
*** 3195,3202 ****
  
                  String c = (String) eArg.getValue(session, Types.VARCHAR);
  
!                 return likeObject.compare(c) ? Boolean.TRUE
!                                              : Boolean.FALSE;
  
              case IN :
                  return eArg2.testValueList(session, eArg.getValue(session));
--- 3196,3202 ----
  
                  String c = (String) eArg.getValue(session, Types.VARCHAR);
  
!                 return likeObject.compare(session, c);
  
              case IN :
                  return eArg2.testValueList(session, eArg.getValue(session));
***************
*** 3255,3268 ****
              return null;
          }
  
!         return compareValues(o, o2, type, exprType) ? Boolean.TRUE
!                                                     : Boolean.FALSE;
      }
  
!     private static boolean compareValues(Object o, Object o2, int valueType,
                                           int exprType) throws HsqlException {
  
!         int result = Column.compare(o, o2, valueType);
  
          switch (exprType) {
  
--- 3255,3269 ----
              return null;
          }
  
!         return compareValues(session, o, o2, type, exprType) ? Boolean.TRUE
!                                                              : Boolean.FALSE;
      }
  
!     private static boolean compareValues(Session session, Object o,
!                                          Object o2, int valueType,
                                           int exprType) throws HsqlException {
  
!         int result = Column.compare(session, o, o2, valueType);
  
          switch (exprType) {
  
***************
*** 3327,3333 ****
              for (int i = 0; i < len; i++) {
                  Object o2 = valueList[i].getValue(session, dataType);
  
!                 if (Column.compare(o, o2, dataType) == 0) {
                      return Boolean.TRUE;
                  }
              }
--- 3328,3334 ----
              for (int i = 0; i < len; i++) {
                  Object o2 = valueList[i].getValue(session, dataType);
  
!                 if (Column.compare(session, o, o2, dataType) == 0) {
                      return Boolean.TRUE;
                  }
              }
***************
*** 3351,3357 ****
              Result r = subSelect.getResult(session, 0);
  
              // fredt - reduce the size if possible
!             r.removeDuplicates();
  
              Record n    = r.rRoot;
              int    type = r.metaData.colTypes[0];
--- 3352,3358 ----
              Result r = subSelect.getResult(session, 0);
  
              // fredt - reduce the size if possible
!             r.removeDuplicates(session);
  
              Record n    = r.rRoot;
              int    type = r.metaData.colTypes[0];
***************
*** 3365,3371 ****
              while (n != null) {
                  Object o2 = n.data[0];
  
!                 if (o2 != null && Column.compare(o2, o, type) == 0) {
                      return Boolean.TRUE;
                  }
  
--- 3366,3372 ----
              while (n != null) {
                  Object o2 = n.data[0];
  
!                 if (o2 != null && Column.compare(session, o2, o, type) == 0) {
                      return Boolean.TRUE;
                  }
  
*** misc/hsqldb/src/org/hsqldb/HSQLClientConnection.java	Wed Mar  2 14:50:48 2005
--- misc/build/hsqldb/src/org/hsqldb/HSQLClientConnection.java	Thu Mar 24 14:18:00 2005
***************
*** 112,129 ****
  
          rowOut    = new RowOutputBinary(mainBuffer);
          rowIn     = new RowInputBinary(rowOut);
!         resultOut = new Result(ResultConstants.DATA, 7);
!         resultOut.metaData.colNames = resultOut.metaData.colLabels =
!             resultOut.metaData.tableNames = new String[] {
!             "", "", "", "", "", "", ""
!         };
  
          resultOut.add(new Object[7]);
- 
-         resultOut.metaData.colTypes = new int[] {
-             Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
-             Types.BOOLEAN, Types.BOOLEAN, Types.BOOLEAN
-         };
      }
  
      protected void initConnection(String host, int port,
--- 112,120 ----
  
          rowOut    = new RowOutputBinary(mainBuffer);
          rowIn     = new RowInputBinary(rowOut);
!         resultOut = Result.newSessionAttributesResult();
  
          resultOut.add(new Object[7]);
      }
  
      protected void initConnection(String host, int port,
***************
*** 241,246 ****
--- 232,246 ----
                            : Boolean.FALSE, Session.INFO_AUTOCOMMIT);
      }
  
+     public void setIsolation(int level) throws HsqlException {}
+ 
+     public int getIsolation() throws HsqlException {
+ 
+         Object info = getAttribute(Session.INFO_ISOLATION);
+ 
+         return ((Integer) info).intValue();
+     }
+ 
      public boolean isClosed() {
          return isClosed;
      }
*** misc/hsqldb/src/org/hsqldb/HsqlDateTime.java	Wed Mar  2 14:50:48 2005
--- misc/build/hsqldb/src/org/hsqldb/HsqlDateTime.java	Thu Mar 24 14:18:00 2005
***************
*** 526,529 ****
--- 526,727 ----
              return tempCalDefault.get(part);
          }
      }
+ 
+     private final static char[][] dateTokens     = {
+         {
+             'R', 'R', 'R', 'R'
+         }, {
+             'I', 'Y', 'Y', 'Y'
+         }, {
+             'Y', 'Y', 'Y', 'Y'
+         }, {
+             'I', 'Y'
+         }, {
+             'Y', 'Y'
+         }, {
+             'B', 'C'
+         }, {
+             'B', '.', 'C', '.'
+         }, {
+             'A', 'D'
+         }, {
+             'A', '.', 'D', '.'
+         }, {
+             'M', 'O', 'N'
+         }, {
+             'M', 'O', 'N', 'T', 'H'
+         }, { 'D' }, {
+             'I', 'W'
+         }, {
+             'D', 'D'
+         }, {
+             'D', 'D', 'D'
+         }, {
+             'H', 'H', '2', '4'
+         }, {
+             'H', 'H', '1', '2'
+         }, {
+             'H', 'H'
+         }, {
+             'M', 'I',
+         }, {
+             'S', 'S'
+         }, {
+             'A', 'M'
+         }, {
+             'P', 'M',
+         }, {
+             'A', '.', 'M', '.'
+         }, {
+             'P', '.', 'M', '.'
+         }
+     };
+     private final static String[] javaDateTokens = {
+         "yyyy", "yyyy", "yyyy", "yy", "yy", "G", "G", "G", "G", "MMM",
+         "MMMMM", "E", "w", "dd", "D", "k", "K", "K", "mm", "ss", "aaa", "aaa",
+         "aaa", "aaa"
+     };
+ 
+     /** Indicates end-of-input */
+     public static final char e = 0xffff;
+ 
+     /**
+      * Converts the given format into a pattern accepted by <code>java.text.SimpleDataFormat</code>
+      * @param format
+      * @return
+      */
+     public static String toJavaDatePattern(String format) {
+ 
+         int          len = format.length();
+         char         ch;
+         StringBuffer pattern   = new StringBuffer(len);
+         Tokenizer    tokenizer = new Tokenizer();
+ 
+         for (int i = 0; i <= len; i++) {
+             ch = (i == len) ? e
+                             : format.charAt(i);
+ 
+             if (!tokenizer.next(ch, dateTokens)) {
+                 int index = tokenizer.getLastMatch();
+ 
+                 if (index >= 0) {
+                     pattern.setLength(pattern.length() - tokenizer.length());
+                     pattern.append(javaDateTokens[index]);
+                 }
+ 
+                 tokenizer.reset();
+ 
+                 if (tokenizer.isConsumed()) {
+                     continue;
+                 }
+             }
+ 
+             pattern.append(ch);
+         }
+ 
+         return pattern.substring(0, pattern.length() - 1);
+     }
+ 
+     /**
+      * This class can match 64 tokens at maximum.
+      */
+     static class Tokenizer {
+ 
+         private int     last;
+         private int     offset;
+         private long    state;
+         private boolean consumed;
+ 
+         public Tokenizer() {
+             reset();
+         }
+ 
+         /**
+          * Resets for next reuse.
+          *
+          */
+         public void reset() {
+ 
+             last   = -1;
+             offset = -1;
+             state  = 0;
+         }
+ 
+         /**
+          * Returns a length of a token to match.
+          * @return
+          */
+         public int length() {
+             return offset;
+         }
+ 
+         /**
+          * Returns an index of the last matched token.
+          * @return
+          */
+         public int getLastMatch() {
+             return last;
+         }
+ 
+         /**
+          * Indicates whethe the last character has been consumed by the matcher.
+          * @return
+          */
+         public boolean isConsumed() {
+             return consumed;
+         }
+ 
+         /**
+          * Checks whether the specified bit is not set.
+          * @param bit
+          * @return
+          */
+         private boolean isZeroBit(int bit) {
+             return (state & (1L << bit)) == 0;
+         }
+ 
+         /**
+          * Sets the specified bit.
+          * @param bit
+          */
+         private void setBit(int bit) {
+             state |= (1L << bit);
+         }
+ 
+         /**
+          * Matches the specified character against tokens.
+          * @param ch
+          * @param tokens
+          * @return
+          */
+         public boolean next(char ch, char[][] tokens) {
+ 
+             // Use local variable for performance
+             int index = ++offset;
+             int len   = offset + 1;
+             int left  = 0;
+ 
+             consumed = false;
+ 
+             for (int i = tokens.length; --i >= 0; ) {
+                 if (isZeroBit(i)) {
+                     if (tokens[i][index] == ch) {
+                         consumed = true;
+ 
+                         if (tokens[i].length == len) {
+                             setBit(i);
+ 
+                             last = i;
+                         } else {
+                             ++left;
+                         }
+                     } else {
+                         setBit(i);
+                     }
+                 }
+             }
+ 
+             return left > 0;
+         }
+     }
  }
*** misc/hsqldb/src/org/hsqldb/HsqlNameManager.java	Wed Mar  2 14:50:48 2005
--- misc/build/hsqldb/src/org/hsqldb/HsqlNameManager.java	Thu Mar 24 14:18:00 2005
***************
*** 62,68 ****
  class HsqlNameManager {
  
      private static HsqlNameManager staticManager = new HsqlNameManager();
!     private static int             serialNumber  = 0;
      private int                    sysNumber     = 0;
  
      static HsqlName newHsqlSystemTableName(String name) {
--- 62,68 ----
  class HsqlNameManager {
  
      private static HsqlNameManager staticManager = new HsqlNameManager();
!     private int                    serialNumber  = 1;    // 0 is reserved in lookups
      private int                    sysNumber     = 0;
  
      static HsqlName newHsqlSystemTableName(String name) {
***************
*** 92,98 ****
  
      /**
       * Auto names are used for autogenerated indexes or anonymous constraints.
-      * Also the name of a pseudo-column is the autoname ""
       */
      HsqlName newAutoName(String type, String namepart) {
  
--- 92,97 ----
***************
*** 133,139 ****
  
          private HsqlName(HsqlNameManager man) {
              manager  = man;
!             hashCode = HsqlNameManager.serialNumber++;
          }
  
          private HsqlName(HsqlNameManager man, String name,
--- 132,138 ----
  
          private HsqlName(HsqlNameManager man) {
              manager  = man;
!             hashCode = manager.serialNumber++;
          }
  
          private HsqlName(HsqlNameManager man, String name,
*** misc/hsqldb/src/org/hsqldb/Index.java	Wed Mar  2 14:50:48 2005
--- misc/build/hsqldb/src/org/hsqldb/Index.java	Thu Mar 24 14:18:00 2005
***************
*** 253,259 ****
      /**
       * Insert a node into the index
       */
!     void insert(Row row, int offset) throws HsqlException {
  
          Node    n       = root,
                  x       = n;
--- 253,259 ----
      /**
       * Insert a node into the index
       */
!     void insert(Session session, Row row, int offset) throws HsqlException {
  
          Node    n       = root,
                  x       = n;
***************
*** 273,279 ****
                  break;
              }
  
!             compare = compareRowUnique(row, n.getRow());
  
              if (compare == 0) {
                  throw Trace.error(Trace.VIOLATION_OF_UNIQUE_INDEX,
--- 273,279 ----
                  break;
              }
  
!             compare = compareRowUnique(session, row, n.getRow());
  
              if (compare == 0) {
                  throw Trace.error(Trace.VIOLATION_OF_UNIQUE_INDEX,
***************
*** 523,529 ****
      RowIterator findFirstRow(Session session, Object[] rowdata,
                               int[] rowColMap) throws HsqlException {
  
!         Node node = findNotNull(rowdata, rowColMap, true);
  
          return node == null ? emptyIterator
                              : new IndexRowIterator(session, this, node);
--- 523,529 ----
      RowIterator findFirstRow(Session session, Object[] rowdata,
                               int[] rowColMap) throws HsqlException {
  
!         Node node = findNotNull(session, rowdata, rowColMap, true);
  
          return node == null ? emptyIterator
                              : new IndexRowIterator(session, this, node);
***************
*** 532,538 ****
      RowIterator findFirstRowForDelete(Session session, Object[] rowdata,
                                        int[] rowColMap) throws HsqlException {
  
!         Node node = findNotNull(rowdata, rowColMap, true);
  
          if (node == null) {
              return emptyIterator;
--- 532,538 ----
      RowIterator findFirstRowForDelete(Session session, Object[] rowdata,
                                        int[] rowColMap) throws HsqlException {
  
!         Node node = findNotNull(session, rowdata, rowColMap, true);
  
          if (node == null) {
              return emptyIterator;
***************
*** 547,553 ****
  
      public Row findRow(Session session, Row row) throws HsqlException {
  
!         Node node = search(row);
  
          return node == null ? null
                              : node.getRow();
--- 547,553 ----
  
      public Row findRow(Session session, Row row) throws HsqlException {
  
!         Node node = search(session, row);
  
          return node == null ? null
                              : node.getRow();
***************
*** 555,561 ****
  
      boolean exists(Session session, Object[] rowdata,
                     int[] rowColMap) throws HsqlException {
!         return findNotNull(rowdata, rowColMap, true) != null;
      }
  
      RowIterator emptyIterator() {
--- 555,561 ----
  
      boolean exists(Session session, Object[] rowdata,
                     int[] rowColMap) throws HsqlException {
!         return findNotNull(session, rowdata, rowColMap, true) != null;
      }
  
      RowIterator emptyIterator() {
***************
*** 571,577 ****
       * @return matching node or null
       * @throws HsqlException
       */
!     private Node findNotNull(Object[] rowdata, int[] rowColMap,
                               boolean first) throws HsqlException {
  
          Node x      = root, n;
--- 571,578 ----
       * @return matching node or null
       * @throws HsqlException
       */
!     private Node findNotNull(Session session, Object[] rowdata,
!                              int[] rowColMap,
                               boolean first) throws HsqlException {
  
          Node x      = root, n;
***************
*** 582,588 ****
          }
  
          while (x != null) {
!             int i = this.compareRowNonUnique(rowdata, rowColMap, x.getData());
  
              if (i == 0) {
                  if (first == false) {
--- 583,590 ----
          }
  
          while (x != null) {
!             int i = this.compareRowNonUnique(session, rowdata, rowColMap,
!                                              x.getData());
  
              if (i == 0) {
                  if (first == false) {
***************
*** 620,625 ****
--- 622,628 ----
       * @return node matching node
       * @throws HsqlException
       */
+ /*
      Node find(Object[] rowdata, int[] rowColMap) throws HsqlException {
  
          Node x = root;
***************
*** 638,643 ****
--- 641,647 ----
  
          return null;
      }
+ */
  
      /**
       * Determines if a table row has a null column for any of the columns given
***************
*** 691,697 ****
          boolean unique = isUnique &&!isNull(rowdata);
  
          while (x != null) {
!             int c = compareRowNonUnique(rowdata, colIndex, x.getData());
  
              if (c == 0) {
                  found = x;
--- 695,702 ----
          boolean unique = isUnique &&!isNull(rowdata);
  
          while (x != null) {
!             int c = compareRowNonUnique(session, rowdata, colIndex,
!                                         x.getData());
  
              if (c == 0) {
                  found = x;
***************
*** 751,758 ****
  */
          while (x != null) {
              boolean t =
!                 Column.compare(value, x.getData()[colIndex[0]], colType[0])
!                 >= iTest;
  
              if (t) {
                  Node r = x.getRight();
--- 756,764 ----
  */
          while (x != null) {
              boolean t =
!                 Column.compare(
!                     session, value, x.getData()[colIndex[0]],
!                     colType[0]) >= iTest;
  
              if (t) {
                  Node r = x.getRight();
***************
*** 782,788 ****
  */
          while (x != null) {
              Object colvalue = x.getData()[colIndex[0]];
!             int    result   = Column.compare(value, colvalue, colType[0]);
  
              if (result >= iTest) {
                  x = next(x);
--- 788,794 ----
  */
          while (x != null) {
              Object colvalue = x.getData()[colIndex[0]];
!             int result = Column.compare(session, value, colvalue, colType[0]);
  
              if (result >= iTest) {
                  x = next(x);
***************
*** 817,825 ****
          Node x = root;
  
          while (x != null) {
!             boolean t =
!                 Column.compare(null, x.getData()[colIndex[0]], colType[0])
!                 >= 0;
  
              if (t) {
                  Node r = x.getRight();
--- 823,830 ----
          Node x = root;
  
          while (x != null) {
!             boolean t = Column.compare(
!                 session, null, x.getData()[colIndex[0]], colType[0]) >= 0;
  
              if (t) {
                  Node r = x.getRight();
***************
*** 988,1000 ****
       *
       * @throws HsqlException
       */
!     Node search(Row row) throws HsqlException {
  
          Object[] d = row.getData();
          Node     x = root;
  
          while (x != null) {
!             int c = compareRowUnique(row, x.getRow());
  
              if (c == 0) {
                  return x;
--- 993,1005 ----
       *
       * @throws HsqlException
       */
!     Node search(Session session, Row row) throws HsqlException {
  
          Object[] d = row.getData();
          Node     x = root;
  
          while (x != null) {
!             int c = compareRowUnique(session, row, x.getRow());
  
              if (c == 0) {
                  return x;
***************
*** 1022,1031 ****
       * @return comparison result, -1,0,+1
       * @throws HsqlException
       */
!     int compareRowNonUnique(Object[] a, int[] rowColMap,
                              Object[] b) throws HsqlException {
  
!         int i = Column.compare(a[rowColMap[0]], b[colIndex[0]], colType[0]);
  
          if (i != 0) {
              return i;
--- 1027,1037 ----
       * @return comparison result, -1,0,+1
       * @throws HsqlException
       */
!     int compareRowNonUnique(Session session, Object[] a, int[] rowColMap,
                              Object[] b) throws HsqlException {
  
!         int i = Column.compare(session, a[rowColMap[0]], b[colIndex[0]],
!                                colType[0]);
  
          if (i != 0) {
              return i;
***************
*** 1034,1040 ****
          int fieldcount = rowColMap.length;
  
          for (int j = 1; j < fieldcount; j++) {
!             i = Column.compare(a[rowColMap[j]], b[colIndex[j]], colType[j]);
  
              if (i != 0) {
                  return i;
--- 1040,1047 ----
          int fieldcount = rowColMap.length;
  
          for (int j = 1; j < fieldcount; j++) {
!             i = Column.compare(session, a[rowColMap[j]], b[colIndex[j]],
!                                colType[j]);
  
              if (i != 0) {
                  return i;
***************
*** 1054,1066 ****
       * @return comparison result, -1,0,+1
       * @throws HsqlException
       */
!     static int compareRows(Object[] a, Object[] b, int[] cols,
!                            int[] coltypes) throws HsqlException {
  
          int fieldcount = cols.length;
  
          for (int j = 0; j < fieldcount; j++) {
!             int i = Column.compare(a[cols[j]], b[cols[j]], coltypes[j]);
  
              if (i != 0) {
                  return i;
--- 1061,1074 ----
       * @return comparison result, -1,0,+1
       * @throws HsqlException
       */
!     static int compareRows(Session session, Object[] a, Object[] b,
!                            int[] cols, int[] coltypes) throws HsqlException {
  
          int fieldcount = cols.length;
  
          for (int j = 0; j < fieldcount; j++) {
!             int i = Column.compare(session, a[cols[j]], b[cols[j]],
!                                    coltypes[cols[j]]);
  
              if (i != 0) {
                  return i;
***************
*** 1080,1086 ****
       *
       * @throws HsqlException
       */
!     private int compareRowUnique(Row left, Row right) throws HsqlException {
  
          Object[] a       = left.getData();
          Object[] b       = right.getData();
--- 1088,1095 ----
       *
       * @throws HsqlException
       */
!     private int compareRowUnique(Session session, Row left,
!                                  Row right) throws HsqlException {
  
          Object[] a       = left.getData();
          Object[] b       = right.getData();
***************
*** 1089,1095 ****
  
          for (; j < colIndex.length; j++) {
              Object currentvalue = a[colIndex[j]];
!             int i = Column.compare(currentvalue, b[colIndex[j]], colType[j]);
  
              if (i != 0) {
                  return i;
--- 1098,1105 ----
  
          for (; j < colIndex.length; j++) {
              Object currentvalue = a[colIndex[j]];
!             int i = Column.compare(session, currentvalue, b[colIndex[j]],
!                                    colType[j]);
  
              if (i != 0) {
                  return i;
***************
*** 1106,1112 ****
  
          for (j = 0; j < pkCols.length; j++) {
              Object currentvalue = a[pkCols[j]];
!             int    i = Column.compare(currentvalue, b[pkCols[j]], pkTypes[j]);
  
              if (i != 0) {
                  return i;
--- 1116,1123 ----
  
          for (j = 0; j < pkCols.length; j++) {
              Object currentvalue = a[pkCols[j]];
!             int i = Column.compare(session, currentvalue, b[pkCols[j]],
!                                    pkTypes[j]);
  
              if (i != 0) {
                  return i;
***************
*** 1161,1166 ****
--- 1172,1178 ----
  
      static class IndexRowIterator implements RowIterator {
  
+         Session                    session;
          Index                      index;
          Node                       nextnode;
          protected IndexRowIterator last;
***************
*** 1172,1177 ****
--- 1184,1190 ----
                  return;
              }
  
+             this.session  = session;
              this.index    = index;
              this.nextnode = node;
          }
*** misc/hsqldb/src/org/hsqldb/Library.java	Wed Mar  2 14:50:53 2005
--- misc/build/hsqldb/src/org/hsqldb/Library.java	Thu Mar 24 14:18:00 2005
***************
*** 87,92 ****
--- 87,93 ----
  // boucherb@user 20020918 - doc 1.7.2 - added JavaDoc  and code comments
  // fredt@user 20021021 - doc 1.7.2 - modified JavaDoc
  // boucherb@users 20030201 - patch 1.7.2 - direct calls for org.hsqldb.Library
+ //
  
  /**
   * fredt - todo - since the introduction of SQL built-in functions and
***************
*** 107,112 ****
--- 108,114 ----
   */
  public class Library {
  
+     static final SimpleDateFormat tocharFormat = new SimpleDateFormat();
      static final SimpleDateFormat daynameFormat = new SimpleDateFormat("EEEE",
          Locale.ENGLISH);
      static final SimpleDateFormat monthnameFormat =
***************
*** 271,276 ****
--- 273,280 ----
              "WEEK", "org.hsqldb.Library.week"
          }, {
              "YEAR", "org.hsqldb.Library.year"
+         }, {
+             "TO_CHAR", "org.hsqldb.Library.to_char"
          }
      };
      public static final String[][] sSystem   = {
***************
*** 1562,1567 ****
--- 1566,1584 ----
                  Calendar.YEAR));
      }
  
+     public static String to_char(java.util.Date d, String format) {
+ 
+         if (d == null || format == null) {
+             return null;
+         }
+ 
+         synchronized (tocharFormat) {
+             tocharFormat.applyPattern(HsqlDateTime.toJavaDatePattern(format));
+ 
+             return tocharFormat.format(d);
+         }
+     }
+ 
      // date calculations.
  
      /**
***************
*** 1893,1898 ****
--- 1910,1916 ----
      static final int soundex                   = 54;
      static final int space                     = 55;
      static final int substring                 = 56;
+     static final int to_char                   = 65;
      static final int trim                      = 57;
      static final int truncate                  = 58;
      static final int ucase                     = 59;
***************
*** 1968,1973 ****
--- 1986,1992 ----
          functionMap.put("soundex", soundex);
          functionMap.put("space", space);
          functionMap.put("substring", substring);
+         functionMap.put("to_char", to_char);
          functionMap.put("trim", trim);
          functionMap.put("truncate", truncate);
          functionMap.put("ucase", ucase);
***************
*** 2206,2211 ****
--- 2225,2233 ----
                  case year : {
                      return year((Date) params[0]);
                  }
+                 case to_char : {
+                     return to_char((Date) params[0], (String) params[1]);
+                 }
                  case isReadOnlyDatabaseFiles : {
                      return null;
                  }
*** misc/hsqldb/src/org/hsqldb/Like.java	Wed Mar  2 14:50:53 2005
--- misc/build/hsqldb/src/org/hsqldb/Like.java	Thu Mar 24 14:18:00 2005
***************
*** 85,96 ****
      private int      iFirstWildCard;
      private boolean  isNull;
      Character        escapeChar;
      boolean          optimised;
      static final int UNDERSCORE_CHAR = 1;
      static final int PERCENT_CHAR    = 2;
  
!     Like(Character escape) {
!         escapeChar = escape;
      }
  
      /**
--- 85,98 ----
      private int      iFirstWildCard;
      private boolean  isNull;
      Character        escapeChar;
+     boolean          hasCollation;
      boolean          optimised;
      static final int UNDERSCORE_CHAR = 1;
      static final int PERCENT_CHAR    = 2;
  
!     Like(Character escape, boolean collation) {
!         escapeChar   = escape;
!         hasCollation = collation;
      }
  
      /**
***************
*** 143,152 ****
       *
       * @return
       */
!     boolean compare(Object o) {
  
          if (o == null) {
!             return iLen == 0;
          }
  
          String s = o.toString();
--- 145,154 ----
       *
       * @return
       */
!     Boolean compare(Session session, Object o) {
  
          if (o == null) {
!             return null;
          }
  
          String s = o.toString();
***************
*** 155,161 ****
              s = s.toUpperCase();
          }
  
!         return compareAt(s, 0, 0, s.length());
      }
  
      /**
--- 157,164 ----
              s = s.toUpperCase();
          }
  
!         return compareAt(s, 0, 0, s.length()) ? Boolean.TRUE
!                                               : Boolean.FALSE;
      }
  
      /**
*** misc/hsqldb/src/org/hsqldb/Parser.java	Wed Mar  2 14:50:53 2005
--- misc/build/hsqldb/src/org/hsqldb/Parser.java	Thu Mar 24 14:18:00 2005
***************
*** 751,757 ****
                  len--;
  
                  vcolumn.remove(current);
!             } else if (e.getType() == Expression.COLUMN) {
                  if (e.getFilter() == null) {
                      for (int f = 0; f < filters.length; f++) {
                          e.resolveTables(filters[f]);
--- 751,757 ----
                  len--;
  
                  vcolumn.remove(current);
!             } else /* if (e.getType() == Expression.COLUMN) */ {
                  if (e.getFilter() == null) {
                      for (int f = 0; f < filters.length; f++) {
                          e.resolveTables(filters[f]);
***************
*** 1281,1287 ****
              escape = new Character(s.charAt(0));
          }
  
!         a = new Expression(a, b, escape);
  
          return a;
      }
--- 1281,1289 ----
              escape = new Character(s.charAt(0));
          }
  
!         boolean hasCollation = database.collation.name != null;
! 
!         a = new Expression(a, b, escape, hasCollation);
  
          return a;
      }
***************
*** 1734,1739 ****
--- 1736,1745 ----
              tokenizer.getThis(Token.T_CLOSEBRACKET);
          }
  
+         if (t == Types.FLOAT && p > 53) {
+             throw Trace.error(Trace.NUMERIC_VALUE_OUT_OF_RANGE);
+         }
+ 
          if (r.isParam()) {
              r.setDataType(t);
          }
***************
*** 2257,2262 ****
--- 2263,2269 ----
          tokenSet.put(Token.T_VAR_POP, Expression.VAR_POP);
          tokenSet.put(Token.T_VAR_SAMP, Expression.VAR_SAMP);
          tokenSet.put(Token.T_IFNULL, Expression.IFNULL);
+         tokenSet.put(Token.T_NVL, Expression.IFNULL);
          tokenSet.put(Token.T_NULLIF, Expression.NULLIF);
          tokenSet.put(Token.T_CONVERT, Expression.CONVERT);
          tokenSet.put(Token.T_CAST, Expression.CAST);
*** misc/hsqldb/src/org/hsqldb/Result.java	Wed Mar  2 14:50:54 2005
--- misc/build/hsqldb/src/org/hsqldb/Result.java	Thu Mar 24 14:18:00 2005
***************
*** 839,846 ****
       *
       * @throws  HsqlException
       */
!     void removeDuplicates() throws HsqlException {
!         removeDuplicates(significantColumns);
      }
  
      /**
--- 839,846 ----
       *
       * @throws  HsqlException
       */
!     void removeDuplicates(Session session) throws HsqlException {
!         removeDuplicates(session, significantColumns);
      }
  
      /**
***************
*** 852,858 ****
  
  // fredt@users 20020130 - patch 1.7.0 by fredt
  // to ensure consistency of r.rTail r.iSize in all set operations
!     void removeDuplicates(int columnCount) throws HsqlException {
  
          if (rRoot == null) {
              return;
--- 852,859 ----
  
  // fredt@users 20020130 - patch 1.7.0 by fredt
  // to ensure consistency of r.rTail r.iSize in all set operations
!     void removeDuplicates(Session session,
!                           int columnCount) throws HsqlException {
  
          if (rRoot == null) {
              return;
***************
*** 866,872 ****
              way[i]   = 1;
          }
  
!         sortResult(order, way);
  
          Record n = rRoot;
  
--- 867,873 ----
              way[i]   = 1;
          }
  
!         sortResult(session, order, way);
  
          Record n = rRoot;
  
***************
*** 877,883 ****
                  break;
              }
  
!             if (compareRecord(n.data, next.data, columnCount) == 0) {
                  n.next = next.next;
  
                  size--;
--- 878,884 ----
                  break;
              }
  
!             if (compareRecord(session, n.data, next.data, columnCount) == 0) {
                  n.next = next.next;
  
                  size--;
***************
*** 896,905 ****
       * @param  minus
       * @throws  HsqlException
       */
!     void removeSecond(Result minus, int columnCount) throws HsqlException {
  
!         removeDuplicates(columnCount);
!         minus.removeDuplicates(columnCount);
  
          Record  n     = rRoot;
          Record  last  = rRoot;
--- 897,907 ----
       * @param  minus
       * @throws  HsqlException
       */
!     void removeSecond(Session session, Result minus,
!                       int columnCount) throws HsqlException {
  
!         removeDuplicates(session, columnCount);
!         minus.removeDuplicates(session, columnCount);
  
          Record  n     = rRoot;
          Record  last  = rRoot;
***************
*** 908,914 ****
          int     i     = 0;
  
          while (n != null && n2 != null) {
!             i = compareRecord(n.data, n2.data, columnCount);
  
              if (i == 0) {
                  if (rootr) {
--- 910,916 ----
          int     i     = 0;
  
          while (n != null && n2 != null) {
!             i = compareRecord(session, n.data, n2.data, columnCount);
  
              if (i == 0) {
                  if (rootr) {
***************
*** 945,954 ****
       * @param  r2
       * @throws  HsqlException
       */
!     void removeDifferent(Result r2, int columnCount) throws HsqlException {
  
!         removeDuplicates(columnCount);
!         r2.removeDuplicates(columnCount);
  
          Record  n     = rRoot;
          Record  last  = rRoot;
--- 947,957 ----
       * @param  r2
       * @throws  HsqlException
       */
!     void removeDifferent(Session session, Result r2,
!                          int columnCount) throws HsqlException {
  
!         removeDuplicates(session, columnCount);
!         r2.removeDuplicates(session, columnCount);
  
          Record  n     = rRoot;
          Record  last  = rRoot;
***************
*** 959,965 ****
          size = 0;
  
          while (n != null && n2 != null) {
!             i = compareRecord(n.data, n2.data, columnCount);
  
              if (i == 0) {             // same rows
                  if (rootr) {
--- 962,968 ----
          size = 0;
  
          while (n != null && n2 != null) {
!             i = compareRecord(session, n.data, n2.data, columnCount);
  
              if (i == 0) {             // same rows
                  if (rootr) {
***************
*** 998,1004 ****
       * @param  way
       * @throws  HsqlException
       */
!     void sortResult(final int[] order, final int[] way) throws HsqlException {
  
          if (rRoot == null || rRoot.next == null) {
              return;
--- 1001,1008 ----
       * @param  way
       * @throws  HsqlException
       */
!     void sortResult(Session session, final int[] order,
!                     final int[] way) throws HsqlException {
  
          if (rRoot == null || rRoot.next == null) {
              return;
***************
*** 1043,1050 ****
                          source0 = source0.next;
  
                          n0--;
!                     } else if (compareRecord(
!                             source0.data, source1.data, order, way) > 0) {
                          n       = source1;
                          source1 = source1.next;
  
--- 1047,1054 ----
                          source0 = source0.next;
  
                          n0--;
!                     } else if (compareRecord(session, source0.data, source1
!                             .data, order, way) > 0) {
                          n       = source1;
                          source1 = source1.next;
  
***************
*** 1082,1097 ****
       * @return -1, 0, +1
       * @throws  HsqlException
       */
!     private int compareRecord(Object[] a, final Object[] b,
                                final int[] order,
                                int[] way) throws HsqlException {
  
!         int i = Column.compare(a[order[0]], b[order[0]],
                                 metaData.colTypes[order[0]]);
  
          if (i == 0) {
              for (int j = 1; j < order.length; j++) {
!                 i = Column.compare(a[order[j]], b[order[j]],
                                     metaData.colTypes[order[j]]);
  
                  if (i != 0) {
--- 1086,1101 ----
       * @return -1, 0, +1
       * @throws  HsqlException
       */
!     private int compareRecord(Session session, Object[] a, final Object[] b,
                                final int[] order,
                                int[] way) throws HsqlException {
  
!         int i = Column.compare(session, a[order[0]], b[order[0]],
                                 metaData.colTypes[order[0]]);
  
          if (i == 0) {
              for (int j = 1; j < order.length; j++) {
!                 i = Column.compare(session, a[order[j]], b[order[j]],
                                     metaData.colTypes[order[j]]);
  
                  if (i != 0) {
***************
*** 1112,1122 ****
       * @return -1, 0, +1
       * @throws  HsqlException
       */
!     private int compareRecord(Object[] a, Object[] b,
                                int len) throws HsqlException {
  
          for (int j = 0; j < len; j++) {
!             int i = Column.compare(a[j], b[j], metaData.colTypes[j]);
  
              if (i != 0) {
                  return i;
--- 1116,1126 ----
       * @return -1, 0, +1
       * @throws  HsqlException
       */
!     private int compareRecord(Session session, Object[] a, Object[] b,
                                int len) throws HsqlException {
  
          for (int j = 0; j < len; j++) {
!             int i = Column.compare(session, a[j], b[j], metaData.colTypes[j]);
  
              if (i != 0) {
                  return i;
***************
*** 1126,1131 ****
--- 1130,1154 ----
          return 0;
      }
  
+     /**
+      * Result structure used for set/get session attributes
+      */
+     static Result newSessionAttributesResult() {
+ 
+         Result r = new Result(ResultConstants.DATA, 7);
+ 
+         r.metaData.colNames = r.metaData.colLabels = r.metaData.tableNames =
+             new String[] {
+             "", "", "", "", "", "", ""
+         };
+         r.metaData.colTypes = new int[] {
+             Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER,
+             Types.BOOLEAN, Types.BOOLEAN, Types.BOOLEAN
+         };
+ 
+         return r;
+     }
+ 
      void write(RowOutputBinary out) throws IOException, HsqlException {
  
          if (mode == ResultConstants.MULTI) {
*** misc/hsqldb/src/org/hsqldb/Row.java	Wed Mar  2 14:50:54 2005
--- misc/build/hsqldb/src/org/hsqldb/Row.java	Thu Mar 24 14:18:00 2005
***************
*** 84,89 ****
--- 84,90 ----
   */
  public class Row implements CachedObject {
  
+     int                tableId;
      int                iPos;
      protected Object[] oData;
      protected Node     nPrimaryNode;
***************
*** 110,116 ****
              n       = n.nNext;
          }
  
!         oData = o;
      }
  
      /**
--- 111,118 ----
              n       = n.nNext;
          }
  
!         tableId = t.getId();
!         oData   = o;
      }
  
      /**
***************
*** 192,197 ****
--- 194,203 ----
          return 0;
      }
  
+     public long getId() {
+         return ((long) tableId << 32) + (((long) iPos) & 0xffffffffL);
+     }
+ 
      public int getPos() {
          return iPos;
      }
*** misc/hsqldb/src/org/hsqldb/Select.java	Wed Mar  2 14:50:55 2005
--- misc/build/hsqldb/src/org/hsqldb/Select.java	Thu Mar 24 14:18:00 2005
***************
*** 306,312 ****
                                                    type);
          }
  
!         HsqlException e = Trace.error(Trace.SINGLE_VALUE_EXPECTED);
  
          if (size == 0 && len == 1) {
              throw new HsqlInternalException(e);
--- 306,313 ----
                                                    type);
          }
  
!         HsqlException e =
!             Trace.error(Trace.CARDINALITY_VIOLATION_NO_SUBCLASS);
  
          if (size == 0 && len == 1) {
              throw new HsqlInternalException(e);
***************
*** 504,510 ****
              r = getResultMain(session);
          }
  
!         sortResult(r);
  
          // fredt - now there is no need for the sort and group columns
          r.setColumnCount(iResultLen);
--- 505,511 ----
              r = getResultMain(session);
          }
  
!         sortResult(session, r);
  
          // fredt - now there is no need for the sort and group columns
          r.setColumnCount(iResultLen);
***************
*** 551,557 ****
                              break;
                          }
  
!                         unionArray[i].mergeResults(unionResults[i],
                                                     unionResults[nextIndex]);
  
                          unionResults[nextIndex] = unionResults[i];
--- 552,558 ----
                              break;
                          }
  
!                         unionArray[i].mergeResults(session, unionResults[i],
                                                     unionResults[nextIndex]);
  
                          unionResults[nextIndex] = unionResults[i];
***************
*** 568,581 ****
       * Merges the second result into the first using the unionMode
       * set operation.
       */
!     private void mergeResults(Result first,
                                Result second) throws HsqlException {
  
          switch (unionType) {
  
              case UNION :
                  first.append(second);
!                 first.removeDuplicates(iResultLen);
                  break;
  
              case UNIONALL :
--- 569,582 ----
       * Merges the second result into the first using the unionMode
       * set operation.
       */
!     private void mergeResults(Session session, Result first,
                                Result second) throws HsqlException {
  
          switch (unionType) {
  
              case UNION :
                  first.append(second);
!                 first.removeDuplicates(session, iResultLen);
                  break;
  
              case UNIONALL :
***************
*** 583,593 ****
                  break;
  
              case INTERSECT :
!                 first.removeDifferent(second, iResultLen);
                  break;
  
              case EXCEPT :
!                 first.removeSecond(second, iResultLen);
                  break;
          }
      }
--- 584,594 ----
                  break;
  
              case INTERSECT :
!                 first.removeDifferent(session, second, iResultLen);
                  break;
  
              case EXCEPT :
!                 first.removeSecond(session, second, iResultLen);
                  break;
          }
      }
***************
*** 604,610 ****
          // the result is perhaps wider (due to group and order by)
          // so use the visible columns to remove duplicates
          if (isDistinctSelect) {
!             r.removeDuplicates(iResultLen);
          }
  
          return r;
--- 605,611 ----
          // the result is perhaps wider (due to group and order by)
          // so use the visible columns to remove duplicates
          if (isDistinctSelect) {
!             r.removeDuplicates(session, iResultLen);
          }
  
          return r;
***************
*** 643,655 ****
          }
      }
  
!     private void sortResult(Result r) throws HsqlException {
  
          if (iOrderLen == 0) {
              return;
          }
  
!         r.sortResult(sortOrder, sortDirection);
      }
  
      /**
--- 644,656 ----
          }
      }
  
!     private void sortResult(Session session, Result r) throws HsqlException {
  
          if (iOrderLen == 0) {
              return;
          }
  
!         r.sortResult(session, sortOrder, sortDirection);
      }
  
      /**
*** misc/hsqldb/src/org/hsqldb/Session.java	Wed Mar  2 14:50:55 2005
--- misc/build/hsqldb/src/org/hsqldb/Session.java	Thu Mar 24 14:18:00 2005
***************
*** 107,115 ****
      private volatile boolean isAutoCommit;
      private volatile boolean isReadOnly;
      private volatile boolean isClosed;
  
      //
!     private Database       database;
      private User           user;
      HsqlArrayList          transactionList;
      private boolean        isNestedTransaction;
--- 107,116 ----
      private volatile boolean isAutoCommit;
      private volatile boolean isReadOnly;
      private volatile boolean isClosed;
+     int                      isolation;
  
      //
!     Database               database;
      private User           user;
      HsqlArrayList          transactionList;
      private boolean        isNestedTransaction;
***************
*** 118,124 ****
      private int            sessionMaxRows;
      private Number         lastIdentity = ValuePool.getInt(0);
      private final int      sessionId;
!     private HashMappedList savepoints;
      private boolean        script;
      private jdbcConnection intConnection;
      private Tokenizer      tokenizer;
--- 119,125 ----
      private int            sessionMaxRows;
      private Number         lastIdentity = ValuePool.getInt(0);
      private final int      sessionId;
!     HashMappedList         savepoints;
      private boolean        script;
      private jdbcConnection intConnection;
      private Tokenizer      tokenizer;
***************
*** 214,219 ****
--- 215,228 ----
          return isClosed;
      }
  
+     public void setIsolation(int level) throws HsqlException {
+         isolation = level;
+     }
+ 
+     public int getIsolation() throws HsqlException {
+         return isolation;
+     }
+ 
      /**
       * Setter for iLastIdentity attribute.
       *
***************
*** 349,354 ****
--- 358,364 ----
              Transaction t = new Transaction(true, table, row, sessionSCN);
  
              transactionList.add(t);
+             database.txManager.addTransaction(this, t);
          }
      }
  
***************
*** 365,370 ****
--- 375,381 ----
              Transaction t = new Transaction(false, table, row, sessionSCN);
  
              transactionList.add(t);
+             database.txManager.addTransaction(this, t);
          }
      }
  
***************
*** 410,419 ****
                  try {
                      database.logger.writeCommitStatement(this);
                  } catch (HsqlException e) {}
- 
-                 transactionList.clear();
-                 savepoints.clear();
              }
          }
      }
  
--- 421,429 ----
                  try {
                      database.logger.writeCommitStatement(this);
                  } catch (HsqlException e) {}
              }
+ 
+             database.txManager.commit(this);
          }
      }
  
***************
*** 429,451 ****
          }
  
          synchronized (database) {
!             int i = transactionList.size();
! 
!             while (i-- > 0) {
!                 Transaction t = (Transaction) transactionList.get(i);
! 
!                 t.rollback(this, false);
!             }
! 
!             if (!transactionList.isEmpty()) {
                  try {
                      database.logger.writeToLog(this, Token.T_ROLLBACK);
                  } catch (HsqlException e) {}
- 
-                 transactionList.clear();
              }
  
!             savepoints.clear();
          }
      }
  
--- 439,451 ----
          }
  
          synchronized (database) {
!             if (transactionList.size() != 0) {
                  try {
                      database.logger.writeToLog(this, Token.T_ROLLBACK);
                  } catch (HsqlException e) {}
              }
  
!             database.txManager.rollback(this);
          }
      }
  
***************
*** 475,490 ****
       */
      void rollbackToSavepoint(String name) throws HsqlException {
  
!         int index = savepoints.getIndex(name);
! 
!         Trace.check(index >= 0, Trace.SAVEPOINT_NOT_FOUND, name);
! 
!         Integer oi = (Integer) savepoints.get(index);
! 
!         index = oi.intValue();
! 
!         rollbackToSavepoint(index, false);
!         releaseSavepoint(name);
  
          try {
              database.logger.writeToLog(this,
--- 475,483 ----
       */
      void rollbackToSavepoint(String name) throws HsqlException {
  
!         if (isClosed) {
!             return;
!         }
  
          try {
              database.logger.writeToLog(this,
***************
*** 492,511 ****
                                         + " " + Token.T_SAVEPOINT + " "
                                         + name);
          } catch (HsqlException e) {}
-     }
- 
-     private void rollbackToSavepoint(int index,
-                                      boolean log) throws HsqlException {
- 
-         int i = transactionList.size() - 1;
  
!         for (; i >= index; i--) {
!             Transaction t = (Transaction) transactionList.get(i);
! 
!             t.rollback(this, log);
!         }
! 
!         transactionList.setSize(index);
      }
  
      /**
--- 485,492 ----
                                         + " " + Token.T_SAVEPOINT + " "
                                         + name);
          } catch (HsqlException e) {}
  
!         database.txManager.rollbackSavepoint(this, name);
      }
  
      /**
***************
*** 551,557 ****
          Trace.doAssert(isNestedTransaction, "endNestedTransaction");
  
          if (rollback) {
!             rollbackToSavepoint(nestedOldTransIndex, true);
          }
  
          // reset after the rollback
--- 532,539 ----
          Trace.doAssert(isNestedTransaction, "endNestedTransaction");
  
          if (rollback) {
!             database.txManager.rollbackTransactions(this,
!                     nestedOldTransIndex, true);
          }
  
          // reset after the rollback
***************
*** 1290,1318 ****
      static final int INFO_DATABASE            = 0;
      static final int INFO_USER                = 1;
      static final int INFO_SESSION_ID          = 2;
!     static final int INFO_IDENTITY            = 3;
      static final int INFO_AUTOCOMMIT          = 4;
      static final int INFO_DATABASE_READONLY   = 5;
      static final int INFO_CONNECTION_READONLY = 6;
  
      Result getAttributes() {
  
!         Result r = new Result(ResultConstants.DATA, 7);
! 
!         r.metaData.colNames = r.metaData.colLabels = r.metaData.tableNames =
!             new String[] {
!             "", "", "", "", "", "", ""
!         };
!         r.metaData.colTypes = new int[] {
!             Types.VARCHAR, Types.VARCHAR, Types.INTEGER,
!             lastIdentity instanceof Long ? Types.BIGINT
!                                          : Types.INTEGER, Types.BOOLEAN,
!             Types.BOOLEAN, Types.BOOLEAN
!         };
! 
          Object[] row = new Object[] {
              database.getURI(), getUsername(), ValuePool.getInt(sessionId),
!             lastIdentity, ValuePool.getBoolean(isAutoCommit),
              ValuePool.getBoolean(database.databaseReadOnly),
              ValuePool.getBoolean(isReadOnly)
          };
--- 1272,1288 ----
      static final int INFO_DATABASE            = 0;
      static final int INFO_USER                = 1;
      static final int INFO_SESSION_ID          = 2;
!     static final int INFO_ISOLATION           = 3;
      static final int INFO_AUTOCOMMIT          = 4;
      static final int INFO_DATABASE_READONLY   = 5;
      static final int INFO_CONNECTION_READONLY = 6;
  
      Result getAttributes() {
  
!         Result   r   = Result.newSessionAttributesResult();
          Object[] row = new Object[] {
              database.getURI(), getUsername(), ValuePool.getInt(sessionId),
!             ValuePool.getInt(isolation), ValuePool.getBoolean(isAutoCommit),
              ValuePool.getBoolean(database.databaseReadOnly),
              ValuePool.getBoolean(isReadOnly)
          };
*** misc/hsqldb/src/org/hsqldb/SessionInterface.java	Wed Mar  2 14:50:55 2005
--- misc/build/hsqldb/src/org/hsqldb/SessionInterface.java	Thu Mar 24 14:18:00 2005
***************
*** 56,61 ****
--- 56,65 ----
  
      void setAutoCommit(boolean autoCommit) throws HsqlException;
  
+     void setIsolation(int level) throws HsqlException;
+ 
+     int getIsolation() throws HsqlException;
+ 
      void commit() throws HsqlException;
  
      void rollback() throws HsqlException;
*** misc/hsqldb/src/org/hsqldb/SetFunction.java	Wed Mar  2 14:50:55 2005
--- misc/build/hsqldb/src/org/hsqldb/SetFunction.java	Thu Mar 24 14:18:00 2005
***************
*** 77,83 ****
          }
      }
  
!     void add(Object item) throws HsqlException {
  
          if (item == null) {
              hasNull = true;
--- 77,83 ----
          }
      }
  
!     void add(Session session, Object item) throws HsqlException {
  
          if (item == null) {
              hasNull = true;
***************
*** 141,147 ****
                      return;
                  }
  
!                 if (Column.compare(currentValue, item, type) > 0) {
                      currentValue = item;
                  }
  
--- 141,147 ----
                      return;
                  }
  
!                 if (Column.compare(session, currentValue, item, type) > 0) {
                      currentValue = item;
                  }
  
***************
*** 154,160 ****
                      return;
                  }
  
!                 if (Column.compare(currentValue, item, type) < 0) {
                      currentValue = item;
                  }
  
--- 154,160 ----
                      return;
                  }
  
!                 if (Column.compare(session, currentValue, item, type) < 0) {
                      currentValue = item;
                  }
  
*** misc/hsqldb/src/org/hsqldb/Table.java	Wed Mar  2 15:11:13 2005
--- misc/build/hsqldb/src/org/hsqldb/Table.java	Thu Mar 24 14:18:00 2005
***************
*** 67,74 ****
  package org.hsqldb;
  
  import java.io.IOException;
- import java.math.BigDecimal;
- import java.math.BigInteger;
  
  import org.hsqldb.HsqlNameManager.HsqlName;
  import org.hsqldb.index.RowIterator;
--- 67,72 ----
***************
*** 129,137 ****
  // boucherb@users - for future implementation of SQL standard INFORMATION_SCHEMA
      static final int SYSTEM_VIEW = 8;
  
-     // name of the column added to tables without primary key
-     static final String DEFAULT_PK = "";
- 
      // main properties
  // boucherb@users - access changed in support of metadata 1.7.2
      public HashMappedList columnList;                 // columns in table
--- 127,132 ----
***************
*** 573,578 ****
--- 568,577 ----
          return tableName;
      }
  
+     public int getId() {
+         return tableName.hashCode();
+     }
+ 
      /**
       * Changes table name. Used by 'alter table rename to'.
       * Essential to use the existing HsqlName as this is is referenced by
***************
*** 640,666 ****
  // fredt@users 20020405 - patch 1.7.0 by fredt - DROP and CREATE INDEX bug
  
      /**
-      * DROP INDEX and CREATE INDEX on non empty tables both recreate the table
-      * and the data to reflect the new indexing structure. The new structure
-      * should be reflected in the DDL script, otherwise if a
-      * SHUTDOWN IMMEDIATELY occures, the following will happen:<br>
-      *
-      * <ul>
-      * <li>If the table is cached, the index roots will be different from what
-      *     is specified in SET INDEX ROOTS. <p>
-      *
-      * <li>If the table is memory, the old index will be used until the script
-      *     reaches drop index etc. and data is recreated again. <p>
-      *
-      * <ul>
-      *
-      * The fix avoids scripting the row insert and delete ops. <p>
-      *
       * Constraints that need removing are removed outside this method.<br>
!      * withoutindex is the name of an index to be removed <br>
!      * adjust {-1 | 0 | +1} indicates if a column {removed | no change | added}
       */
!     Table moveDefinition(String withoutindex, Column newcolumn, int colindex,
                           int adjust) throws HsqlException {
  
          Table tn = duplicate();
--- 639,652 ----
  // fredt@users 20020405 - patch 1.7.0 by fredt - DROP and CREATE INDEX bug
  
      /**
       * Constraints that need removing are removed outside this method.<br>
!      * withoutindex is the name of an index to be removed, in which case
!      * no change is made to columns <br>
!      * When withoutindex is null,  adjust {-1 | 0 | +1} indicates if a
!      * column is {removed | replaced | added}
!      *
       */
!     Table moveDefinition(String withoutIndex, Column newColumn, int colIndex,
                           int adjust) throws HsqlException {
  
          Table tn = duplicate();
***************
*** 668,676 ****
          // loop beyond the end in order to be able to add a column to the end
          // of the list
          for (int i = 0; i < columnCount + 1; i++) {
!             if (i == colindex) {
!                 if (adjust > 0) {
!                     tn.addColumn(newcolumn);
                  } else if (adjust < 0) {
                      continue;
                  }
--- 654,668 ----
          // loop beyond the end in order to be able to add a column to the end
          // of the list
          for (int i = 0; i < columnCount + 1; i++) {
!             if (i == colIndex) {
!                 if (adjust == 0) {
!                     if (newColumn != null) {
!                         tn.addColumn(newColumn);
! 
!                         continue;
!                     }
!                 } else if (adjust > 0) {
!                     tn.addColumn(newColumn);
                  } else if (adjust < 0) {
                      continue;
                  }
***************
*** 689,698 ****
  
          if (primarykey != null) {
              int[] newpk = ArrayUtil.toAdjustedColumnArray(primarykey,
!                 colindex, adjust);
  
-             // fredt - we don't drop pk column
-             // although we _can_ drop single column pk wih no fk reference
              if (primarykey.length != newpk.length) {
                  throw Trace.error(Trace.DROP_PRIMARY_KEY);
              } else {
--- 681,688 ----
  
          if (primarykey != null) {
              int[] newpk = ArrayUtil.toAdjustedColumnArray(primarykey,
!                 colIndex, adjust);
  
              if (primarykey.length != newpk.length) {
                  throw Trace.error(Trace.DROP_PRIMARY_KEY);
              } else {
***************
*** 708,719 ****
          for (int i = 1; i < getIndexCount(); i++) {
              Index idx = getIndex(i);
  
!             if (withoutindex != null
!                     && idx.getName().name.equals(withoutindex)) {
                  continue;
              }
  
!             Index newidx = tn.createAdjustedIndex(idx, colindex, adjust);
  
              if (newidx == null) {
  
--- 698,709 ----
          for (int i = 1; i < getIndexCount(); i++) {
              Index idx = getIndex(i);
  
!             if (withoutIndex != null
!                     && idx.getName().name.equals(withoutIndex)) {
                  continue;
              }
  
!             Index newidx = tn.createAdjustedIndex(idx, colIndex, adjust);
  
              if (newidx == null) {
  
***************
*** 832,837 ****
--- 822,844 ----
      }
  
      /**
+      * Used for retype column. Checks whether column is in an FK or is
+      * referenced by an FK
+      */
+     void checkColumnInFKConstraint(String colname) throws HsqlException {
+ 
+         int colIndex = getColumnNr(colname);
+ 
+         for (int i = 0, size = constraintList.length; i < size; i++) {
+             Constraint c = constraintList[i];
+ 
+             if (c.hasColumn(colIndex)) {
+                 throw Trace.error(Trace.COLUMN_IS_REFERENCED, c.getName());
+             }
+         }
+     }
+ 
+     /**
       * Used for rename column.
       */
      private void renameColumnInCheckConstraints(String oldname,
***************
*** 1327,1341 ****
  
          // tony_lai@users 20020820 - patch 595099
          HsqlName name = pkName != null ? pkName
!                                        : makeSysPKName(this);
  
          createPrimaryIndex(columns, name);
          setBestRowIdentifiers();
      }
  
!     static HsqlName makeSysPKName(Table table) throws HsqlException {
!         return table.database.nameManager.newHsqlName("SYS_PK",
!                 table.tableName.name, table.tableName.isNameQuoted);
      }
  
      void createPrimaryIndex(int[] pkcols,
--- 1334,1350 ----
  
          // tony_lai@users 20020820 - patch 595099
          HsqlName name = pkName != null ? pkName
!                                        : makeSysPKName();
  
          createPrimaryIndex(columns, name);
          setBestRowIdentifiers();
      }
  
!     HsqlName makeSysPKName() throws HsqlException {
! 
!         return isTemp ? database.nameManager.newAutoName("PK")
!                       : database.nameManager.newHsqlName("SYS_PK",
!                       tableName.name, tableName.isNameQuoted);
      }
  
      void createPrimaryIndex(int[] pkcols,
***************
*** 1386,1392 ****
              constraint, forward);
          Index       newindex     = indexList[newindexNo];
          Index       primaryindex = getPrimaryIndex();
!         RowIterator it           = primaryindex.firstRow(null);
          int         rowCount     = 0;
          int         error        = 0;
  
--- 1395,1402 ----
              constraint, forward);
          Index       newindex     = indexList[newindexNo];
          Index       primaryindex = getPrimaryIndex();
!         Session     session      = database.sessionManager.getSysSession();
!         RowIterator it           = primaryindex.firstRow(session);
          int         rowCount     = 0;
          int         error        = 0;
  
***************
*** 1402,1408 ****
                  // count before inserting
                  rowCount++;
  
!                 newindex.insert(row, newindexNo);
              }
  
              return newindex;
--- 1412,1418 ----
                  // count before inserting
                  rowCount++;
  
!                 newindex.insert(session, row, newindexNo);
              }
  
              return newindex;
***************
*** 1414,1420 ****
  
          // backtrack on error
          // rowCount rows have been modified
!         it = primaryindex.firstRow(null);
  
          for (int i = 0; i < rowCount; i++) {
              Row  row      = it.next();
--- 1424,1430 ----
  
          // backtrack on error
          // rowCount rows have been modified
!         it = primaryindex.firstRow(session);
  
          for (int i = 0; i < rowCount; i++) {
              Row  row      = it.next();
***************
*** 1653,1662 ****
                    int adjust) throws HsqlException {
  
          Object colvalue = null;
  
!         if (adjust > 0) {
!             Column column = getColumn(colindex);
! 
              colvalue = column.getDefaultValue(session);
          }
  
--- 1663,1672 ----
                    int adjust) throws HsqlException {
  
          Object colvalue = null;
+         Column column   = null;
  
!         if (adjust >= 0 && colindex != -1) {
!             column   = getColumn(colindex);
              colvalue = column.getDefaultValue(session);
          }
  
***************
*** 1667,1679 ****
              Object[] o    = row.getData();
              Object[] data = getEmptyRowData();
  
              ArrayUtil.copyAdjustArray(o, data, colvalue, colindex, adjust);
              updateIdentityValue(data);
              enforceNullConstraints(data);
  
              Row newrow = newRow(data);
  
!             indexRow(newrow);
          }
  
          from.drop();
--- 1677,1696 ----
              Object[] o    = row.getData();
              Object[] data = getEmptyRowData();
  
+             if (adjust == 0 && colindex != -1) {
+                 colvalue = Column.convertObject(o[colindex],
+                                                 column.getType(),
+                                                 column.getSize(),
+                                                 column.getScale());
+             }
+ 
              ArrayUtil.copyAdjustArray(o, data, colvalue, colindex, adjust);
              updateIdentityValue(data);
              enforceNullConstraints(data);
  
              Row newrow = newRow(data);
  
!             indexRow(session, newrow);
          }
  
          from.drop();
***************
*** 1746,1752 ****
      void insertIntoTable(Session session,
                           Result result) throws HsqlException {
  
!         insert(result);
  
          if (isTemp || isText ||!database.logger.hasLog()) {
              return;
--- 1763,1769 ----
      void insertIntoTable(Session session,
                           Result result) throws HsqlException {
  
!         insertResult(session, result);
  
          if (isTemp || isText ||!database.logger.hasLog()) {
              return;
***************
*** 1772,1778 ****
          Row r = newRow(data);
  
          // this handles the UNIQUE constraints
!         indexRow(r);
  
          if (session != null) {
              session.addTransactionInsert(this, r);
--- 1789,1795 ----
          Row r = newRow(data);
  
          // this handles the UNIQUE constraints
!         indexRow(session, r);
  
          if (session != null) {
              session.addTransactionInsert(this, r);
***************
*** 1794,1800 ****
          Row r = newRow(data);
  
          updateIdentityValue(data);
!         indexRow(r);
  
          if (session != null) {
              session.addTransactionInsert(this, r);
--- 1811,1817 ----
          Row r = newRow(data);
  
          updateIdentityValue(data);
!         indexRow(session, r);
  
          if (session != null) {
              session.addTransactionInsert(this, r);
***************
*** 1811,1817 ****
  
          row = newRow(row.getData());
  
!         indexRow(row);
  
          if (log &&!isTemp &&!isText &&!isReadOnly) {
              database.logger.writeInsertStatement(session, this,
--- 1828,1834 ----
  
          row = newRow(row.getData());
  
!         indexRow(session, row);
  
          if (log &&!isTemp &&!isText &&!isReadOnly) {
              database.logger.writeInsertStatement(session, this,
***************
*** 1820,1835 ****
      }
  
      /**
!      * Used for subquery and system table inserts. No checks. No identity
       * columns.
       */
!     int insert(Result ins) throws HsqlException {
  
          Record ni    = ins.rRoot;
          int    count = 0;
  
          while (ni != null) {
!             insert(ni.data);
  
              ni = ni.next;
  
--- 1837,1873 ----
      }
  
      /**
!      * Used for system table inserts. No checks. No identity
!      * columns.
!      */
!     int insertSys(Result ins) throws HsqlException {
! 
!         Session session = database.sessionManager.getSysSession();
!         Record  ni      = ins.rRoot;
!         int     count   = 0;
! 
!         while (ni != null) {
!             insertData(session, ni.data);
! 
!             ni = ni.next;
! 
!             count++;
!         }
! 
!         return count;
!     }
! 
!     /**
!      * Used for subquery inserts. No checks. No identity
       * columns.
       */
!     int insertResult(Session session, Result ins) throws HsqlException {
  
          Record ni    = ins.rRoot;
          int    count = 0;
  
          while (ni != null) {
!             insertData(session, ni.data);
  
              ni = ni.next;
  
***************
*** 1845,1872 ****
       * the table when the .script file is read.
       */
      public void insertFromScript(Object[] data) throws HsqlException {
          updateIdentityValue(data);
!         insert(data);
      }
  
      /**
!      * Used by the methods above. To avoid unnecessary
!      * creation of arrays The Object[] for data in the Result rows is inserted
!      * into the table if it has the same length as table row data.
       */
!     public void insert(Object[] data) throws HsqlException {
  
!         if (data.length != columnCount) {
!             Object[] newdata = getEmptyRowData();
  
!             ArrayUtil.copyArray(data, newdata, columnCount);
  
!             data = newdata;
!         }
  
!         Row r = newRow(data);
  
!         indexRow(r);
      }
  
      /**
--- 1883,1915 ----
       * the table when the .script file is read.
       */
      public void insertFromScript(Object[] data) throws HsqlException {
+ 
+         Session session = database.sessionManager.getSysSession();
+ 
          updateIdentityValue(data);
!         insertData(session, data);
      }
  
      /**
!      * Used by the methods above.
       */
!     public void insertData(Session session,
!                            Object[] data) throws HsqlException {
  
!         Row r = newRow(data);
  
!         indexRow(session, r);
!     }
  
!     /**
!      * Used by the system tables
!      */
!     public void insertSys(Object[] data) throws HsqlException {
  
!         Session session = database.sessionManager.getSysSession();
!         Row     r       = newRow(data);
  
!         indexRow(session, r);
      }
  
      /**
***************
*** 1875,1886 ****
       */
      protected void insertNoChange(CachedRow row) throws HsqlException {
  
!         Object[] data = row.getData();
  
          updateIdentityValue(data);
          enforceFieldValueLimits(data, defaultColumnMap);
          enforceNullConstraints(data);
!         indexRow(row);
      }
  
      /**
--- 1918,1930 ----
       */
      protected void insertNoChange(CachedRow row) throws HsqlException {
  
!         Session  session = database.sessionManager.getSysSession();
!         Object[] data    = row.getData();
  
          updateIdentityValue(data);
          enforceFieldValueLimits(data, defaultColumnMap);
          enforceNullConstraints(data);
!         indexRow(session, row);
      }
  
      /**
***************
*** 2195,2201 ****
  
                  if (refrow == null || refrow.isDeleted()
                          || refindex.compareRowNonUnique(
!                             mdata, m_columns, refrow.getData()) != 0) {
                      break;
                  }
  
--- 2239,2246 ----
  
                  if (refrow == null || refrow.isDeleted()
                          || refindex.compareRowNonUnique(
!                             session, mdata, m_columns,
!                             refrow.getData()) != 0) {
                      break;
                  }
  
***************
*** 2400,2406 ****
                          refrow = refiterator.next()) {
                      if (refrow == null
                              || refindex.compareRowNonUnique(
!                                 orow.getData(), m_columns,
                                  refrow.getData()) != 0) {
                          break;
                      }
--- 2445,2451 ----
                          refrow = refiterator.next()) {
                      if (refrow == null
                              || refindex.compareRowNonUnique(
!                                 session, orow.getData(), m_columns,
                                  refrow.getData()) != 0) {
                          break;
                      }
***************
*** 2480,2495 ****
       * Merge the full triggered change with the updated row, or add to list.
       * Return false if changes conflict.
       */
!     static boolean mergeKeepUpdate(HashMappedList rowSet, int[] cols,
!                                    int[] colTypes, Row row,
                                     Object[] newData) throws HsqlException {
  
          Object[] data = (Object[]) rowSet.get(row);
  
          if (data != null) {
!             if (Index.compareRows(row
!                     .getData(), newData, cols, colTypes) != 0 && Index
!                         .compareRows(newData, data, cols, colTypes) != 0) {
                  return false;
              }
  
--- 2525,2542 ----
       * Merge the full triggered change with the updated row, or add to list.
       * Return false if changes conflict.
       */
!     static boolean mergeKeepUpdate(Session session, HashMappedList rowSet,
!                                    int[] cols, int[] colTypes, Row row,
                                     Object[] newData) throws HsqlException {
  
          Object[] data = (Object[]) rowSet.get(row);
  
          if (data != null) {
!             if (Index.compareRows(
!                     session, row
!                         .getData(), newData, cols, colTypes) != 0 && Index
!                             .compareRows(
!                                 session, newData, data, cols, colTypes) != 0) {
                  return false;
              }
  
***************
*** 2543,2548 ****
--- 2590,2606 ----
              }
          }
  
+         // check transactions
+         database.txManager.checkDelete(session, deleteList);
+ 
+         for (int i = 0; i < tUpdateList.size(); i++) {
+             Table          table      = (Table) tUpdateList.getKey(i);
+             HashMappedList updateList = (HashMappedList) tUpdateList.get(i);
+ 
+             database.txManager.checkDelete(session, updateList);
+         }
+ 
+         // perform delete
          fireAll(session, Trigger.DELETE_BEFORE);
  
          if (database.isReferentialIntegrity()) {
***************
*** 2652,2658 ****
                  }
  
                  if (Index.compareRows(
!                         row.getData(), data, defaultColumnMap,
                          colTypes) == 0) {
                      break;
                  }
--- 2710,2716 ----
                  }
  
                  if (Index.compareRows(
!                         session, row.getData(), data, defaultColumnMap,
                          colTypes) == 0) {
                      break;
                  }
***************
*** 2671,2684 ****
  
                  // reached end of range
                  if (bestIndex.compareRowNonUnique(
!                         data, bestIndex.getColumns(), rowdata) != 0) {
                      row = null;
  
                      break;
                  }
  
                  if (Index.compareRows(
!                         rowdata, data, defaultColumnMap, colTypes) == 0) {
                      break;
                  }
              }
--- 2729,2744 ----
  
                  // reached end of range
                  if (bestIndex.compareRowNonUnique(
!                         session, data, bestIndex.getColumns(),
!                         rowdata) != 0) {
                      row = null;
  
                      break;
                  }
  
                  if (Index.compareRows(
!                         session, rowdata, data, defaultColumnMap,
!                         colTypes) == 0) {
                      break;
                  }
              }
***************
*** 2688,2693 ****
--- 2748,2756 ----
              return;
          }
  
+         // not necessary for log deletes
+         database.txManager.checkDelete(session, row);
+ 
          for (int i = indexList.length - 1; i >= 0; i--) {
              Node node = row.getNode(i);
  
***************
*** 2708,2715 ****
      void deleteNoCheckRollback(Session session, Row row,
                                 boolean log) throws HsqlException {
  
-         // the orininal row may have been deleted by another transaction
-         // so we do not use it directly
          row = getIndex(0).findRow(session, row);
  
          for (int i = indexList.length - 1; i >= 0; i--) {
--- 2771,2776 ----
***************
*** 2798,2809 ****
                  Row      row  = (Row) triggeredList.getKey(i);
                  Object[] data = (Object[]) triggeredList.get(i);
  
!                 mergeKeepUpdate(updateList, cols, colTypes, row, data);
              }
  
              triggeredList.clear();
          }
  
          for (int i = 0; i < tUpdateList.size(); i++) {
              Table          table       = (Table) tUpdateList.getKey(i);
              HashMappedList updateListT = (HashMappedList) tUpdateList.get(i);
--- 2859,2882 ----
                  Row      row  = (Row) triggeredList.getKey(i);
                  Object[] data = (Object[]) triggeredList.get(i);
  
!                 mergeKeepUpdate(session, updateList, cols, colTypes, row,
!                                 data);
              }
  
              triggeredList.clear();
          }
  
+         // check transactions
+         for (int i = 0; i < tUpdateList.size(); i++) {
+             Table          table       = (Table) tUpdateList.getKey(i);
+             HashMappedList updateListT = (HashMappedList) tUpdateList.get(i);
+ 
+             database.txManager.checkDelete(session, updateListT);
+         }
+ 
+         database.txManager.checkDelete(session, updateList);
+ 
+         // update lists - main list last
          for (int i = 0; i < tUpdateList.size(); i++) {
              Table          table       = (Table) tUpdateList.getKey(i);
              HashMappedList updateListT = (HashMappedList) tUpdateList.get(i);
***************
*** 2812,2818 ****
              updateListT.clear();
          }
  
-         // update main list
          updateRowSet(session, updateList, cols, true);
          fireAll(session, Trigger.UPDATE_AFTER);
          path.clear();
--- 2885,2890 ----
***************
*** 3034,3050 ****
  
      void registerRow(CachedRow row) {}
  
      void removeRow(CachedRow row) throws HsqlException {
          rowStore.remove(row.getPos());
      }
  
!     void indexRow(Row row) throws HsqlException {
  
          int i = 0;
  
          try {
!             for (; i < getIndexCount(); i++) {
!                 indexList[i].insert(row, i);
              }
          } catch (HsqlException e) {
              Index   index        = indexList[i];
--- 3106,3124 ----
  
      void registerRow(CachedRow row) {}
  
+     /**
+      */
      void removeRow(CachedRow row) throws HsqlException {
          rowStore.remove(row.getPos());
      }
  
!     void indexRow(Session session, Row row) throws HsqlException {
  
          int i = 0;
  
          try {
!             for (; i < indexList.length; i++) {
!                 indexList[i].insert(session, row, i);
              }
          } catch (HsqlException e) {
              Index   index        = indexList[i];
***************
*** 3161,3169 ****
              return;
          }
  
          rowIdSequence = new NumberSequence(null, 0, 1, Types.BIGINT);
  
!         RowIterator it = rowIterator(null);
  
          while (it.hasNext()) {
              Row row = it.next();
--- 3235,3245 ----
              return;
          }
  
+         Session session = database.sessionManager.getSysSession();
+ 
          rowIdSequence = new NumberSequence(null, 0, 1, Types.BIGINT);
  
!         RowIterator it = rowIterator(session);
  
          while (it.hasNext()) {
              Row row = it.next();
*** misc/hsqldb/src/org/hsqldb/TableFilter.java	Wed Mar  2 14:50:56 2005
--- misc/build/hsqldb/src/org/hsqldb/TableFilter.java	Thu Mar 24 14:18:00 2005
***************
*** 328,333 ****
--- 328,341 ----
              return;
          }
  
+         if (type == Expression.OR && isOuterJoin && e.isInJoin
+                 && e.outerFilter == this) {
+             addAndCondition(e);
+             e.setTrue();
+ 
+             return;
+         }
+ 
          int conditionType = toConditionType(type);
  
          if (conditionType == CONDITION_NONE) {
***************
*** 472,478 ****
                  Expression e = findFirstExpressions[i];
  
                  if (e != null) {
!                     data[i] = e.getValue(null, types[i]);
                  }
              }
  
--- 480,486 ----
                  Expression e = findFirstExpressions[i];
  
                  if (e != null) {
!                     data[i] = e.getValue(session, types[i]);
                  }
              }
  
*** misc/hsqldb/src/org/hsqldb/TableWorks.java	Wed Mar  2 14:50:56 2005
--- misc/build/hsqldb/src/org/hsqldb/TableWorks.java	Thu Mar 24 14:18:01 2005
***************
*** 33,38 ****
--- 33,39 ----
  
  import org.hsqldb.lib.ArrayUtil;
  import org.hsqldb.lib.HashSet;
+ import org.hsqldb.index.RowIterator;
  import org.hsqldb.HsqlNameManager.HsqlName;
  
  // fredt@users 20020520 - patch 1.7.0 - ALTER TABLE support
***************
*** 139,145 ****
          }
  
          // existing rows, value checks
!         Constraint.checkReferencedRows(table, fkcol, exportindex);
  
          // create
          HsqlName iname   = table.database.nameManager.newAutoName("IDX");
--- 140,146 ----
          }
  
          // existing rows, value checks
!         Constraint.checkReferencedRows(session, table, fkcol, exportindex);
  
          // create
          HsqlName iname   = table.database.nameManager.newAutoName("IDX");
***************
*** 195,208 ****
              newindex = table.createIndex(col, name, unique, constraint,
                                           forward);
          } else {
!             Table tn = table.moveDefinition(null, null,
!                                             table.getColumnCount(), 0);
  
              newindex = tn.createIndexStructure(col, name, unique, constraint,
                                                 forward);
  
!             tn.moveData(session, table, table.getColumnCount(), 0);
!             tn.updateConstraintsTables(table, table.getColumnCount(), 0);
  
              int index = table.database.getTableIndex(table);
  
--- 196,208 ----
              newindex = table.createIndex(col, name, unique, constraint,
                                           forward);
          } else {
!             Table tn = table.moveDefinition(null, null, -1, 0);
  
              newindex = tn.createIndexStructure(col, name, unique, constraint,
                                                 forward);
  
!             tn.moveData(session, table, -1, 0);
!             tn.updateConstraintsTables(table, -1, 0);
  
              int index = table.database.getTableIndex(table);
  
***************
*** 221,226 ****
--- 221,230 ----
  
      void addPrimaryKey(int[] cols, HsqlName name) throws HsqlException {
  
+         if (name == null) {
+             name = table.makeSysPKName();
+         }
+ 
          if (table.database.constraintNameList.containsName(name.name)) {
              throw Trace.error(Trace.CONSTRAINT_ALREADY_EXISTS, name.name);
          }
***************
*** 239,246 ****
  
          Table tn = table.moveDefinitionPK(name, cols);
  
!         tn.moveData(session, table, table.getColumnCount(), 0);
!         tn.updateConstraintsTables(table, table.getColumnCount(), 0);
  
          int index = table.database.getTableIndex(table);
  
--- 243,250 ----
  
          Table tn = table.moveDefinitionPK(name, cols);
  
!         tn.moveData(session, table, -1, 0);
!         tn.updateConstraintsTables(table, -1, 0);
  
          int index = table.database.getTableIndex(table);
  
***************
*** 348,358 ****
          if (table.isIndexingMutable()) {
              table.dropIndex(indexname);
          } else {
!             Table tn = table.moveDefinition(indexname, null,
!                                             table.getColumnCount(), 0);
  
!             tn.moveData(session, table, table.getColumnCount(), 0);
!             tn.updateConstraintsTables(table, table.getColumnCount(), 0);
  
              int i = table.database.getTableIndex(table);
  
--- 352,361 ----
          if (table.isIndexingMutable()) {
              table.dropIndex(indexname);
          } else {
!             Table tn = table.moveDefinition(indexname, null, -1, 0);
  
!             tn.moveData(session, table, -1, 0);
!             tn.updateConstraintsTables(table, -1, 0);
  
              int i = table.database.getTableIndex(table);
  
***************
*** 367,385 ****
  
      /**
       *
!      * @param  column
       * @param  colindex
!      * @param  adjust +1 or -1
       * @throws  HsqlException
       */
!     void addOrDropColumn(Column column, int colindex,
!                          int adjust) throws HsqlException {
  
          if (table.isText()) {
              throw Trace.error(Trace.OPERATION_NOT_SUPPORTED);
          }
  
!         if (adjust == -1) {
              table.database.checkColumnIsInView(
                  table.getName().name,
                  table.getColumn(colindex).columnName.name);
--- 370,388 ----
  
      /**
       *
!      * @param  column is null if adjust is -1
       * @param  colindex
!      * @param  adjust +1, 0 -1
       * @throws  HsqlException
       */
!     void addDropRetypeColumn(Column column, int colindex,
!                              int adjust) throws HsqlException {
  
          if (table.isText()) {
              throw Trace.error(Trace.OPERATION_NOT_SUPPORTED);
          }
  
!         if (adjust == -1 || adjust == 0) {
              table.database.checkColumnIsInView(
                  table.getName().name,
                  table.getColumn(colindex).columnName.name);
***************
*** 467,470 ****
--- 470,593 ----
  
          table.database.constraintNameList.removeName(name);
      }
+ 
+     void reTypeColumn(Column oldCol, Column newCol) throws HsqlException {
+ 
+         boolean notallowed = false;
+         int     oldtype    = oldCol.getType();
+         int     newtype    = newCol.getType();
+ 
+         switch (newtype) {
+ 
+             case Types.BINARY :
+             case Types.VARBINARY :
+             case Types.LONGVARBINARY :
+             case Types.OTHER :
+             case Types.JAVA_OBJECT :
+                 notallowed = !table.isEmpty();
+         }
+ 
+         switch (oldtype) {
+ 
+             case Types.BINARY :
+             case Types.VARBINARY :
+             case Types.LONGVARBINARY :
+             case Types.OTHER :
+             case Types.JAVA_OBJECT :
+                 notallowed = !table.isEmpty();
+                 break;
+ 
+             case Types.TINYINT :
+             case Types.SMALLINT :
+             case Types.INTEGER :
+             case Types.BIGINT :
+             case Types.REAL :
+             case Types.FLOAT :
+             case Types.DOUBLE :
+             case Types.NUMERIC :
+             case Types.DECIMAL :
+                 switch (newtype) {
+ 
+                     case Types.DATE :
+                     case Types.TIME :
+                     case Types.TIMESTAMP :
+                         notallowed = !table.isEmpty();
+                     default :
+                 }
+                 break;
+ 
+             case Types.DATE :
+             case Types.TIME :
+             case Types.TIMESTAMP :
+                 switch (newtype) {
+ 
+                     case Types.TINYINT :
+                     case Types.SMALLINT :
+                     case Types.INTEGER :
+                     case Types.BIGINT :
+                     case Types.REAL :
+                     case Types.FLOAT :
+                     case Types.DOUBLE :
+                     case Types.NUMERIC :
+                     case Types.DECIMAL :
+                         notallowed = !table.isEmpty();
+                     default :
+                 }
+                 break;
+         }
+ 
+         if (notallowed) {
+             throw Trace.error(Trace.INVALID_CONVERSION);
+         }
+ 
+         int colindex = table.getColumnNr(oldCol.columnName.name);
+ 
+         if (table.getPrimaryKey().length > 1) {
+ 
+             // if there is a multi-column PK, do not change the PK attributes
+             if (newCol.isIdentity()) {
+                 throw Trace.error(Trace.SECOND_PRIMARY_KEY);
+             }
+ 
+             newCol.setPrimaryKey(oldCol.isPrimaryKey());
+ 
+             if (ArrayUtil.find(table.getPrimaryKey(), colindex) != -1) {
+                 newCol.setNullable(false);
+             }
+         } else if (table.hasPrimaryKey()) {
+             if (oldCol.isPrimaryKey()) {
+                 newCol.setPrimaryKey(true);
+                 newCol.setNullable(false);
+             } else if (newCol.isPrimaryKey()) {
+                 throw Trace.error(Trace.SECOND_PRIMARY_KEY);
+             }
+         } else if (newCol.isPrimaryKey()) {
+ 
+             // use a better error message
+             throw Trace.error(Trace.SECOND_PRIMARY_KEY);
+         }
+ 
+         table.database.checkColumnIsInView(
+             table.getName().name, table.getColumn(colindex).columnName.name);
+         table.checkColumnInCheckConstraint(
+             table.getColumn(colindex).columnName.name);
+         table.checkColumnInFKConstraint(oldCol.columnName.name);
+         checkConvertColDataType(oldCol, newCol);
+         addDropRetypeColumn(newCol, colindex, 0);
+     }
+ 
+     void checkConvertColDataType(Column oldCol,
+                                  Column newCol) throws HsqlException {
+ 
+         int         colindex = table.getColumnNr(oldCol.columnName.name);
+         RowIterator it       = table.rowIterator(null);
+ 
+         while (it.hasNext()) {
+             Row    row = it.next();
+             Object o   = row.getData()[colindex];
+ 
+             Column.convertObject(o, newCol.getType(), newCol.getSize(),
+                                  newCol.getScale());
+         }
+     }
  }
*** misc/hsqldb/src/org/hsqldb/Token.java	Wed Mar  2 14:50:57 2005
--- misc/build/hsqldb/src/org/hsqldb/Token.java	Thu Mar 24 14:18:01 2005
***************
*** 338,348 ****
--- 338,350 ----
      static final String        T_CHECKPOINT     = "CHECKPOINT";
      static final String        T_CLASS          = "CLASS";
      static final String        T_COALESCE       = "COALESCE";
+     static final String        T_COLLATION      = "COLLATION";
      static final String        T_COMPACT        = "COMPACT";
      public static final String T_COMPRESSED     = "COMPRESSED";
      static final String        T_CONCAT         = "CONCAT";
      static final String        T_CONVERT        = "CONVERT";
      static final String        T_COUNT          = "COUNT";
+     static final String        T_DATABASE       = "DATABASE";
      static final String        T_DEFRAG         = "DEFRAG";
      static final String        T_DESC           = "DESC";
      static final String        T_EVERY          = "EVERY";
***************
*** 366,371 ****
--- 368,374 ----
      static final String        T_NOW            = "NOW";
      static final String        T_NOWAIT         = "NOWAIT";
      static final String        T_NULLIF         = "NULLIF";
+     static final String        T_NVL            = "NVL";
      static final String        T_PASSWORD       = "PASSWORD";
      static final String        T_PLAN           = "PLAN";
      static final String        T_POSITION       = "POSITION";
***************
*** 687,692 ****
--- 690,697 ----
      static final int STDDEV_SAMP = 333;
      static final int DEFRAG      = 334;
      static final int INCREMENT   = 335;
+     static final int TOCHAR      = 336;
+     static final int DATABASE    = 337;
  
      //
      static {
***************
*** 718,723 ****
--- 723,729 ----
          commandSet.put(T_CONNECT, CONNECT);
          commandSet.put(T_CONSTRAINT, CONSTRAINT);
          commandSet.put(T_CREATE, CREATE);
+         commandSet.put(T_DATABASE, DATABASE);
          commandSet.put(T_DELETE, DELETE);
          commandSet.put(T_DEFRAG, DEFRAG);
          commandSet.put(T_DISCONNECT, DISCONNECT);
***************
*** 807,813 ****
              Token.T_IS, Token.T_IN, Token.T_INTERSECT, Token.T_JOIN,
              Token.T_INNER, Token.T_LEADING, Token.T_LIKE, Token.T_MAX,
              Token.T_MIN, Token.T_NEXT, Token.T_NULLIF, Token.T_NOT,
!             Token.T_MINUS, Token.T_ON, Token.T_ORDER, Token.T_OR,
              Token.T_OUTER, Token.T_POSITION, Token.T_PRIMARY, Token.T_SELECT,
              Token.T_SET, Token.T_SOME, Token.T_STDDEV_POP,
              Token.T_STDDEV_SAMP, Token.T_SUBSTRING, Token.T_SUM, Token.T_THEN,
--- 813,819 ----
              Token.T_IS, Token.T_IN, Token.T_INTERSECT, Token.T_JOIN,
              Token.T_INNER, Token.T_LEADING, Token.T_LIKE, Token.T_MAX,
              Token.T_MIN, Token.T_NEXT, Token.T_NULLIF, Token.T_NOT,
!             Token.T_NVL, Token.T_MINUS, Token.T_ON, Token.T_ORDER, Token.T_OR,
              Token.T_OUTER, Token.T_POSITION, Token.T_PRIMARY, Token.T_SELECT,
              Token.T_SET, Token.T_SOME, Token.T_STDDEV_POP,
              Token.T_STDDEV_SAMP, Token.T_SUBSTRING, Token.T_SUM, Token.T_THEN,
*** misc/hsqldb/src/org/hsqldb/Trace.java	Wed Mar  2 14:50:57 2005
--- misc/build/hsqldb/src/org/hsqldb/Trace.java	Thu Mar 24 14:18:01 2005
***************
*** 117,123 ****
                              NEED_AGGREGATE                            = 14,
                              SUM_OF_NON_NUMERIC                        = 15,
                              WRONG_DATA_TYPE                           = 16,
!                             SINGLE_VALUE_EXPECTED                     = 17,
                              SERIALIZATION_FAILURE                     = 18,
                              TRANSFER_CORRUPTED                        = 19,
                              FUNCTION_NOT_SUPPORTED                    = 20,
--- 117,123 ----
                              NEED_AGGREGATE                            = 14,
                              SUM_OF_NON_NUMERIC                        = 15,
                              WRONG_DATA_TYPE                           = 16,
!                             CARDINALITY_VIOLATION_NO_SUBCLASS         = 17,
                              SERIALIZATION_FAILURE                     = 18,
                              TRANSFER_CORRUPTED                        = 19,
                              FUNCTION_NOT_SUPPORTED                    = 20,
***************
*** 217,228 ****
                              DatabaseScriptReader_readExistingData     = 114,
                              Message_Pair                              = 115,
                              HsqlDatabaseProperties                    = 116,
!                             not_used                                  = 117,
                              JDBC_INVALID_BRI_SCOPE                    = 118,
                              JDBC_NO_RESULT_SET_METADATA               = 119,
                              JDBC_NO_RESULT_SET                        = 120,
                              MISSING_CLOSEBRACKET                      = 121,
!                             TableFilter_findFirst                     = 122,
                              Table_moveDefinition                      = 123,
                              STRING_DATA_TRUNCATION                    = 124,
                              QUOTED_IDENTIFIER_REQUIRED                = 125,
--- 217,228 ----
                              DatabaseScriptReader_readExistingData     = 114,
                              Message_Pair                              = 115,
                              HsqlDatabaseProperties                    = 116,
!                             INVALID_TRANSACTION_STATE_NO_SUBCLASS     = 117,
                              JDBC_INVALID_BRI_SCOPE                    = 118,
                              JDBC_NO_RESULT_SET_METADATA               = 119,
                              JDBC_NO_RESULT_SET                        = 120,
                              MISSING_CLOSEBRACKET                      = 121,
!                             ITSNS_OVERWRITE                           = 122,
                              Table_moveDefinition                      = 123,
                              STRING_DATA_TRUNCATION                    = 124,
                              QUOTED_IDENTIFIER_REQUIRED                = 125,
***************
*** 308,314 ****
                              CREATE_TRIGGER_COMMAND_2                  = 205,
                              BAD_SAVEPOINT_NAME                        = 206,
                              DataFileCache_defrag                      = 207,
!                             DataFileCache_closeFile                   = 208,
                              DataFileCache_makeRow                     = 209,
                              DataFileCache_open                        = 210,
                              DataFileCache_close                       = 211,
--- 308,314 ----
                              CREATE_TRIGGER_COMMAND_2                  = 205,
                              BAD_SAVEPOINT_NAME                        = 206,
                              DataFileCache_defrag                      = 207,
!                             INVALID_COLLATION_NAME_NO_SUBCLASS        = 208,
                              DataFileCache_makeRow                     = 209,
                              DataFileCache_open                        = 210,
                              DataFileCache_close                       = 211,
***************
*** 350,356 ****
          "37000 Need aggregate function or group by",                    //
          "37000 Sum on non-numeric data not allowed",                    //
          "37000 Wrong data type",                                        //
!         "37000 Single value expected",                                  //
          "40001 Serialization failure",                                  //
          "40001 Transfer corrupted",                                     //
          "IM001 This function is not supported",                         //
--- 350,356 ----
          "37000 Need aggregate function or group by",                    //
          "37000 Sum on non-numeric data not allowed",                    //
          "37000 Wrong data type",                                        //
!         "21000 Single value expected",                                  //
          "40001 Serialization failure",                                  //
          "40001 Transfer corrupted",                                     //
          "IM001 This function is not supported",                         //
***************
*** 450,461 ****
          " line: $$ $$",                                                 // DatabaseScriptReader_readExistingData
          " $$ $$",                                                       // Function_Function
          " $$.properties $$",                                            // HsqlDatabaseProperties_load
!         "",                                                             // unused
          "invalid scope value",                                          // jdbcDatabaseMetaData_getBestRowIdentifier
          "result set is null",                                           // jdbcResultSetMetaData_jdbcResultSetMetaData
          "result set is closed",                                         // jdbcResultSetMetaData_jdbcResultSetMetaData_2
          "37000 missing )",                                              // MISSING_CLOSEBRACKET
!         "37000 an index is required on table $$, column $$",            // TableFilter_findFirst
          "37000 there is an index on the column to be removed",          // Table_moveDefinition
          "22001 string too long",                                        //
          "00000 quoted identifier required",                             // SET PROPERTY "name" "value"
--- 450,461 ----
          " line: $$ $$",                                                 // DatabaseScriptReader_readExistingData
          " $$ $$",                                                       // Function_Function
          " $$.properties $$",                                            // HsqlDatabaseProperties_load
!         "25000 invalid transaction state",                              // INVALID_TRANSACTION_STATE_NO_SUBCLASS
          "invalid scope value",                                          // jdbcDatabaseMetaData_getBestRowIdentifier
          "result set is null",                                           // jdbcResultSetMetaData_jdbcResultSetMetaData
          "result set is closed",                                         // jdbcResultSetMetaData_jdbcResultSetMetaData_2
          "37000 missing )",                                              // MISSING_CLOSEBRACKET
!         "row has been modified by another transaction",                 // TableFilter_findFirst
          "37000 there is an index on the column to be removed",          // Table_moveDefinition
          "22001 string too long",                                        //
          "00000 quoted identifier required",                             // SET PROPERTY "name" "value"
***************
*** 541,547 ****
          "loading trigger class ",                                       // DatabaseCommandInterpreter_processCreateTrigger2
          "missing or zero-length savepoint name",                        // DatabaseCommandInterpreter_processSavepoint
          "error $$ during defrag - file $$",                             // DataFileCache_defrag
!         "error $$ during shutdown - file $$",                           // DataFileCache_closeFile
          "error $$ reading row - file $$",                               // DataFileCache_makeRow
          "error $$ opening file - file $$",                              // DataFileCache_makeRow
          "error $$ closing file - file $$",                              // 211 DataFileCache_makeRow
--- 541,547 ----
          "loading trigger class ",                                       // DatabaseCommandInterpreter_processCreateTrigger2
          "missing or zero-length savepoint name",                        // DatabaseCommandInterpreter_processSavepoint
          "error $$ during defrag - file $$",                             // DataFileCache_defrag
!         "invalid collation name",                                       // INVALID_COLLATION_NAME_NO_SUBCLASS
          "error $$ reading row - file $$",                               // DataFileCache_makeRow
          "error $$ opening file - file $$",                              // DataFileCache_makeRow
          "error $$ closing file - file $$",                              // 211 DataFileCache_makeRow
*** misc/hsqldb/src/org/hsqldb/Transaction.java	Wed Mar  2 14:50:57 2005
--- misc/build/hsqldb/src/org/hsqldb/Transaction.java	Thu Mar 24 14:18:01 2005
***************
*** 73,82 ****
   */
  class Transaction {
  
!     private boolean isDelete;
!     private Table   tTable;
!     private Row     row;
!     long            SCN;
  
      /**
       * Constructor. <p>
--- 73,82 ----
   */
  class Transaction {
  
!     boolean isDelete;
!     Table   tTable;
!     Row     row;
!     long    SCN;
  
      /**
       * Constructor. <p>
*** misc/hsqldb/src/org/hsqldb/TxManager.java	Thu Mar 24 14:14:06 2005
--- misc/build/hsqldb/src/org/hsqldb/TxManager.java	Thu Mar 24 14:18:01 2005
***************
*** 1 ****
! dummy
--- 1,145 ----
! /* Copyright (c) 2001-2005, The HSQL Development Group
!  * All rights reserved.
!  *
!  * Redistribution and use in source and binary forms, with or without
!  * modification, are permitted provided that the following conditions are met:
!  *
!  * Redistributions of source code must retain the above copyright notice, this
!  * list of conditions and the following disclaimer.
!  *
!  * Redistributions in binary form must reproduce the above copyright notice,
!  * this list of conditions and the following disclaimer in the documentation
!  * and/or other materials provided with the distribution.
!  *
!  * Neither the name of the HSQL Development Group nor the names of its
!  * contributors may be used to endorse or promote products derived from this
!  * software without specific prior written permission.
!  *
!  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
!  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
!  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
!  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
!  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
!  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
!  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
!  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
!  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
!  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!  */
! 
! 
! package org.hsqldb;
! 
! import org.hsqldb.lib.*;
! 
! class TxManager {
! 
!     LongKeyIntValueHashMap rowSessionMap;
! 
!     TxManager() {
!         rowSessionMap = new LongKeyIntValueHashMap();
!     }
! 
!     void checkDelete(Session session, Row row) throws HsqlException {}
! 
!     void checkDelete(Session session,
!                      HashMappedList rowSet) throws HsqlException {
! 
!         int sessionid = session.getId();
! 
!         for (int i = 0, size = rowSet.size(); i < size; i++) {
!             Row  row   = (Row) rowSet.getKey(i);
!             long rowid = row.getId();
! 
!             if (rowSessionMap.get(rowid, sessionid) != sessionid) {
!                 throw Trace.error(Trace.INVALID_TRANSACTION_STATE_NO_SUBCLASS,
!                                   Trace.ITSNS_OVERWRITE);
!             }
!         }
!     }
! 
!     void checkDelete(Session session,
!                      HsqlArrayList rowSet) throws HsqlException {
! 
!         int sessionid = session.getId();
! 
!         for (int i = 0, size = rowSet.size(); i < size; i++) {
!             Row  row   = (Row) rowSet.get(i);
!             long rowid = row.getId();
! 
!             if (rowSessionMap.get(rowid, sessionid) != sessionid) {
!                 throw Trace.error(Trace.INVALID_TRANSACTION_STATE_NO_SUBCLASS,
!                                   Trace.ITSNS_OVERWRITE);
!             }
!         }
!     }
! 
!     void commit(Session session) {
! 
!         Object[] list = session.transactionList.getArray();
!         int      size = session.transactionList.size();
! 
!         for (int i = 0; i < size; i++) {
!             Transaction tx    = (Transaction) list[i];
!             long        rowid = tx.row.getId();
! 
!             rowSessionMap.remove(rowid);
!         }
! 
!         session.transactionList.clear();
!         session.savepoints.clear();
!     }
! 
!     synchronized void rollback(Session session) {
! 
!         int size = session.transactionList.size();
! 
!         rollbackTransactions(session, 0, false);
!         session.savepoints.clear();
!     }
! 
!     void rollbackSavepoint(Session session,
!                            String name) throws HsqlException {
! 
!         int index = session.savepoints.getIndex(name);
! 
!         if (index < 1) {
!             throw Trace.error(Trace.SAVEPOINT_NOT_FOUND, name);
!         }
! 
!         Integer oi    = (Integer) session.savepoints.get(index);
!         int     limit = oi.intValue();
! 
!         rollbackTransactions(session, limit, false);
! 
!         while (session.savepoints.size() > index) {
!             session.savepoints.remove(session.savepoints.size() - 1);
!         }
!     }
! 
!     void rollbackTransactions(Session session, int limit, boolean log) {
! 
!         Object[] list = session.transactionList.getArray();
!         int      size = session.transactionList.size();
! 
!         for (int i = size - 1; i >= limit; i--) {
!             Transaction tx = (Transaction) list[i];
! 
!             tx.rollback(session, false);
!         }
! 
!         for (int i = limit; i < size; i++) {
!             Transaction tx    = (Transaction) list[i];
!             long        rowid = tx.row.getId();
! 
!             rowSessionMap.remove(rowid);
!         }
! 
!         session.transactionList.setSize(limit);
!     }
! 
!     void addTransaction(Session session, Transaction transaction) {
!         rowSessionMap.put(transaction.row.getId(), session.getId());
!     }
! }
*** misc/hsqldb/src/org/hsqldb/jdbc/jdbcClob.java	Wed Mar  2 14:50:49 2005
--- misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcClob.java	Thu Mar 24 14:18:01 2005
***************
*** 275,280 ****
--- 275,282 ----
          final long   dlen  = ldata.length();
          final long   sslen = searchstr.length();
  
+         start--;    //***** FOIRGOT THIS *******
+ 
  // This is potentially much less expensive than materializing a large
  // substring from some other vendor's CLOB.  Indeed, we should probably
  // do the comparison piecewise, using an in-memory buffer (or temp-files
*** misc/hsqldb/src/org/hsqldb/jdbc/jdbcConnection.java	Wed Mar  2 14:50:49 2005
--- misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcConnection.java	Thu Mar 24 14:18:01 2005
***************
*** 1260,1270 ****
       * <!-- end generic documentation -->
       * <!-- start release-specific documentation -->
       * <div class="ReleaseSpecificDocumentation">
-      * <h3>HSQLDB-Specific Information:</h3> <p>
-      *
-      * Up to and including 1.7.1, HSQLDB supports only
-      * <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>. <p>
-      *
       * </div> <!-- end release-specific documentation -->
       *
       * @param level one of the following <code>Connection</code>
--- 1260,1265 ----
***************
*** 1286,1294 ****
  
          checkClosed();
  
!         if (level != Connection.TRANSACTION_READ_UNCOMMITTED) {
              throw Util.notSupported;
          }
      }
  
      /**
--- 1281,1300 ----
  
          checkClosed();
  
!         boolean ok = level == Connection.TRANSACTION_READ_UNCOMMITTED
!                      || level == Connection.TRANSACTION_READ_COMMITTED
!                      || level == Connection.TRANSACTION_REPEATABLE_READ
!                      || level == Connection.TRANSACTION_SERIALIZABLE;
! 
!         if (!ok) {
              throw Util.notSupported;
          }
+ 
+         try {
+             sessionProxy.setIsolation(level);
+         } catch (HsqlException e) {
+             throw Util.sqlException(e);
+         }
      }
  
      /**
***************
*** 1324,1330 ****
  
          checkClosed();
  
!         return Connection.TRANSACTION_READ_UNCOMMITTED;
      }
  
      /**
--- 1330,1340 ----
  
          checkClosed();
  
!         try {
!             return sessionProxy.getIsolation();
!         } catch (HsqlException e) {
!             throw Util.sqlException(e);
!         }
      }
  
      /**
*** misc/hsqldb/src/org/hsqldb/jdbc/jdbcDatabaseMetaData.java	Wed Mar  2 14:50:50 2005
--- misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcDatabaseMetaData.java	Thu Mar 24 14:18:01 2005
***************
*** 2902,2908 ****
       * <!-- start release-specific documentation -->
       * <div class="ReleaseSpecificDocumentation">
       * <h3>HSQLDB-Specific Information</h3>
!      * HSQLDB supports only <code>TRANSACTION_READ_UNCOMMITED</code>.
       * </div>
       * <!-- end release-specific documentation -->
       *
--- 2902,2909 ----
       * <!-- start release-specific documentation -->
       * <div class="ReleaseSpecificDocumentation">
       * <h3>HSQLDB-Specific Information</h3>
!      * HSQLDB supports <code>TRANSACTION_READ_UNCOMMITED</code> and
!      * <code>TRANSACTION_READ_COMMITED</code>.
       * </div>
       * <!-- end release-specific documentation -->
       *
***************
*** 2915,2921 ****
       */
      public boolean supportsTransactionIsolationLevel(int level)
      throws SQLException {
!         return level == Connection.TRANSACTION_READ_UNCOMMITTED;
      }
  
      /**
--- 2916,2926 ----
       */
      public boolean supportsTransactionIsolationLevel(int level)
      throws SQLException {
! 
!         return level == Connection.TRANSACTION_READ_UNCOMMITTED
!                || level == Connection.TRANSACTION_READ_COMMITTED
!                || level == Connection.TRANSACTION_REPEATABLE_READ
!                || level == Connection.TRANSACTION_SERIALIZABLE;
      }
  
      /**
*** misc/hsqldb/src/org/hsqldb/jdbc/jdbcPreparedStatement.java	Wed Mar  2 14:50:51 2005
--- misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcPreparedStatement.java	Thu Mar 24 14:18:01 2005
***************
*** 2134,2140 ****
       *
       * @throws SQLException if a database access error occurs
       */
!     public void close() throws SQLException {
  
          if (isClosed()) {
              return;
--- 2134,2140 ----
       *
       * @throws SQLException if a database access error occurs
       */
!     public synchronized void close() throws SQLException {
  
          if (isClosed()) {
              return;
*** misc/hsqldb/src/org/hsqldb/jdbc/jdbcStatement.java	Wed Mar  2 14:50:52 2005
--- misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcStatement.java	Thu Mar 24 14:18:01 2005
***************
*** 122,128 ****
   *
   * @author boucherb@users
   * @author fredt@user
!  * @version 1.7.2
   * @see jdbcConnection#createStatement
   * @see jdbcResultSet
   */
--- 122,128 ----
   *
   * @author boucherb@users
   * @author fredt@user
!  * @version 1.8.0
   * @see jdbcConnection#createStatement
   * @see jdbcResultSet
   */
***************
*** 133,139 ****
       * object now explicitly closes all of its open jdbcXXXStatement objects
       * when it is closed.
       */
!     boolean isClosed;
  
      /** Is escape processing enabled? */
      private boolean isEscapeProcessing = true;
--- 133,139 ----
       * object now explicitly closes all of its open jdbcXXXStatement objects
       * when it is closed.
       */
!     volatile boolean isClosed;
  
      /** Is escape processing enabled? */
      private boolean isEscapeProcessing = true;
***************
*** 258,264 ****
       *
       * @exception SQLException if a database access error occurs
       */
!     public void close() throws SQLException {
  
          if (isClosed) {
              return;
--- 258,264 ----
       *
       * @exception SQLException if a database access error occurs
       */
!     public synchronized void close() throws SQLException {
  
          if (isClosed) {
              return;
***************
*** 1533,1539 ****
      /**
       * Retrieves whether this statement is closed.
       */
!     boolean isClosed() {
          return isClosed;
      }
  
--- 1533,1539 ----
      /**
       * Retrieves whether this statement is closed.
       */
!     synchronized boolean isClosed() {
          return isClosed;
      }
  
*** misc/hsqldb/src/org/hsqldb/lib/ArrayUtil.java	Wed Mar  2 14:50:52 2005
--- misc/build/hsqldb/src/org/hsqldb/lib/ArrayUtil.java	Thu Mar 24 14:18:01 2005
***************
*** 788,794 ****
       *  colindex is not copied. If adjust is +1 that element is filled with
       *  the Object addition. All the rest of the elements in source are
       *  shifted left or right accordingly when they are copied. If adjust is 0
!      *  only elements up to colindex are copied.
       *
       *  No checks are perfomed on array sizes and an exception is thrown
       *  if they are not consistent with the other arguments.
--- 788,794 ----
       *  colindex is not copied. If adjust is +1 that element is filled with
       *  the Object addition. All the rest of the elements in source are
       *  shifted left or right accordingly when they are copied. If adjust is 0
!      *  the addition is copied over the element at colindex.
       *
       *  No checks are perfomed on array sizes and an exception is thrown
       *  if they are not consistent with the other arguments.
***************
*** 799,808 ****
  
          int length = Array.getLength(source);
  
          System.arraycopy(source, 0, dest, 0, colindex);
  
          if (adjust == 0) {
!             return;
          } else if (adjust < 0) {
              int endcount = length - colindex - 1;
  
--- 799,821 ----
  
          int length = Array.getLength(source);
  
+         if (colindex < 0) {
+             System.arraycopy(source, 0, dest, 0, length);
+ 
+             return;
+         }
+ 
          System.arraycopy(source, 0, dest, 0, colindex);
  
          if (adjust == 0) {
!             int endcount = length - colindex - 1;
! 
!             Array.set(dest, colindex, addition);
! 
!             if (endcount > 0) {
!                 System.arraycopy(source, colindex + 1, dest, colindex + 1,
!                                  endcount);
!             }
          } else if (adjust < 0) {
              int endcount = length - colindex - 1;
  
***************
*** 917,923 ****
              colindex[i] = i;
          }
      }
!     /*
      public static void main(String[] args) {
  
          int[] a = new int[] {
--- 930,936 ----
              colindex[i] = i;
          }
      }
! /*
      public static void main(String[] args) {
  
          int[] a = new int[] {
*** misc/hsqldb/src/org/hsqldb/lib/HsqlArrayList.java	Wed Mar  2 14:50:52 2005
--- misc/build/hsqldb/src/org/hsqldb/lib/HsqlArrayList.java	Thu Mar 24 14:18:01 2005
***************
*** 331,336 ****
--- 331,340 ----
          Sort.sort(elementData, c, 0, elementCount - 1);
      }
  
+     public Object[] getArray() {
+         return elementData;
+     }
+ 
  // fredt@users - temp - won't need this when start using HashedMappedList for Table
      public void remove(Object obj) {
  
*** misc/hsqldb/src/org/hsqldb/lib/LongKeyIntValueHashMap.java	Thu Mar 24 14:14:06 2005
--- misc/build/hsqldb/src/org/hsqldb/lib/LongKeyIntValueHashMap.java	Thu Mar 24 14:18:01 2005
***************
*** 1 ****
! dummy
--- 1,200 ----
! /* Copyright (c) 2001-2005, The HSQL Development Group
!  * All rights reserved.
!  *
!  * Redistribution and use in source and binary forms, with or without
!  * modification, are permitted provided that the following conditions are met:
!  *
!  * Redistributions of source code must retain the above copyright notice, this
!  * list of conditions and the following disclaimer.
!  *
!  * Redistributions in binary form must reproduce the above copyright notice,
!  * this list of conditions and the following disclaimer in the documentation
!  * and/or other materials provided with the distribution.
!  *
!  * Neither the name of the HSQL Development Group nor the names of its
!  * contributors may be used to endorse or promote products derived from this
!  * software without specific prior written permission.
!  *
!  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
!  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
!  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
!  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
!  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
!  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
!  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
!  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
!  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
!  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!  */
! 
! 
! package org.hsqldb.lib;
! 
! import java.util.NoSuchElementException;
! 
! import org.hsqldb.store.BaseHashMap;
! 
! /**
!  * @author fredt@users
!  * @version 1.7.2
!  * @since 1.7.2
!  */
! public class LongKeyIntValueHashMap extends BaseHashMap {
! 
!     private Set        keySet;
!     private Collection values;
! 
!     public LongKeyIntValueHashMap() {
!         this(16, 0.75f);
!     }
! 
!     public LongKeyIntValueHashMap(int initialCapacity)
!     throws IllegalArgumentException {
!         this(initialCapacity, 0.75f);
!     }
! 
!     public LongKeyIntValueHashMap(int initialCapacity,
!                                   float loadFactor)
!                                   throws IllegalArgumentException {
!         super(initialCapacity, loadFactor, BaseHashMap.longKeyOrValue,
!               BaseHashMap.intKeyOrValue, false);
!     }
! 
!     public int get(long key) throws NoSuchElementException {
! 
!         int lookup = getLookup(key);
! 
!         if (lookup != -1) {
!             return intValueTable[lookup];
!         }
! 
!         throw new NoSuchElementException();
!     }
! 
!     public int get(long key, int defaultValue) {
! 
!         int lookup = getLookup(key);
! 
!         if (lookup != -1) {
!             return intValueTable[lookup];
!         }
! 
!         return defaultValue;
!     }
! 
!     public boolean get(long key, int[] value) {
! 
!         int lookup = getLookup(key);
! 
!         if (lookup != -1) {
!             value[0] = intValueTable[lookup];
! 
!             return true;
!         }
! 
!         return false;
!     }
! 
!     public boolean put(long key, int value) {
! 
!         int oldSize = size();
! 
!         super.addOrRemove(key, value, null, null, false);
! 
!         return oldSize != size();
!     }
! 
!     public boolean remove(long key) {
! 
!         int oldSize = size();
! 
!         super.addOrRemove(key, 0, null, null, true);
! 
!         return oldSize != size();
!     }
! 
!     public Set keySet() {
! 
!         if (keySet == null) {
!             keySet = new KeySet();
!         }
! 
!         return keySet;
!     }
! 
!     public Collection values() {
! 
!         if (values == null) {
!             values = new Values();
!         }
! 
!         return values;
!     }
! 
!     class KeySet implements Set {
! 
!         public Iterator iterator() {
!             return LongKeyIntValueHashMap.this.new BaseHashIterator(true);
!         }
! 
!         public int size() {
!             return LongKeyIntValueHashMap.this.size();
!         }
! 
!         public boolean contains(Object o) {
!             throw new RuntimeException();
!         }
! 
!         public Object get(Object key) {
!             throw new RuntimeException();
!         }
! 
!         public boolean add(Object value) {
!             throw new RuntimeException();
!         }
! 
!         public boolean remove(Object o) {
!             throw new RuntimeException();
!         }
! 
!         public boolean isEmpty() {
!             return size() == 0;
!         }
! 
!         public void clear() {
!             LongKeyIntValueHashMap.this.clear();
!         }
!     }
! 
!     class Values implements Collection {
! 
!         public Iterator iterator() {
!             return LongKeyIntValueHashMap.this.new BaseHashIterator(false);
!         }
! 
!         public int size() {
!             return LongKeyIntValueHashMap.this.size();
!         }
! 
!         public boolean contains(Object o) {
!             throw new RuntimeException();
!         }
! 
!         public boolean add(Object value) {
!             throw new RuntimeException();
!         }
! 
!         public boolean remove(Object o) {
!             throw new RuntimeException();
!         }
! 
!         public boolean isEmpty() {
!             return size() == 0;
!         }
! 
!         public void clear() {
!             LongKeyIntValueHashMap.this.clear();
!         }
!     }
! }
*** misc/hsqldb/src/org/hsqldb/persist/DataFileCache.java	Wed Mar  2 14:50:53 2005
--- misc/build/hsqldb/src/org/hsqldb/persist/DataFileCache.java	Thu Mar 24 14:18:01 2005
***************
*** 197,206 ****
          fileFreePosition = 0;
  
          try {
!             boolean preexists = false;
              long    freesize  = 0;
  
!             if (fa.isStreamElement(fileName)) {
                  if (database.isStoredFileAccess()) {
                      preexists = true;
                  } else {
--- 197,206 ----
          fileFreePosition = 0;
  
          try {
!             boolean preexists = database.isFilesInJar();
              long    freesize  = 0;
  
!             if (!preexists && fa.isStreamElement(fileName)) {
                  if (database.isStoredFileAccess()) {
                      preexists = true;
                  } else {
***************
*** 234,239 ****
--- 234,243 ----
              int fileType = isNio ? ScaledRAFile.DATA_FILE_NIO
                                   : ScaledRAFile.DATA_FILE_RAF;
  
+             if (database.isFilesInJar()) {
+                 fileType = ScaledRAFile.DATA_FILE_JAR;
+             }
+ 
              // oj@openofice.org - change to file access api
              String cname =
                  database.getURLProperties().getProperty("storage_class_name");
*** misc/hsqldb/src/org/hsqldb/persist/HsqlDatabaseProperties.java	Wed Mar  2 15:04:03 2005
--- misc/build/hsqldb/src/org/hsqldb/persist/HsqlDatabaseProperties.java	Thu Mar 24 14:18:01 2005
***************
*** 145,153 ****
          // char and padding to size and exception if data is too long
          setProperty("sql.enforce_strict_size", false);
  
-         // char and varchar sorting in charset of the current jvm Locale
-         setProperty("sql.compare_in_locale", false);
- 
          // removed from 1.7.2 - sql.month is always true (1-12)
          // removed from 1.7.2 - sql.strict_fk is always enforced
          // if true, requires a pre-existing unique index for foreign key
--- 145,150 ----
***************
*** 254,259 ****
--- 251,257 ----
              setProperty("hsqldb.log_size", 10);
              setProperty("sql.enforce_strict_size", true);
              setProperty("hsqldb.first_identity", 1);
+             setProperty("hsqldb.nio_data_file", false);
          }
  
          setSystemVariables();
***************
*** 262,268 ****
  
      private void setSystemVariables() {
  
!         Column.setCompareInLocal(isPropertyTrue("sql.compare_in_locale"));
  
          Record.gcFrequency = getIntegerProperty("runtime.gc_interval", 0);
      }
--- 260,269 ----
  
      private void setSystemVariables() {
  
!         if (isPropertyTrue("sql.compare_in_locale")) {
!             stringProps.remove("sql.compare_in_locale");
!             database.collation.setCollationAsLocale();
!         }
  
          Record.gcFrequency = getIntegerProperty("runtime.gc_interval", 0);
      }
*** misc/hsqldb/src/org/hsqldb/persist/Log.java	Wed Mar  2 14:50:54 2005
--- misc/build/hsqldb/src/org/hsqldb/persist/Log.java	Thu Mar 24 14:18:01 2005
***************
*** 376,385 ****
       */
      DataFileCache getCache() throws HsqlException {
  
          if (database.isFilesInJar()) {
              return null;
          }
! 
          if (cache == null) {
              cache = new DataFileCache(database, cacheFileName,
                                        backupFileName);
--- 376,386 ----
       */
      DataFileCache getCache() throws HsqlException {
  
+ /*
          if (database.isFilesInJar()) {
              return null;
          }
! */
          if (cache == null) {
              cache = new DataFileCache(database, cacheFileName,
                                        backupFileName);
*** misc/hsqldb/src/org/hsqldb/persist/ScaledRAFile.java	Wed Mar  2 14:50:54 2005
--- misc/build/hsqldb/src/org/hsqldb/persist/ScaledRAFile.java	Thu Mar 24 14:18:01 2005
***************
*** 55,60 ****
--- 55,61 ----
  
      static final int         DATA_FILE_RAF = 0;
      static final int         DATA_FILE_NIO = 1;
+     static final int         DATA_FILE_JAR = 2;
      final RandomAccessFile   file;
      private final boolean    readOnly;
      final String             fileName;
***************
*** 101,107 ****
              }
          }
  
!         if (type == DATA_FILE_RAF) {
              return new ScaledRAFile(name, readonly);
          } else {
              try {
--- 102,110 ----
              }
          }
  
!         if (type == DATA_FILE_JAR) {
!             return new ScaledRAFileInJar(name);
!         } else if (type == DATA_FILE_RAF) {
              return new ScaledRAFile(name, readonly);
          } else {
              try {
***************
*** 248,254 ****
              cacheHit++;
          }
  
- // 1_8_0_n
          ba.reset();
          ba.skip(seekPosition - bufferOffset);
  
--- 251,256 ----
*** misc/hsqldb/src/org/hsqldb/persist/ScaledRAFileInJar.java	Thu Mar 24 14:14:06 2005
--- misc/build/hsqldb/src/org/hsqldb/persist/ScaledRAFileInJar.java	Thu Mar 24 14:18:01 2005
***************
*** 1 ****
! dummy
--- 1,234 ----
! /* Copyright (c) 2001-2005, The HSQL Development Group
!  * All rights reserved.
!  *
!  * Redistribution and use in source and binary forms, with or without
!  * modification, are permitted provided that the following conditions are met:
!  *
!  * Redistributions of source code must retain the above copyright notice, this
!  * list of conditions and the following disclaimer.
!  *
!  * Redistributions in binary form must reproduce the above copyright notice,
!  * this list of conditions and the following disclaimer in the documentation
!  * and/or other materials provided with the distribution.
!  *
!  * Neither the name of the HSQL Development Group nor the names of its
!  * contributors may be used to endorse or promote products derived from this
!  * software without specific prior written permission.
!  *
!  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
!  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
!  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
!  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
!  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
!  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
!  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
!  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
!  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
!  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!  */
! 
! 
! package org.hsqldb.persist;
! 
! import java.io.FileNotFoundException;
! import java.io.IOException;
! import java.io.DataInputStream;
! import java.io.InputStream;
! 
! import org.hsqldb.lib.HsqlByteArrayInputStream;
! import org.hsqldb.lib.Storage;
! 
! /**
!  * This class is a random access wrapper around a DataInputStream object and
!  * enables access to cached tables when a database is included in a jar.
!  *
!  * A proof-of-concept prototype was first contributed by winfriedthom@users.
!  *
!  * @author fredt@users
!  * @version  1.8.0
!  * @since  1.8.0
!  */
! class ScaledRAFileInJar implements Storage {
! 
!     DataInputStream          file;
!     final String             fileName;
!     long                     fileLength;
!     boolean                  bufferDirty = true;
!     byte[]                   buffer      = new byte[4096];
!     HsqlByteArrayInputStream ba = new HsqlByteArrayInputStream(buffer);
!     long                     bufferOffset;
! 
!     //
!     long seekPosition;
!     long realPosition;
! 
!     ScaledRAFileInJar(String name) throws FileNotFoundException, IOException {
! 
!         fileName = name;
! 
!         resetStream();
!         file.skip(DataFileCache.LONG_FREE_POS_POS);
! 
!         fileLength = file.readLong();
! 
!         resetStream();
!     }
! 
!     public long length() throws IOException {
!         return fileLength;
!     }
! 
!     /**
!      * Some JVM's do not allow seek beyond end of file, so zeros are written
!      * first in that case. Reported by bohgammer@users in Open Disucssion
!      * Forum.
!      */
!     public void seek(long position) throws IOException {
!         seekPosition = position;
!     }
! 
!     public long getFilePointer() throws IOException {
!         return seekPosition;
!     }
! 
!     private void readIntoBuffer() throws IOException {
! 
!         long filePos = seekPosition;
! 
!         bufferDirty = false;
! 
!         long subOffset  = filePos % buffer.length;
!         long readLength = fileLength - (filePos - subOffset);
! 
!         if (readLength <= 0) {
!             throw new IOException("read beyond end of file");
!         }
! 
!         if (readLength > buffer.length) {
!             readLength = buffer.length;
!         }
! 
!         fileSeek(filePos - subOffset);
!         file.readFully(buffer, 0, (int) readLength);
! 
!         bufferOffset = filePos - subOffset;
!         realPosition = bufferOffset + readLength;
!     }
! 
!     public int read() throws IOException {
! 
!         if (seekPosition >= fileLength) {
!             return -1;
!         }
! 
!         if (bufferDirty || seekPosition < bufferOffset
!                 || seekPosition >= bufferOffset + buffer.length) {
!             readIntoBuffer();
!         }
! 
!         ba.reset();
!         ba.skip(seekPosition - bufferOffset);
! 
!         int val = ba.read();
! 
!         seekPosition++;
! 
!         return val;
!     }
! 
!     public long readLong() throws IOException {
! 
!         long hi = readInt();
!         long lo = readInt();
! 
!         return (hi << 32) + (lo & 0xffffffffL);
!     }
! 
!     public int readInt() throws IOException {
! 
!         if (bufferDirty || seekPosition < bufferOffset
!                 || seekPosition >= bufferOffset + buffer.length) {
!             readIntoBuffer();
!         }
! 
!         ba.reset();
!         ba.skip(seekPosition - bufferOffset);
! 
!         int val = ba.readInt();
! 
!         seekPosition += 4;
! 
!         return val;
!     }
! 
!     public void read(byte[] b, int offset, int length) throws IOException {
! 
!         if (bufferDirty || seekPosition < bufferOffset
!                 || seekPosition >= bufferOffset + buffer.length) {
!             readIntoBuffer();
!         }
! 
!         ba.reset();
!         ba.skip(seekPosition - bufferOffset);
! 
!         int bytesRead = ba.read(b, offset, length);
! 
!         seekPosition += bytesRead;
! 
!         if (bytesRead < length) {
!             if (seekPosition != realPosition) {
!                 fileSeek(seekPosition);
!             }
! 
!             file.readFully(b, offset + bytesRead, length - bytesRead);
! 
!             seekPosition += (length - bytesRead);
!             realPosition = seekPosition;
!         }
!     }
! 
!     public void write(byte[] b, int off, int len) throws IOException {}
! 
!     public void writeInt(int i) throws IOException {}
! 
!     public void writeLong(long i) throws IOException {}
! 
!     public void close() throws IOException {
!         file.close();
!     }
! 
!     public boolean isReadOnly() {
!         return true;
!     }
! 
!     public boolean wasNio() {
!         return false;
!     }
! 
!     private void resetStream() throws IOException {
! 
!         if (file != null) {
!             file.close();
!         }
! 
!         InputStream fis = getClass().getResourceAsStream(fileName);
! 
!         file = new DataInputStream(fis);
!     }
! 
!     private void fileSeek(long position) throws IOException {
! 
!         long skipPosition = realPosition;
! 
!         if (position < skipPosition) {
!             resetStream();
! 
!             skipPosition = 0;
!         }
! 
!         while (position > skipPosition) {
!             skipPosition += file.skip(position - skipPosition);
!         }
!     }
! }
*** misc/hsqldb/src/org/hsqldb/scriptio/ScriptWriterBase.java	Wed Mar  2 14:50:54 2005
--- misc/build/hsqldb/src/org/hsqldb/scriptio/ScriptWriterBase.java	Thu Mar 24 14:18:01 2005
***************
*** 41,46 ****
--- 41,47 ----
  import org.hsqldb.DatabaseScript;
  import org.hsqldb.HsqlException;
  import org.hsqldb.Result;
+ import org.hsqldb.Session;
  import org.hsqldb.Table;
  import org.hsqldb.Token;
  import org.hsqldb.Trace;
***************
*** 83,89 ****
  // used at checkpoint
  public abstract class ScriptWriterBase implements Runnable {
  
!     Database            db;
      String              outFile;
      OutputStream        fileStreamOut;
      FileAccess.FileSync outDescriptor;
--- 84,90 ----
  // used at checkpoint
  public abstract class ScriptWriterBase implements Runnable {
  
!     Database            database;
      String              outFile;
      OutputStream        fileStreamOut;
      FileAccess.FileSync outDescriptor;
***************
*** 139,145 ****
              throw Trace.error(Trace.FILE_IO_ERROR, file);
          }
  
!         this.db                = db;
          this.includeCachedData = includeCachedData;
          outFile                = file;
  
--- 140,146 ----
              throw Trace.error(Trace.FILE_IO_ERROR, file);
          }
  
!         this.database          = db;
          this.includeCachedData = includeCachedData;
          outFile                = file;
  
***************
*** 219,225 ****
      protected void openFile() throws HsqlException {
  
          try {
!             FileAccess   fa  = db.getFileAccess();
              OutputStream fos = fa.openOutputStreamElement(outFile);
  
              outDescriptor = fa.getFileSync(fos);
--- 220,226 ----
      protected void openFile() throws HsqlException {
  
          try {
!             FileAccess   fa  = database.getFileAccess();
              OutputStream fos = fa.openOutputStreamElement(outFile);
  
              outDescriptor = fa.getFileSync(fos);
***************
*** 240,253 ****
  
      protected void writeDDL() throws IOException, HsqlException {
  
!         Result ddlPart = DatabaseScript.getScript(db, !includeCachedData);
  
          writeSingleColumnResult(ddlPart);
      }
  
      protected void writeExistingData() throws HsqlException, IOException {
  
!         HsqlArrayList tables = db.getTables();
  
          for (int i = 0, size = tables.size(); i < size; i++) {
              Table t = (Table) tables.get(i);
--- 241,256 ----
  
      protected void writeDDL() throws IOException, HsqlException {
  
!         Result ddlPart = DatabaseScript.getScript(database,
!             !includeCachedData);
  
          writeSingleColumnResult(ddlPart);
      }
  
      protected void writeExistingData() throws HsqlException, IOException {
  
!         HsqlArrayList tables  = database.getTables();
!         Session       session = database.sessionManager.getSysSession();
  
          for (int i = 0, size = tables.size(); i < size; i++) {
              Table t = (Table) tables.get(i);
***************
*** 277,283 ****
                  if (script) {
                      writeTableInit(t);
  
!                     RowIterator it = t.rowIterator(null);
  
                      while (it.hasNext()) {
                          writeRow(0, t, it.next().getData());
--- 280,286 ----
                  if (script) {
                      writeTableInit(t);
  
!                     RowIterator it = t.rowIterator(session);
  
                      while (it.hasNext()) {
                          writeRow(0, t, it.next().getData());
*** misc/hsqldb/src/org/hsqldb/scriptio/ScriptWriterZipped.java	Wed Mar  2 14:50:54 2005
--- misc/build/hsqldb/src/org/hsqldb/scriptio/ScriptWriterZipped.java	Thu Mar 24 14:18:01 2005
***************
*** 63,69 ****
      protected void openFile() throws HsqlException {
  
          try {
!             FileAccess           fa  = db.getFileAccess();
              java.io.OutputStream fos = fa.openOutputStreamElement(outFile);
  
              outDescriptor = fa.getFileSync(fos);
--- 63,69 ----
      protected void openFile() throws HsqlException {
  
          try {
!             FileAccess           fa  = database.getFileAccess();
              java.io.OutputStream fos = fa.openOutputStreamElement(outFile);
  
              outDescriptor = fa.getFileSync(fos);
*** misc/hsqldb/src/org/hsqldb/test/TestBug785429.java	Wed Mar  2 14:50:56 2005
--- misc/build/hsqldb/src/org/hsqldb/test/TestBug785429.java	Thu Mar 24 14:18:01 2005
***************
*** 55,61 ****
  
      public void test() throws Exception {
  
!         Connection        conn = newConnection();
          Statement         stmt = conn.createStatement();
          String            sql;
          String            msg;
--- 55,64 ----
  
      public void test() throws Exception {
  
!         Connection conn = newConnection();
! 
!         conn.setAutoCommit(false);
! 
          Statement         stmt = conn.createStatement();
          String            sql;
          String            msg;
*** misc/hsqldb/src/org/hsqldb/test/TestCacheSize.java	Wed Mar  2 14:50:56 2005
--- misc/build/hsqldb/src/org/hsqldb/test/TestCacheSize.java	Thu Mar 24 14:18:01 2005
***************
*** 107,116 ****
      int     deleteWhileInsertInterval = 10000;
  
      // size of the tables used in test
!     int bigrows = 256000;
  
      // number of ops
!     int bigops    = 256000;
      int smallops  = 8000;
      int smallrows = 0xfff;
  
--- 107,116 ----
      int     deleteWhileInsertInterval = 10000;
  
      // size of the tables used in test
!     int bigrows = 64000;
  
      // number of ops
!     int bigops    = 64000;
      int smallops  = 8000;
      int smallrows = 0xfff;
  
*** misc/hsqldb/src/org/hsqldb/test/TestCollation.java	Thu Mar 24 14:14:06 2005
--- misc/build/hsqldb/src/org/hsqldb/test/TestCollation.java	Thu Mar 24 14:18:01 2005
***************
*** 1 ****
! dummy
--- 1,249 ----
! /* Copyright (c) 2001-2005, The HSQL Development Group
!  * All rights reserved.
!  *
!  * Redistribution and use in source and binary forms, with or without
!  * modification, are permitted provided that the following conditions are met:
!  *
!  * Redistributions of source code must retain the above copyright notice, this
!  * list of conditions and the following disclaimer.
!  *
!  * Redistributions in binary form must reproduce the above copyright notice,
!  * this list of conditions and the following disclaimer in the documentation
!  * and/or other materials provided with the distribution.
!  *
!  * Neither the name of the HSQL Development Group nor the names of its
!  * contributors may be used to endorse or promote products derived from this
!  * software without specific prior written permission.
!  *
!  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
!  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
!  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
!  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
!  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
!  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
!  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
!  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
!  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
!  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
!  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!  */
! 
! package org.hsqldb.test;
! 
! import junit.framework.TestCase;
! import junit.framework.TestResult;
! 
! /**
!  * Test HSQLDBs collation capabilities
!  * @author frank.schoenheit@sun.com
!  */
! public class TestCollation extends TestBase {
!     
!     java.sql.Statement      statement;
!     java.sql.Connection     connection;
!     org.hsqldb.Collation    collation;
!     org.hsqldb.lib.Iterator collIterator;
!     org.hsqldb.lib.Iterator localeIterator;
! 
!     /** Creates a new instance of TestCollation */
!     public TestCollation(String name)
!     {
!         super(name);
!         super.isNetwork = false;
!     }
!     
!     protected void setUp()
!     {
!         super.setUp();
! 
!         try
!         {
!             connection = super.newConnection();
!             statement  = connection.createStatement();
!         }
!         catch (Exception e)
!         {
!         }
! 
!         collation = new org.hsqldb.Collation();
!         collIterator = collation.getCollationsIterator();
!         localeIterator = collation.getLocalesIterator();
!     }
! 
!     protected void tearDown()
!     {
!         try
!         {
!             statement = connection.createStatement();
!             statement.execute( "SHUTDOWN" );
!         }
!         catch( Exception e )
!         {
!         }
!         super.tearDown();
!     }
! 
!     /**
!      * checks whether expected locales are present and selectable
!      */
!     public void verifyAvailability()
!     {
!         // let's check whether unknown collation identifiers are rejected
!         try
!         {
!             statement.execute( getSetCollationStmt( "ThisIsDefinatelyNoValidCollationIdentifier" ) );
!             fail( "database did not reject invalid collation name" );
!         }
!         catch( java.sql.SQLException e ) { }
! 
!         // let's check whether the DB accepts all known collations
!         int count = 0;
!         while ( collIterator.hasNext() )
!         {
!             String collationName = (String)collIterator.next();
!             try { statement.execute( getSetCollationStmt( collationName ) ); }
!             catch( java.sql.SQLException e )
!             {
!                 fail( "could not set collation '" + collationName + "'\n  exception message: " + e.getMessage() );
!             }
!             ++count;
!         }
!         System.out.println( "checked " + count + " collations for availability." );
! 
!         // even if the above worked, we cannot be sure that all locales are really supported.
!         // The fact that SET DATABASE COLLATION succeeeded only means that a Collator could
!         // be instantiated with a Locale matching the given collation name. But what if
!         // Locale.Instance(...) lied, and returned a fallback Locale instance?
!         //
!         // Hmm, looking at the documentation of Locale.getAvailableLocales, I'm not sure
!         // whether it is really feasible. The doc states "returns a list of all installed Locales".
!         // The "installed" puzzles me - maybe this is really different per installation, and not only
!         // per JDK version?
!         java.util.Locale availableLocales[] = java.util.Locale.getAvailableLocales();
!         org.hsqldb.lib.Set existenceCheck = new org.hsqldb.lib.HashSet();
!         for ( int i = 0; i < availableLocales.length; ++i )
!         {
!             String availaleName = availableLocales[i].getLanguage();
!             if ( availableLocales[i].getCountry().length() > 0 )
!                 availaleName += "-" + availableLocales[i].getCountry();
!             existenceCheck.add( availaleName );
!         }
! 
!         String notInstalled = "";
!         int expected = 0, failed = 0;
!         while ( localeIterator.hasNext() )
!         {
!             String localeName = (String)localeIterator.next();
!             ++expected;
! 
!             if ( !existenceCheck.contains( localeName ) )
!             {
!                 if ( notInstalled.length() > 0 )
!                     notInstalled += "; ";
!                 notInstalled += localeName;
!                 ++failed;
!             }
!         }
!         if ( notInstalled.length() > 0 )
!             fail( "the following locales are not installed:\n  " + notInstalled + "\n  (" + failed + " out of " + expected + ")" );
!     }
! 
!     /**
!      * checks whether sorting via a given collation works as expected
!      */
!     public void verifyCollation()
!     {
!         String failedCollations = "";
!         String failMessage = "";
! 
!         while ( collIterator.hasNext() )
!         {
!             String collationName = (String)collIterator.next();
!             String message = checkSorting( collationName );
!             if ( message.length() > 0 )
!             {
!                 if ( failedCollations.length() > 0 )
!                     failedCollations += ", ";
!                 failedCollations += collationName;
!                 failMessage += message;
!             }
!         }
!         if ( failedCollations.length() > 0 )
!         {
!             fail( "test failed for following collations:\n" + failedCollations + "\n" + failMessage );
!         }
!     }
! 
!     /**
!      * returns an SQL statement to set the database collation
!      **/
!     protected final String getSetCollationStmt( String collationName )
!     {
!         final String setCollationStmtPre = "SET DATABASE COLLATION \"";
!         final String setCollationStmtPost = "\"";
!         return setCollationStmtPre + collationName + setCollationStmtPost;
!     }
! 
!     /**
!      * checks sorting a table with according to a given collation
!      */
!     protected String checkSorting( String collationName )
!     {
!         String prepareStmt = "DROP TABLE WORDLIST IF EXISTS; CREATE TEXT TABLE WORDLIST ( ID INTEGER, WORD VARCHAR );" +
!                 "SET TABLE WORDLIST SOURCE \"" + collationName + ".csv;encoding=UTF-8\"";
!         String selectStmt = "SELECT ID, WORD FROM WORDLIST ORDER BY WORD";
! 
!         String returnMessage = "";
! 
!         try
!         {
!             // set database collation
!             statement.execute( getSetCollationStmt( collationName ) );
!             statement.execute( prepareStmt );
! 
!             java.sql.ResultSet results = statement.executeQuery( selectStmt );
!             while ( results.next() )
!             {
!                 int expectedPosition = results.getInt(1);
!                 int foundPosition = results.getRow();
!                 if ( expectedPosition != foundPosition )
!                 {
!                     String word = results.getString( 2 );
!                     return "testing collation '" + collationName + "' failed\n" +
!                             "  word              : " + word + "\n" +
!                             "  expected position : " + expectedPosition + "\n" +
!                             "  found position    : " + foundPosition+ "\n";
!                 }
!             }
!         }
!         catch( java.sql.SQLException e )
!         {
!             return "testing collation '" + collationName + "' failed\n  exception message: " + e.getMessage() + "\n";
!         }
! 
!         return "";
!     }
!    
!     public static void main(String[] argv)
!     {
!         TestResult result = new TestResult();
! 
!         TestCase availability = new TestCollation( "verifyAvailability" );
!         availability.run( result );
! 
!         TestCase sorting = new TestCollation( "verifyCollation" );
!         sorting.run( result );
! 
!         if ( result.failureCount() != 0 )
!         {
!             System.err.println( "TestCollation encountered errors:" );
!             java.util.Enumeration failures = result.failures();
!             while ( failures.hasMoreElements() )
!                 System.err.println( failures.nextElement().toString() );
!         }
!         else
!         {
!             System.out.println( "TestCollation: all fine." );
!         }
!     }
! }
*** misc/hsqldb/src/org/hsqldb/test/TestHashStructures.java	Wed Mar  2 14:50:57 2005
--- misc/build/hsqldb/src/org/hsqldb/test/TestHashStructures.java	Thu Mar 24 14:18:01 2005
***************
*** 32,38 ****
  package org.hsqldb.test;
  
  import java.util.Random;
- import java.util.Arrays;
  
  import org.hsqldb.lib.DoubleIntIndex;
  
--- 32,37 ----
***************
*** 53,175 ****
  
      public void testHashMap() throws Exception {
  
          int                    testSize = 33;
          org.hsqldb.lib.HashMap hMap     = new org.hsqldb.lib.HashMap();
          org.hsqldb.lib.IntKeyHashMap hIntMap =
              new org.hsqldb.lib.IntKeyHashMap();
          java.util.HashMap uMap = new java.util.HashMap();
  
!         // -
!         populateBySerialIntKeys(uMap, hMap, testSize);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
! 
!         // -
!         populateByRandomIntKeys(uMap, hMap, testSize);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
! 
!         //
!         depopulateRandomly(uMap, hMap, 20);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
! 
!         // -
!         populateBySerialIntKeys(uMap, hMap, testSize);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
! 
!         //
!         depopulateByIterator(uMap, hMap, 20);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
      }
  
      public void testIntKeyHashMap() throws Exception {
  
!         int testSize = 33;
          org.hsqldb.lib.IntKeyHashMap hIntMap =
              new org.hsqldb.lib.IntKeyHashMap();
          java.util.HashMap uMap = new java.util.HashMap();
  
!         populateBySerialIntKeysInt(uMap, hIntMap, testSize);
!         compareByUIteratorInt(uMap, hIntMap);
!         populateByRandomIntKeysInt(uMap, hIntMap, testSize);
!         compareByUIteratorInt(uMap, hIntMap);
!         compareByHIteratorInt(uMap, hIntMap);
! 
!         //
!         depopulateByIntIterator(uMap, hIntMap, 20);
!         compareByUIteratorInt(uMap, hIntMap);
!         compareByHIteratorInt(uMap, hIntMap);
! 
!         //
!         clearByIntIterator(uMap, hIntMap);
!         compareByUIteratorInt(uMap, hIntMap);
!         compareByHIteratorInt(uMap, hIntMap);
! 
!         // -
!         populateBySerialIntKeysInt(uMap, hIntMap, testSize);
!         compareByUIteratorInt(uMap, hIntMap);
!         compareByHIteratorInt(uMap, hIntMap);
! 
!         //
!         clearByIntIterator(uMap, hIntMap);
!         compareByUIteratorInt(uMap, hIntMap);
!         compareByHIteratorInt(uMap, hIntMap);
  
!         //-
!         assertTrue(true);
      }
  
      public void testHashMappedList() throws Exception {
  
!         int testSize = 33;
          org.hsqldb.lib.HashMappedList hMap =
              new org.hsqldb.lib.HashMappedList();
          java.util.HashMap uMap = new java.util.HashMap();
  
!         populateBySerialIntKeys(uMap, hMap, testSize);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
!         populateByRandomIntKeys(uMap, hMap, testSize);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
!         depopulateRandomly(uMap, hMap, 20);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
!         populateByRandomIntKeys(uMap, hMap, testSize);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
!         depopulateRandomly(uMap, hMap, 20);
!         populateBySerialIntKeys(uMap, hMap, testSize);
!         compareByUIterator(uMap, hMap);
!         compareByHIterator(uMap, hMap);
  
!         //-
!         assertTrue(true);
      }
  
      public void testDoubleIntLookup() throws Exception {
  
!         int testSize = 512;
          org.hsqldb.lib.IntKeyHashMap hIntMap =
              new org.hsqldb.lib.IntKeyHashMap();
          DoubleIntIndex intLookup = new DoubleIntIndex(12, false);
  
!         intLookup.setKeysSearchTarget();
!         populateBySerialIntKeysInt(intLookup, hIntMap, testSize);
!         compareByHIteratorInt(intLookup, hIntMap);
!         populateByRandomIntKeysInt(intLookup, hIntMap, testSize);
!         compareByHIteratorInt(intLookup, hIntMap);
  
!         //-
!         assertTrue(true);
      }
  
      public void testDoubleIntSpeed() throws Exception {
  
!         int testSize = 500;
          org.hsqldb.lib.IntKeyHashMap hIntMap =
              new org.hsqldb.lib.IntKeyHashMap();
          DoubleIntIndex intLookup = new DoubleIntIndex(testSize, false);
--- 52,193 ----
  
      public void testHashMap() throws Exception {
  
+         boolean                failed   = false;
          int                    testSize = 33;
          org.hsqldb.lib.HashMap hMap     = new org.hsqldb.lib.HashMap();
          org.hsqldb.lib.IntKeyHashMap hIntMap =
              new org.hsqldb.lib.IntKeyHashMap();
          java.util.HashMap uMap = new java.util.HashMap();
  
!         try {
!             populateBySerialIntKeys(uMap, hMap, testSize);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
! 
!             // -
!             populateByRandomIntKeys(uMap, hMap, testSize);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
! 
!             //
!             depopulateRandomly(uMap, hMap, 20);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
! 
!             // -
!             populateBySerialIntKeys(uMap, hMap, testSize);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
! 
!             //
!             depopulateByIterator(uMap, hMap, 20);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
!         } catch (Exception e) {
!             failed = true;
!         }
! 
!         assertTrue(!failed);
      }
  
      public void testIntKeyHashMap() throws Exception {
  
!         boolean failed   = false;
!         int     testSize = 33;
          org.hsqldb.lib.IntKeyHashMap hIntMap =
              new org.hsqldb.lib.IntKeyHashMap();
          java.util.HashMap uMap = new java.util.HashMap();
  
!         try {
!             populateBySerialIntKeysInt(uMap, hIntMap, testSize);
!             compareByUIteratorInt(uMap, hIntMap);
!             populateByRandomIntKeysInt(uMap, hIntMap, testSize);
!             compareByUIteratorInt(uMap, hIntMap);
!             compareByHIteratorInt(uMap, hIntMap);
! 
!             //
!             depopulateByIntIterator(uMap, hIntMap, 20);
!             compareByUIteratorInt(uMap, hIntMap);
!             compareByHIteratorInt(uMap, hIntMap);
! 
!             //
!             clearByIntIterator(uMap, hIntMap);
!             compareByUIteratorInt(uMap, hIntMap);
!             compareByHIteratorInt(uMap, hIntMap);
! 
!             // -
!             populateBySerialIntKeysInt(uMap, hIntMap, testSize);
!             compareByUIteratorInt(uMap, hIntMap);
!             compareByHIteratorInt(uMap, hIntMap);
! 
!             //
!             clearByIntIterator(uMap, hIntMap);
!             compareByUIteratorInt(uMap, hIntMap);
!             compareByHIteratorInt(uMap, hIntMap);
!         } catch (Exception e) {
!             failed = true;
!         }
  
!         assertTrue(!failed);
      }
  
      public void testHashMappedList() throws Exception {
  
!         boolean failed   = false;
!         int     testSize = 33;
          org.hsqldb.lib.HashMappedList hMap =
              new org.hsqldb.lib.HashMappedList();
          java.util.HashMap uMap = new java.util.HashMap();
  
!         try {
!             populateBySerialIntKeys(uMap, hMap, testSize);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
!             populateByRandomIntKeys(uMap, hMap, testSize);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
!             depopulateRandomly(uMap, hMap, 20);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
!             populateByRandomIntKeys(uMap, hMap, testSize);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
!             depopulateRandomly(uMap, hMap, 20);
!             populateBySerialIntKeys(uMap, hMap, testSize);
!             compareByUIterator(uMap, hMap);
!             compareByHIterator(uMap, hMap);
!         } catch (Exception e) {
!             failed = true;
!         }
  
!         assertTrue(!failed);
      }
  
      public void testDoubleIntLookup() throws Exception {
  
!         boolean failed   = false;
!         int     testSize = 512;
          org.hsqldb.lib.IntKeyHashMap hIntMap =
              new org.hsqldb.lib.IntKeyHashMap();
          DoubleIntIndex intLookup = new DoubleIntIndex(12, false);
  
!         try {
!             intLookup.setKeysSearchTarget();
!             populateBySerialIntKeysInt(intLookup, hIntMap, testSize);
!             compareByHIteratorInt(intLookup, hIntMap);
!             populateByRandomIntKeysInt(intLookup, hIntMap, testSize);
!             compareByHIteratorInt(intLookup, hIntMap);
!         } catch (Exception e) {
!             failed = true;
!         }
  
!         assertTrue(!failed);
      }
  
      public void testDoubleIntSpeed() throws Exception {
  
!         boolean failed   = false;
!         int     testSize = 500;
          org.hsqldb.lib.IntKeyHashMap hIntMap =
              new org.hsqldb.lib.IntKeyHashMap();
          DoubleIntIndex intLookup = new DoubleIntIndex(testSize, false);
***************
*** 207,216 ****
              System.out.println(
                  sw.elapsedTimeToMessage("Double int table error: i =" + i));
  
!             throw e;
          }
  
!         assertTrue(true);
      }
  
      int[] getSampleIntArray(org.hsqldb.lib.DoubleIntIndex index, int size) {
--- 225,234 ----
              System.out.println(
                  sw.elapsedTimeToMessage("Double int table error: i =" + i));
  
!             failed = true;
          }
  
!         assertTrue(!failed);
      }
  
      int[] getSampleIntArray(org.hsqldb.lib.DoubleIntIndex index, int size) {
*** misc/hsqldb/src/org/hsqldb/test/TestScript.java	Wed Mar  2 14:50:57 2005
--- misc/build/hsqldb/src/org/hsqldb/test/TestScript.java	Thu Mar 24 14:18:01 2005
***************
*** 36,48 ****
  
  public class TestScript extends TestBase {
  
-     String path = "TestSelfConstraints.txt";
- 
  //    String path = "TestSelfFieldLimits.txt";
  //    String path = "TestSelfLeftJoin.txt";
  //    String path = "TestSelfQueries.txt";
  //    String path = "TestSelfCheckConstraints.txt";
  //    String path = "TestSelfLeftJoin.txt";
      public TestScript(String name) {
          super(name);
      }
--- 36,50 ----
  
  public class TestScript extends TestBase {
  
  //    String path = "TestSelfFieldLimits.txt";
  //    String path = "TestSelfLeftJoin.txt";
  //    String path = "TestSelfQueries.txt";
  //    String path = "TestSelfCheckConstraints.txt";
+     String path = "TestSelfConstraints.txt";
+ 
+ //    String path = "TestSelfFieldLimits.txt";
  //    String path = "TestSelfLeftJoin.txt";
+ //    String path = "TestSelfUserFunction.txt";
      public TestScript(String name) {
          super(name);
      }
