コード例 #1
0
        /// <summary>
        /// Create a new IngresConnectionStringBuilder with
        /// an initial connection string.
        /// </summary>
        /// <param name="connectionString"></param>
        public IngresConnectionStringBuilder(string connectionString)
        {
            _items = (DictionaryEntry[])
                     ConnectStringConfig.ConnectBuilderKeywords.Clone();

            this.ConnectionString = connectionString;

            _connectStringConfig =
                ConnectStringConfig.ParseConnectionString(connectionString);
        }
コード例 #2
0
ファイル: connection.cs プロジェクト: GunterMueller/Ingres
		/// <summary>
		/// Returns a new Connection object and a cloned connection string.
		/// </summary>
		/// <returns></returns>
		public object Clone()
		{
			IngresConnection newConn = new IngresConnection();
			newConn.ConnectionString =
				ConnectStringConfig.ToConnectionString(this.config);
			// overlay the connection string with the sanitized version
			// if the old connection had been openned.
			newConn._connectionString= this._connectionString;

			return newConn;
		}
コード例 #3
0
ファイル: connection.cs プロジェクト: GunterMueller/Ingres
		/// <summary>
		/// Release allocated resources of the Command and base Component.
		/// </summary>
		/// <param name="disposing">
		/// true if object is being explicitly disposed of, not finalized.
		/// false if method is called by runtime from inside the finalizer.
		/// </param>
		protected override void Dispose(bool disposing)
		{
			/*if disposing == true  Object is being explicitly disposed of, not finalized
			  if disposing == false then method called by runtime from inside the
									finalizer and we should not reference other 
									objects. */
			lock(this)
			{
				try
				{
					if (disposing)
					{
						Close();
						_connectionString = null;
						config                = null;
					}
				}
				finally
				{
					base.Dispose(disposing);  // let component base do its cleanup
				}
			}
		}  // Dispose
コード例 #4
0
        private int TryGetOrdinal(String keyword)
        {
            int i = ConnectStringConfig.TryGetOrdinal(keyword);

            return(i);
        }
コード例 #5
0
        /// <summary>
        /// Get/set the value associated with the specified key.
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public override object this [String keyword]
        {
            // Look up the ordinal for and return
            // the value at that position.
            get
            {
                int i = GetOrdinal(keyword);
                return(_items[i].Value);
            }
            set
            {
                int i = GetOrdinal(keyword);

                if (value == null)
                {
                    this.Remove(keyword);
                    return;
                }

                Object nativeValue = value;                  // assume no conversion needed

                TypeCode sourceTypeCode = Type.GetTypeCode(value.GetType());
                Type     targetType     =
                    ConnectStringConfig.ConnectBuilderKeywords[i].Value.GetType();
                TypeCode targetTypeCode = Type.GetTypeCode(targetType);

                if (targetTypeCode != sourceTypeCode)
                {
                    switch (targetTypeCode)
                    {
                    case TypeCode.Int32:
                        nativeValue = Int32.Parse(value.ToString());
                        break;

                    case TypeCode.Boolean:
                        String valueString = value.ToString().Trim();
                        String valueLower  = ToInvariantLower(valueString);

                        // Catch yes/no literals that Boolean.Parse doesn't
                        if (valueLower == "yes" || valueLower == "1")
                        {
                            nativeValue = true;
                            value       = "true";
                            break;
                        }
                        if (valueLower == "no" || valueLower == "0")
                        {
                            nativeValue = false;
                            value       = "false";
                            break;
                        }
                        nativeValue = Boolean.Parse(valueString);
                        break;

                    case TypeCode.String:
                        nativeValue = value.ToString();
                        break;

                    default:
                        throw new System.InvalidOperationException(
                                  "IngresConnectionStringBuilder internal error: " +
                                  "unexpected Type for keyword '" + keyword + "'.");
                    }             // end switch
                }                 // end if (targetTypeCode != sourceTypeCode)

                string connectionString = keyword + "=" +
                                          (value != null ? value.ToString() : "");
                ConnectStringConfig connectStringConfig =
                    ConnectStringConfig.ParseConnectionString(connectionString);
                if (connectStringConfig.Count > 1)
                {
                    throw new ArgumentException("Invalid keyword/value pair: '" +
                                                connectionString + "'.");
                }

                base[_items[i].Key.ToString()] = nativeValue;                  // Standardize key
                _items[i].Value = nativeValue;
            }
        }