コード例 #1
0
 /// <summary>
 /// Gets the location of a <see cref="NpgsqlParameter">NpgsqlParameter</see> in the collection.
 /// </summary>
 /// <param name="value">The value of the <see cref="NpgsqlParameter">NpgsqlParameter</see> object to find.</param>
 /// <returns>The zero-based index of the <see cref="NpgsqlParameter">NpgsqlParameter</see> object in the collection.</returns>
 public override int IndexOf(object value)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "IndexOf", value);
     CheckType(value);
     return(this.InternalList.IndexOf((NpgsqlParameter)value));
 }
コード例 #2
0
 /// <summary>
 /// Copies <see cref="NpgsqlParameter">NpgsqlParameter</see> objects from the <see cref="NpgsqlParameterCollection">NpgsqlParameterCollection</see> to the specified array.
 /// </summary>
 /// <param name="array">An <see cref="System.Array">Array</see> to which to copy the <see cref="NpgsqlParameter">NpgsqlParameter</see> objects in the collection.</param>
 /// <param name="index">The starting index of the array.</param>
 public override void CopyTo(Array array, int index)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CopyTo", array, index);
     (InternalList as ICollection).CopyTo(array, index);
     IRaiseItemChangedEvents x = InternalList as IRaiseItemChangedEvents;
 }
コード例 #3
0
        /// <summary>
        /// Gets the location of the <see cref="NpgsqlParameter">NpgsqlParameter</see> in the collection with a specific parameter name.
        /// </summary>
        /// <param name="parameterName">The name of the <see cref="NpgsqlParameter">NpgsqlParameter</see> object to find.</param>
        /// <returns>The zero-based location of the <see cref="NpgsqlParameter">NpgsqlParameter</see> in the collection.</returns>
        public override int IndexOf(string parameterName)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "IndexOf", parameterName);

            int retIndex;
            int scanIndex;

            if ((parameterName[0] == ':') || (parameterName[0] == '@'))
            {
                parameterName = parameterName.Remove(0, 1);
            }

            // Using a dictionary is much faster for 5 or more items
            if (this.InternalList.Count >= 5)
            {
                if (this.lookup == null)
                {
                    this.lookup = new Dictionary <string, int>();
                    for (scanIndex = 0; scanIndex < this.InternalList.Count; scanIndex++)
                    {
                        var item = this.InternalList[scanIndex];

                        // Store only the first of each distinct value
                        if (!this.lookup.ContainsKey(item.CleanName))
                        {
                            this.lookup.Add(item.CleanName, scanIndex);
                        }
                    }
                }

                // Try to access the case sensitive parameter name first
                if (this.lookup.TryGetValue(parameterName, out retIndex))
                {
                    return(retIndex);
                }

                // Case sensitive lookup failed, generate a case insensitive lookup
                if (this.lookupIgnoreCase == null)
                {
                    this.lookupIgnoreCase = new Dictionary <string, int>(StringComparer.InvariantCultureIgnoreCase);
                    for (scanIndex = 0; scanIndex < this.InternalList.Count; scanIndex++)
                    {
                        var item = this.InternalList[scanIndex];

                        // Store only the first of each distinct value
                        if (!this.lookupIgnoreCase.ContainsKey(item.CleanName))
                        {
                            this.lookupIgnoreCase.Add(item.CleanName, scanIndex);
                        }
                    }
                }

                // Then try to access the case insensitive parameter name
                if (this.lookupIgnoreCase.TryGetValue(parameterName, out retIndex))
                {
                    return(retIndex);
                }

                return(-1);
            }

            retIndex = -1;

            // Scan until a case insensitive match is found, and save its index for possible return.
            // Items that don't match loosely cannot possibly match exactly.
            for (scanIndex = 0; scanIndex < this.InternalList.Count; scanIndex++)
            {
                var item = this.InternalList[scanIndex];

                if (string.Compare(parameterName, item.CleanName, StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    retIndex = scanIndex;

                    break;
                }
            }

            // Then continue the scan until a case sensitive match is found, and return it.
            // If a case insensitive match was found, it will be re-checked for an exact match.
            for ( ; scanIndex < this.InternalList.Count; scanIndex++)
            {
                var item = this.InternalList[scanIndex];

                if (item.CleanName == parameterName)
                {
                    return(scanIndex);
                }
            }

            // If a case insensitive match was found, it will be returned here.
            return(retIndex);
        }
