/// <summary>
        /// Contructs a new <c>HsqlConnection</c>
        /// with the default connection string.
        /// </summary>
        public HsqlConnection() : base()
        {
            m_id = idseq++;
            m_settings = new HsqlConnectionStringBuilder();

            GC.SuppressFinalize(this);
        }
        public virtual void ShouldSerialize()
        {
            HsqlConnectionStringBuilder testSubject = new HsqlConnectionStringBuilder();
            bool actual = testSubject.ShouldSerialize("foo");

            Assert.Fail("TODO");
        }
        public virtual void Remove()
        {
            HsqlConnectionStringBuilder testSubject = new HsqlConnectionStringBuilder();
            bool actual = testSubject.Remove("foo");

            Assert.Fail("TODO");
        }
        public virtual void Clear()
        {
            HsqlConnectionStringBuilder testSubject = new HsqlConnectionStringBuilder();

            testSubject.Clear();

            Assert.Fail("TODO");
        }
        public virtual void ContainsKey()
        {
            // Create Constructor Parameters

            HsqlConnectionStringBuilder testSubject = new HsqlConnectionStringBuilder();

            testSubject.ContainsKey("foo");

            Assert.Fail("TODO");
        }
        public virtual void EquivalentTo()
        {
            HsqlConnectionStringBuilder testSubject = new HsqlConnectionStringBuilder();

            bool expected = true;
            bool actual = testSubject.EquivalentTo(testSubject);

            Assert.AreEqual(expected, actual);

            Assert.Fail("TODO");
        }
 /// <summary>
 /// Determines whether the given builder specifies an 
 /// embedded connection protocol
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>
 /// <c>true</c> if the builder specified an embedded connection protocol;
 /// otherwise, <c>false</c>.
 /// </returns>
 public static bool IsEmbeddedProtocol(HsqlConnectionStringBuilder builder)
 {
     switch (builder.Protocol)
     {
         case ConnectionProtocol.File:
         case ConnectionProtocol.Mem:
         case ConnectionProtocol.Res:
             {
                 return true;
             }
         default:
             {
                 return false;
             }
     }
 }
        public virtual void TryGetValue()
        {
            HsqlConnectionStringBuilder testSubject = new HsqlConnectionStringBuilder();

            object value;
            bool success = false;

            try
            {
                success = testSubject.TryGetValue("foo", out value);
            }
            catch (Exception)
            {

            }

            Assert.Fail("TODO");
        }
        /// <summary>
        /// Returns the collection of currently valid initial schema names, 
        /// given the specified context.
        /// </summary>
        /// <param name="context">
        /// An <see cref="ITypeDescriptorContext"></see> whose <c>Instance</c> 
        /// property supplies the <c>HsqlConnectionStringBuilder</c> use to 
        /// connect to a data source to retrieve the currently valid initial 
        /// schema names.
        /// </param>
        /// <returns>
        /// A <see cref="TypeConverter.StandardValuesCollection"/> that holds 
        /// collection of currently valid initial schema names.
        /// </returns>
        public override TypeConverter.StandardValuesCollection GetStandardValues(
            ITypeDescriptorContext context)
        {
            if (!IsStandardValuesSupported(context))
            {
                return null;
            }

            List<string> values = new List<string>();

            try
            {
                HsqlConnectionStringBuilder builder
                    = (HsqlConnectionStringBuilder)context.Instance;

                // TODO:  this is sub-optimal, but is currently the best (only?)
                // solution to the problem of how to avoid creating and/or
                // leaving open embedded database instances.
                if (IsEmbeddedProtocol(builder))
                {
                    builder = new HsqlConnectionStringBuilder(
                        builder.ConnectionString);

                    builder.AutoShutdown = true;
                    builder.IfExists = true;
                }

                using (HsqlConnection connection = new HsqlConnection())
                {
                    connection.ConnectionString = builder.ConnectionString;

                    using (HsqlCommand command = new HsqlCommand(
                        connection,
                        SchemaQuery))
                    {
                        connection.Open();

                        using (HsqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                values.Add(reader.GetString(0));
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
            #if DEBUG
                Debug.WriteLine(exception);
            #endif
            }

            return new TypeConverter.StandardValuesCollection(values);
        }
 /// <summary>
 /// Converts the given <c>HsqlConnectionStringBuilder</c>
 /// to an instance descriptor.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>
 /// An instance descriptor representing the given 
 /// <c>HsqlConnectionStringBuilder</c>.
 /// </returns>
 private InstanceDescriptor ConvertToInstanceDescriptor(
     HsqlConnectionStringBuilder builder)
 {
     return new InstanceDescriptor(
         typeof(HsqlConnectionStringBuilder).GetConstructor(types),
         new object[] { builder.ConnectionString });
 }
        /// <summary>
        /// Returns the collection of standard values for 
        /// the <see cref="HsqlConnectionStringBuilder.DataSource"/>
        /// property.
        /// </summary>
        /// <param name="context">Which may hold</param>
        /// <returns>
        /// The standard set of valid values.
        /// </returns>
        public override TypeConverter.StandardValuesCollection GetStandardValues(
            ITypeDescriptorContext context)
        {
            DataTable dataSources = DSEC.GetDataSources();
            DataRowCollection rows = dataSources.Rows;
            int rowCount = rows.Count;
            string[] array;

            if (context != null && context.Instance != null)
            {
                // might be a connection string builder or wrapper for one.
                try
                {
                    HsqlConnectionStringBuilder csb
                        = new HsqlConnectionStringBuilder(
                        Convert.ToString(context.Instance));

                    array = new string[rowCount + 1];

                    array[rowCount] = csb.DataSource;
                }
                catch (Exception)
                {
                    array = new string[rowCount];
                }
            }
            else
            {
                array = new string[rowCount];
            }

            for (int i = 0; i < rowCount; i++)
            {
                DataRow row = rows[i];

                string prefix = row[DSEC.ServerNameColumnOrdinal] as string;
                string suffix = row[DSEC.InstanceNameColumnOrdinal] as string;
                string version = row[DSEC.VersionColumnOrdinal] as string;

                if (string.IsNullOrEmpty(version) ||
                    version.StartsWith("1.8.0", StringComparison.Ordinal))
                {
                    array[i] = (string.IsNullOrEmpty(suffix))
                        ? prefix.Replace('\\', '/')
                        : new StringBuilder(prefix)
                        .Replace('\\', '/')
                        .Append('/')
                        .Append(suffix.Replace('\\', '/').TrimStart('/'))
                        .ToString();
                }
                else
                {
                    array[i] = string.Empty;
                }
            }

            org.hsqldb.lib.HashSet set = new org.hsqldb.lib.HashSet();

            set.addAll(array);

            set.remove(string.Empty);

            if (array.Length != set.size())
            {
                array = new string[set.size()];
            }

            set.toArray(array);

            Array.Sort<string>(array);

            return new TypeConverter.StandardValuesCollection(array);
        }
        /// <summary>
        /// Closes this connection.
        /// </summary>
        internal void CloseInternal()
        {
            ConnectionState state = m_connectionState;

            if (state == ConnectionState.Closed)
            {
                return;
            }

            HsqlSession session = m_session;

            if (m_session == null)
            {
                // Sanity-Check: Should never happen.
                throw new InvalidOperationException(
                    "HsqlSession is null"); // NOI18N
            }

            // Handle dispose/close while enlisted in a system transaction.

            HsqlTransaction transaction = m_transaction;
            HsqlEnlistment enlistment = m_enlistment;

            bool enlisted = (enlistment != null);
            bool preserveEnlistment = (enlisted && !enlistment.m_disposeConnection);

            if (preserveEnlistment)
            {
            #if DEBUG
                // Without this, it is difficult to debug
                // because the m_enlistment's connection
                // ceases to be this one and this connection
                // loses its reference to the enlistment
                // (m_enlistment is set null below).
                m_enlistment_dbg = m_enlistment;
            #endif
                // ...then until it ceases to participate in a
                // System.Transactions.Transaction, the enlistment
                // needs a valid local transaction to commit or
                // rollback

                HsqlConnection connection = new HsqlConnection(this);

                connection.m_connectionState = ConnectionState.Open;
                connection.m_session = session;
                connection.m_enlistment = enlistment;
                connection.m_transaction = transaction;

                enlistment.m_dbConnection = connection;
                enlistment.m_disposeConnection = true;

                if (transaction != null)
                {
                    transaction.m_connection = connection;
                }
            }

            SetStateInternal(ConnectionState.Closed);

            m_session = null;
            m_transaction = null;
            m_enlistment = null;
            m_dbMetaData = null;
            m_settings = null;

            if (!enlisted)
            {
                // No need to roll back here. This will happen automatically
                // a moment later on the back end in response to the
                // session.Close() call below.
                if (transaction != null)
                {
                    transaction.DisposeInternal(/*rollback*/false);
                }

                // release the back-end session and any associated resources,
                // such as network sockets, etc.
                session.Close();
            }
        }