Ejemplo n.º 1
0
        public void DeriveParameters()
        {
            using (HsqlConnection connection = NewConnection())
                using (HsqlCommand testSubject = connection.CreateCommand())
                {
                    testSubject.CommandText = "call 1 + cast(? as integer)";
                    testSubject.CommandType = global::System.Data.CommandType.StoredProcedure;
                    testSubject.DeriveParameters();

                    HsqlParameterCollection parameters = testSubject.Parameters;

                    Assert.AreEqual(1, parameters.Count);

                    HsqlParameter parameter = parameters[0];

                    Assert.AreEqual(DbType.Int32, parameter.DbType);
                    Assert.AreEqual(ParameterDirection.Input, parameter.Direction);
                    Assert.AreEqual(false, parameter.IsNullable);
                    Assert.AreEqual(0, parameter.Offset);
                    Assert.AreEqual("@p1", parameter.ParameterName);
                    Assert.AreEqual(10, parameter.Precision);
                    Assert.AreEqual(HsqlProviderType.Integer, parameter.ProviderType);
                    Assert.AreEqual(0, parameter.Scale);
                    Assert.AreEqual(4, parameter.Size);
                    Assert.AreEqual("", parameter.SourceColumn);
                    Assert.AreEqual(false, parameter.SourceColumnNullMapping);
                    Assert.AreEqual(DataRowVersion.Default, parameter.SourceVersion);
                    Assert.AreEqual("NULL", parameter.ToSqlLiteral());
                    Assert.AreEqual(null, parameter.Value);
                }
        }
        public void Insert()
        {
            HsqlParameterCollection testSubject = NewTestSubject();

            testSubject.Insert(0, new HsqlParameter("foo", "bar"));

            Assert.Fail("TODO");
        }
        public void Clone()
        {
            HsqlParameterCollection testSubject = NewTestSubject();

            testSubject.Clone();

            Assert.Fail("TODO");
        }
        public void GetEnumerator()
        {
            HsqlParameterCollection testSubject = NewTestSubject();

            foreach (HsqlParameter parameter in testSubject)
            {
            }

            Assert.Fail("TODO");
        }