コード例 #4
0
 /// <summary>
 /// Removes the specified <see cref="NpgsqlParameter">NpgsqlParameter</see> from the collection.
 /// </summary>
 /// <param name="oValue">The <see cref="NpgsqlParameter">NpgsqlParameter</see> to remove from the collection.</param>
 public override void Remove(object oValue)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Remove", oValue);
     CheckType(oValue);
     Remove(oValue as NpgsqlParameter);
 }
コード例 #5
0
        /// <summary>
        /// Sends the <see cref="NpgsqlCommand.CommandText">CommandText</see> to
        /// the <see cref="NpgsqlConnection">Connection</see> and builds a
        /// <see cref="NpgsqlDataReader">NpgsqlDataReader</see>.
        /// </summary>
        /// <returns>A <see cref="NpgsqlDataReader">NpgsqlDataReader</see> object.</returns>
        public new NpgsqlDataReader ExecuteReader()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ExecuteReader");

            return(ExecuteReader(CommandBehavior.Default));
        }
コード例 #6
0
 /// <summary>
 /// Gets a value indicating whether a <see cref="NpgsqlParameter">NpgsqlParameter</see> with the specified parameter name exists in the collection.
 /// </summary>
 /// <param name="parameterName">The name of the <see cref="NpgsqlParameter">NpgsqlParameter</see> object to find.</param>
 /// <returns><b>true</b> if the collection contains the parameter; otherwise, <b>false</b>.</returns>
 public override bool Contains(string parameterName)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Contains", parameterName);
     return(IndexOf(parameterName) != -1);
 }
コード例 #7
0
 /// <summary>
 /// Adds a <see cref="NpgsqlParameter">NpgsqlParameter</see> to the <see cref="NpgsqlParameterCollection">NpgsqlParameterCollection</see> given the parameter name and the data type.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="parameterType">One of the DbType values.</param>
 /// <returns>The index of the new <see cref="NpgsqlParameter">NpgsqlParameter</see> object.</returns>
 public NpgsqlParameter Add(string parameterName, NpgsqlDbType parameterType)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Add", parameterName, parameterType);
     return(this.Add(new NpgsqlParameter(parameterName, parameterType)));
 }
コード例 #8
0
        /// <summary>
        /// Process this.commandText, trimming each distinct command and substituting paramater
        /// tokens.
        /// </summary>
        /// <param name="prepare"></param>
        /// <returns>UTF8 encoded command ready to be sent to the backend.</returns>
        private byte[] GetCommandText(bool prepare)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetCommandText");

            MemoryStream commandBuilder = new MemoryStream();

            if (commandType == CommandType.TableDirect)
            {
                foreach (var table in commandText.Split(';'))
                {
                    if (table.Trim().Length == 0)
                    {
                        continue;
                    }

                    commandBuilder
                    .WriteString("SELECT * FROM ")
                    .WriteString(table)
                    .WriteString(";");
                }
            }
            else if (commandType == CommandType.StoredProcedure)
            {
                if (!prepare && !functionChecksDone)
                {
                    functionNeedsColumnListDefinition = Parameters.Count != 0 && CheckFunctionNeedsColumnDefinitionList();

                    functionChecksDone = true;
                }

                commandBuilder.WriteString("SELECT * FROM ");

                if (commandText.TrimEnd().EndsWith(")"))
                {
                    if (!AppendCommandReplacingParameterValues(commandBuilder, commandText, prepare, false))
                    {
                        throw new NpgsqlException("Multiple queries not supported for stored procedures");
                    }
                }
                else
                {
                    commandBuilder
                    .WriteString(commandText)
                    .WriteBytes((byte)ASCIIBytes.ParenLeft);

                    if (prepare)
                    {
                        AppendParameterPlaceHolders(commandBuilder);
                    }
                    else
                    {
                        AppendParameterValues(commandBuilder);
                    }

                    commandBuilder.WriteBytes((byte)ASCIIBytes.ParenRight);
                }

                if (!prepare && functionNeedsColumnListDefinition)
                {
                    AddFunctionColumnListSupport(commandBuilder);
                }
            }
            else
            {
                if (!AppendCommandReplacingParameterValues(commandBuilder, commandText, prepare, !prepare))
                {
                    throw new NpgsqlException("Multiple queries not supported for prepared statements");
                }
            }

            return(commandBuilder.ToArray());
        }
