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 ToSqlLiteral() { HsqlParameter testSubject = new HsqlParameter(); string actual = testSubject.ToSqlLiteral(); Assert.Fail("TODO"); }
public void ToSqlLiteral() { HsqlParameter testSubject = new HsqlParameter(); string actual = testSubject.ToSqlLiteral(); Assert.Fail("TODO"); }
public void Clone() { using (HsqlConnection connection = NewConnection()) using (HsqlTransaction transaction = connection.BeginTransaction()) using (HsqlCommand originalCommand = connection.CreateCommand()) { originalCommand.CommandType = global::System.Data.CommandType.StoredProcedure; originalCommand.CommandText = "call 1 + cast(? as integer)"; originalCommand.DeriveParameters(); HsqlCommand clonedCommand = originalCommand.Clone(); Assert.AreEqual(originalCommand.CommandText, clonedCommand.CommandText); Assert.AreEqual(originalCommand.CommandTimeout, clonedCommand.CommandTimeout); Assert.AreEqual(originalCommand.CommandType, clonedCommand.CommandType); Assert.AreSame(connection, clonedCommand.Connection); Assert.AreEqual(originalCommand.DesignTimeVisible, clonedCommand.DesignTimeVisible); Assert.AreEqual(originalCommand.Parameters.Count, clonedCommand.Parameters.Count); for (int i = 0; i < originalCommand.Parameters.Count; i++) { HsqlParameter orignalCommandParameter = originalCommand.Parameters[i]; HsqlParameter clonedCommandParameter = clonedCommand.Parameters[i]; Assert.AreEqual(orignalCommandParameter.DbType, clonedCommandParameter.DbType); Assert.AreEqual(orignalCommandParameter.Direction, clonedCommandParameter.Direction); Assert.AreEqual(orignalCommandParameter.IsNullable, clonedCommandParameter.IsNullable); Assert.AreEqual(orignalCommandParameter.Offset, clonedCommandParameter.Offset); Assert.AreEqual(orignalCommandParameter.ParameterName, clonedCommandParameter.ParameterName); Assert.AreEqual(orignalCommandParameter.Precision, clonedCommandParameter.Precision); Assert.AreEqual(orignalCommandParameter.ProviderType, clonedCommandParameter.ProviderType); Assert.AreEqual(orignalCommandParameter.Scale, clonedCommandParameter.Scale); Assert.AreEqual(orignalCommandParameter.Size, clonedCommandParameter.Size); Assert.AreEqual(orignalCommandParameter.SourceColumn, clonedCommandParameter.SourceColumn); Assert.AreEqual(orignalCommandParameter.SourceColumnNullMapping, clonedCommandParameter.SourceColumnNullMapping); Assert.AreEqual(orignalCommandParameter.SourceVersion, clonedCommandParameter.SourceVersion); Assert.AreEqual(orignalCommandParameter.ToSqlLiteral(), clonedCommandParameter.ToSqlLiteral()); Assert.AreEqual(orignalCommandParameter.Value, clonedCommandParameter.Value); } Assert.AreSame(originalCommand.Transaction, clonedCommand.Transaction); Assert.AreEqual(originalCommand.UpdatedRowSource, clonedCommand.UpdatedRowSource); } }
/// <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); }