Ejemplo n.º 5
0
 internal LocalCommand(
     string commandText,
     HsqlParameterCollection parameters,
     int returnParameterIndex,
     CommandType cmdType)
 {
     this.CommandText          = commandText;
     this.Parameters           = parameters;
     this.ReturnParameterIndex = returnParameterIndex;
     this.CmdType = cmdType;
 }
        public void IndexOf()
        {
            HsqlParameterCollection testSubject = NewTestSubject();
            HsqlParameter           value       = new HsqlParameter("foo", "bar");

            int expectedValueIndex = testSubject.Add((object)value);
            int actualValueIndex   = testSubject.IndexOf(value);

            Assert.AreEqual(expectedValueIndex, actualValueIndex);
            Assert.AreEqual(testSubject.IndexOf(value.ParameterName), testSubject.IndexOf(value));

            Assert.Fail("TODO");
        }
        public void AddRange()
        {
            HsqlParameterCollection testSubject = NewTestSubject();

            object[] avalues = new object[] { new HsqlParameter() };

            testSubject.AddRange(avalues);

            HsqlParameter[] pvalues = new HsqlParameter[] { new HsqlParameter() };

            testSubject.AddRange(pvalues);

            Assert.Fail("TODO");
        }
        public void Add()
        {
            HsqlParameterCollection testSubject = NewTestSubject();

            object ovalue = new HsqlParameter();


            int parameterIndex = testSubject.Add(ovalue);

            HsqlParameter pvalue = new HsqlParameter();
            HsqlParameter rvalue = testSubject.Add(pvalue);

            Assert.Fail("TODO");
        }
        public void Contains()
        {
            HsqlParameterCollection testSubject = NewTestSubject();
            object value = new HsqlParameter("foo", "bar");

            testSubject.Add(value);

            bool containsValue = testSubject.Contains(value);

            string parameterName = "foo";

            bool containsNamedParameter = testSubject.Contains(parameterName);

            Assert.Fail("TODO");
        }
        public void CopyTo()
        {
            HsqlParameterCollection testSubject = NewTestSubject();

            object[] array = new object[testSubject.Count];

            testSubject.CopyTo(array, 0);

            HsqlParameter[] paramArray = new HsqlParameter[testSubject.Count];


            ICollection <HsqlParameter> parameters = testSubject as ICollection <HsqlParameter>;

            parameters.CopyTo(paramArray, 0);
        }
        public void Remove()
        {
            HsqlParameterCollection testSubject = NewTestSubject();

            HsqlParameter parameter = new HsqlParameter("foo", "bar");

            testSubject.Add(parameter);

            Assert.AreEqual(1, testSubject.Count);

            testSubject.Remove(parameter);

            Assert.AreEqual(0, testSubject.Count);

            Assert.Fail("TODO");
        }
        public void RemoveAt()
        {
            HsqlParameterCollection testSubject = NewTestSubject();

            testSubject.Add(new HsqlParameter("foo", "bar"));
            testSubject.Add(new HsqlParameter("foo2", "bar"));

            Assert.That(testSubject.Contains("foo"));
            Assert.That(testSubject.Contains("foo2"));

            testSubject.RemoveAt(0);
            testSubject.RemoveAt("foo2");

            Assert.That(!testSubject.Contains("foo"));
            Assert.That(!testSubject.Contains("foo2"));

            Assert.Fail("TODO");
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Appends the statically-bound representation of this
        /// list to the given <c>StringBuilder</c>.
        /// </summary>
        /// <param name="sb">
        /// The <c>StringBuilder</c> to which to append.
        /// </param>
        /// <param name="parameters">The parameters to bind.</param>
        /// <param name="strict">
        /// When <c>true</c>, an exception is raised if there exist
        /// any unbound named parameter or parameter marker tokens.
        /// </param>
        /// <returns>
        /// The <c>StringBuilder</c> to which has been appended
        /// the statically-bound representation of this list.
        /// </returns>
        /// <remarks>
        /// The statically-bound representation of this list is the charater
        /// sequence representation in which each <c>NamedParameter</c> <c>Token</c>
        /// is replaced by an SQL literal character sequence representating the
        /// <c>Value</c> property of the matching <c>HsqlParameter</c>
        /// object from the given <c>parameters</c> collection.
        /// </remarks>
        public StringBuilder AppendStaticallyBoundForm(StringBuilder sb,
                                                       HsqlParameterCollection parameters,
                                                       bool strict)
        {
            if (ParameterCount == 0)
            {
                return(AppendNormalizedForm(sb));
            }
            else if (strict && ParameterMarkerCount > 0)
            {
                throw new HsqlDataSourceException(
                          "Cannot statically bind parameter markers"
                          + " ('?' tokens) by name."); //NOI18N
            }

            if (sb == null)
            {
                // Not perfectly accurate preallocation, but better than nothing.
                sb = new StringBuilder(m_normalizedCapacity);
            }
            else
            {
                sb.EnsureCapacity(sb.Length + m_normalizedCapacity);
            }

            int count = m_list.Count;

            for (int i = 0; i < count; i++)
            {
                Token        token = m_list[i];
                string       value = token.Value;
                SqlTokenType type  = token.Type;

                if (i > 0 && (Token.ValueFor.COMMA != value))
                {
                    sb.Append(' ');
                }

                if (type == SqlTokenType.NamedParameter)
                {
                    int index = parameters.IndexOf(value);

                    if (index >= 0)
                    {
                        HsqlParameter parameter
                            = (HsqlParameter)parameters[index];

                        sb.Append(parameter.ToSqlLiteral());
                    }
                    else if (strict)
                    {
                        throw new HsqlDataSourceException(
                                  "No binding for named parameter: "
                                  + value); // NOI18N
                    }
                    else // (index < 0 && strict == false)
                    {
                        // Effectively a named parameter pass through...
                        // may be that we want to do multi-pass binding.
                        sb.Append(value);
                    }
                }
                // Currently, this never happens, due to the
                // (strict && ParameterMarkerCount > 0) check above.
                // stubbed in as a reminder that we might have to deal
                // with this case differently, for instance using
                // a bind-by-parameter-ordinal policy.
                else if (strict && (Token.ValueFor.QUESTION == value))
                {
                    throw new HsqlDataSourceException(
                              "No binding for parameter marker: " + value); //NOI18N
                }
                else
                {
                    sb.Append(value);
                }
            }

            return(sb);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Gets the statically-bound representation of this list.
 /// </summary>
 /// <remarks>
 /// The statically-bound representation of this list is the
 /// one in which each named parameter list element whose <c>Value</c>
 /// property equals the <c>ParameterName</c> property of an
 /// <c>HsqlParameter</c> object in the given collection is
 /// replaced by an SQL literal character sequence representating the
 /// <c>Value</c> property of the matching <c>HsqlParameter</c>
 /// object.
 /// </remarks>
 /// <param name="parameters">The parameters to bind.</param>
 /// <param name="strict">
 /// When <c>true</c>, an exception is raised if there exist
 /// any unbound named parameter or parameter marker tokens.
 /// </param>
 /// <returns>
 /// The statically-bound string representation of this list.
 /// </returns>
 public string ToStaticallyBoundForm(HsqlParameterCollection parameters, bool strict)
 {
     return(AppendStaticallyBoundForm(null, parameters, strict).ToString());
 }
        internal void Append(HsqlCommand command)
        {
            HsqlParameterCollection parameters;

            if (command == null)
            {
                throw new ArgumentNullException(
                    "command");
            }

            string commandText = command.CommandText;

            if (string.IsNullOrEmpty(commandText))
            {
                throw new ArgumentException("Command Text Required",
                    "command.CommandText");
            }

            CommandType commandType = command.CommandType;

            switch (commandType)
            {
                case CommandType.Text:
                case CommandType.StoredProcedure:
                    {
                        parameters = null;
                        HsqlParameterCollection commandParameters = command.Parameters;
                        int parameterCount = commandParameters.Count;

                        if (parameterCount > 0)
                        {
                            parameters = new HsqlParameterCollection();

                            for (int i = 0; i < parameterCount; i++)
                            {
                                HsqlParameter destination = commandParameters[i].Clone();

                                parameters.Add(destination);

                                if (!IdentifierParser.IsMatch(destination
                                    .ParameterName))
                                {
                                    throw new HsqlDataSourceException(
                                        "Bad Parameter Name",
                                        org.hsqldb.Trace.GENERAL_ERROR,"S1000");
                                }
                            }
                        }
                        break;
                    }
                case CommandType.TableDirect:
                    {
                        throw new ArgumentOutOfRangeException(
                            "command.CommandType", commandType,
                            "Enumeration Value Not Supported.");
                    }
                default:
                    {
                        throw new ArgumentOutOfRangeException(
                            "command.CommandType", commandType,
                            "Invalid Enumeration Value");
                    }
            }

            int returnParameterIndex = -1;

            for (int j = 0; j < parameters.Count; j++)
            {
                if (ParameterDirection.ReturnValue == parameters[j].Direction)
                {
                    returnParameterIndex = j;
                    break;
                }
            }

            LocalCommand item = new LocalCommand(
                commandText,
                parameters,
                returnParameterIndex,
                commandType);

            m_commandList.Add(item);
        }
 internal LocalCommand(
     string commandText,
     HsqlParameterCollection parameters,
     int returnParameterIndex,
     CommandType cmdType)
 {
     this.CommandText = commandText;
     this.Parameters = parameters;
     this.ReturnParameterIndex = returnParameterIndex;
     this.CmdType = cmdType;
 }
Ejemplo n.º 17
0
        internal void Append(HsqlCommand command)
        {
            HsqlParameterCollection parameters;

            if (command == null)
            {
                throw new ArgumentNullException(
                          "command");
            }

            string commandText = command.CommandText;

            if (string.IsNullOrEmpty(commandText))
            {
                throw new ArgumentException("Command Text Required",
                                            "command.CommandText");
            }

            CommandType commandType = command.CommandType;

            switch (commandType)
            {
            case CommandType.Text:
            case CommandType.StoredProcedure:
            {
                parameters = null;
                HsqlParameterCollection commandParameters = command.Parameters;
                int parameterCount = commandParameters.Count;

                if (parameterCount > 0)
                {
                    parameters = new HsqlParameterCollection();

                    for (int i = 0; i < parameterCount; i++)
                    {
                        HsqlParameter destination = commandParameters[i].Clone();

                        parameters.Add(destination);

                        if (!IdentifierParser.IsMatch(destination
                                                      .ParameterName))
                        {
                            throw new HsqlDataSourceException(
                                      "Bad Parameter Name",
                                      org.hsqldb.Trace.GENERAL_ERROR, "S1000");
                        }
                    }
                }
                break;
            }

            case CommandType.TableDirect:
            {
                throw new ArgumentOutOfRangeException(
                          "command.CommandType", commandType,
                          "Enumeration Value Not Supported.");
            }

            default:
            {
                throw new ArgumentOutOfRangeException(
                          "command.CommandType", commandType,
                          "Invalid Enumeration Value");
            }
            }

            int returnParameterIndex = -1;

            for (int j = 0; j < parameters.Count; j++)
            {
                if (ParameterDirection.ReturnValue == parameters[j].Direction)
                {
                    returnParameterIndex = j;
                    break;
                }
            }

            LocalCommand item = new LocalCommand(
                commandText,
                parameters,
                returnParameterIndex,
                commandType);

            m_commandList.Add(item);
        }