コード例 #9
0
 /// <summary>
 /// Creates and returns a <see cref="System.Data.Common.DbCommand">DbCommand</see>
 /// object associated with the <see cref="System.Data.Common.DbConnection">IDbConnection</see>.
 /// </summary>
 /// <returns>A <see cref="System.Data.Common.DbCommand">DbCommand</see> object.</returns>
 protected override DbCommand CreateDbCommand()
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "CreateDbCommand");
     return(CreateCommand());
 }
コード例 #10
0
 /// <summary>
 /// Adds a <see cref="NpgsqlParameter">NpgsqlParameter</see> to the <see cref="NpgsqlParameterCollection">NpgsqlParameterCollection</see> given the specified parameter name and value.
 /// </summary>
 /// <param name="parameterName">The name of the <see cref="NpgsqlParameter">NpgsqlParameter</see>.</param>
 /// <param name="value">The Value of the <see cref="NpgsqlParameter">NpgsqlParameter</see> to add to the collection.</param>
 /// <returns>The paramater that was added.</returns>
 public NpgsqlParameter AddWithValue(string parameterName, object value)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "AddWithValue", parameterName, value);
     return(this.Add(new NpgsqlParameter(parameterName, value)));
 }
コード例 #11
0
 /// <summary>
 /// Begins a database transaction.
 /// </summary>
 /// <returns>A <see cref="NpgsqlTransaction">NpgsqlTransaction</see>
 /// object representing the new transaction.</returns>
 /// <remarks>
 /// Currently there's no support for nested transactions.
 /// </remarks>
 public new NpgsqlTransaction BeginTransaction()
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "BeginTransaction");
     return(this.BeginTransaction(IsolationLevel.ReadCommitted));
 }
コード例 #12
0
        /// <summary>
        /// Begins a database transaction with the specified isolation level.
        /// </summary>
        /// <param name="isolationLevel">The <see cref="System.Data.IsolationLevel">isolation level</see> under which the transaction should run.</param>
        /// <returns>An <see cref="System.Data.Common.DbTransaction">DbTransaction</see>
        /// object representing the new transaction.</returns>
        /// <remarks>
        /// Currently the IsolationLevel ReadCommitted and Serializable are supported by the PostgreSQL backend.
        /// There's no support for nested transactions.
        /// </remarks>
        protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "BeginDbTransaction", isolationLevel);

            return(BeginTransaction(isolationLevel));
        }
コード例 #13
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="selectCommand"></param>
 public NpgsqlDataAdapter(NpgsqlCommand selectCommand)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);
     SelectCommand = selectCommand;
 }
コード例 #14
0
 /// <summary>
 /// Returns an enumerator that can iterate through the collection.
 /// </summary>
 /// <returns>An <see cref="System.Collections.IEnumerator">IEnumerator</see> that can be used to iterate through the collection.</returns>
 public override IEnumerator GetEnumerator()
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetEnumerator");
     return(this.InternalList.GetEnumerator());
 }
コード例 #15
0
 /// <summary>
 /// Adds a <see cref="NpgsqlParameter">NpgsqlParameter</see> to the <see cref="NpgsqlParameterCollection">NpgsqlParameterCollection</see> with the parameter name, the data type, the column length, and the source column name.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="parameterType">One of the DbType values.</param>
 /// <param name="size">The length of the column.</param>
 /// <param name="sourceColumn">The name of the source column.</param>
 /// <returns>The index of the new <see cref="NpgsqlParameter">NpgsqlParameter</see> object.</returns>
 public NpgsqlParameter Add(string parameterName, NpgsqlDbType parameterType, int size, string sourceColumn)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Add", parameterName, parameterType, size, sourceColumn);
     return(this.Add(new NpgsqlParameter(parameterName, parameterType, size, sourceColumn)));
 }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the NpgsqlParameterCollection class.
 /// </summary>
 internal NpgsqlParameterCollection()
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);
     InvalidateHashLookups();
 }
コード例 #17
0
 /// <summary>
 /// Removes the specified <see cref="NpgsqlParameter">NpgsqlParameter</see> from the collection using the parameter name.
 /// </summary>
 /// <param name="parameterName">The name of the <see cref="NpgsqlParameter">NpgsqlParameter</see> object to retrieve.</param>
 public override void RemoveAt(string parameterName)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "RemoveAt", parameterName);
     RemoveAt(this.IndexOf(parameterName));
 }
コード例 #18
0
 internal static void LogStringWritten(string theString)
 {
     NpgsqlEventLog.LogMsg("Log_StringWritten", LogLevel.Debug, theString);
 }
コード例 #19
0
        public NpgsqlPasswordPacket(byte[] password)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME);

            this.password = password;
        }