private ColumnDefinitionPayload(string name, CharacterSet characterSet, int columnLength, ColumnType columnType, ColumnFlags columnFlags)
 {
     Name = name;
     CharacterSet = characterSet;
     ColumnLength = columnLength;
     ColumnType = columnType;
     ColumnFlags = columnFlags;
 }
Example #2
0
 public override double?Real64Null(string name, ColumnFlags flags = 0)
 {
     Mediator.Column = Mediator.Table.BindColumn(Mediator.PropertyName, name, new PgDbType(typeof(double?)), flags | Mediator.ColumnFlags | ColumnFlags.Nullable);
     return(default(double?));
 }
Example #3
0
 public override long Int64(string name, ColumnFlags flags = 0)
 {
     Mediator.Column = Mediator.Table.BindColumn(Mediator.PropertyName, name, new PgDbType(typeof(long)), flags | Mediator.ColumnFlags);
     return(default(long));
 }
Example #4
0
		public void SetTypeAndFlags(MySqlDbType type, ColumnFlags flags)
		{
			colFlags = flags;
			mySqlDbType = type;

			if (String.IsNullOrEmpty(TableName) && String.IsNullOrEmpty(RealTableName) &&
				IsBinary && driver.Settings.FunctionsReturnString)
			{
				CharacterSetIndex = driver.ConnectionCharSetIndex;
			}

			// if our type is an unsigned number, then we need
			// to bump it up into our unsigned types
			// we're trusting that the server is not going to set the UNSIGNED
			// flag unless we are a number
			if (IsUnsigned)
			{
				switch (type)
				{
					case MySqlDbType.Byte:
						mySqlDbType = MySqlDbType.UByte;
						return;
					case MySqlDbType.Int16:
						mySqlDbType = MySqlDbType.UInt16;
						return;
					case MySqlDbType.Int24:
						mySqlDbType = MySqlDbType.UInt24;
						return;
					case MySqlDbType.Int32:
						mySqlDbType = MySqlDbType.UInt32;
						return;
					case MySqlDbType.Int64:
						mySqlDbType = MySqlDbType.UInt64;
						return;
				}
			}

			if (IsBlob)
			{
				// handle blob to UTF8 conversion if requested.  This is only activated
				// on binary blobs
				if (IsBinary && driver.Settings.TreatBlobsAsUTF8)
				{
					bool convertBlob = false;
					Regex includeRegex = driver.Settings.GetBlobAsUTF8IncludeRegex();
					Regex excludeRegex = driver.Settings.GetBlobAsUTF8ExcludeRegex();
					if (includeRegex != null && includeRegex.IsMatch(ColumnName))
						convertBlob = true;
					else if (includeRegex == null && excludeRegex != null &&
						!excludeRegex.IsMatch(ColumnName))
						convertBlob = true;

					if (convertBlob)
					{
						binaryOk = false;
						Encoding = System.Text.Encoding.GetEncoding("UTF-8");
						charSetIndex = -1;  // lets driver know we are in charge of encoding
						maxLength = 4;
					}
				}

				if (!IsBinary)
				{
					if (type == MySqlDbType.TinyBlob)
						mySqlDbType = MySqlDbType.TinyText;
					else if (type == MySqlDbType.MediumBlob)
						mySqlDbType = MySqlDbType.MediumText;
					else if (type == MySqlDbType.Blob)
						mySqlDbType = MySqlDbType.Text;
					else if (type == MySqlDbType.LongBlob)
						mySqlDbType = MySqlDbType.LongText;
				}
			}

			// now determine if we really should be binary
			if (driver.Settings.RespectBinaryFlags)
				CheckForExceptions();

			if (Type == MySqlDbType.String && CharacterLength == 36 && !driver.Settings.OldGuids)
				mySqlDbType = MySqlDbType.Guid;

			if (!IsBinary) return;

			if (driver.Settings.RespectBinaryFlags)
			{
				if (type == MySqlDbType.String)
					mySqlDbType = MySqlDbType.Binary;
				else if (type == MySqlDbType.VarChar ||
						 type == MySqlDbType.VarString)
					mySqlDbType = MySqlDbType.VarBinary;
			}

			if (CharacterSetIndex == 63)
				CharacterSetIndex = driver.ConnectionCharSetIndex;

			if (Type == MySqlDbType.Binary && ColumnLength == 16 && driver.Settings.OldGuids)
				mySqlDbType = MySqlDbType.Guid;
		}
Example #5
0
 /// <summary>
 /// プロパティに結びつく列定義として初期化する
 /// </summary>
 /// <param name="environment">この列定義がベースとするDB接続環境</param>
 /// <param name="instance">プロパティを直接保持するオブジェクト</param>
 /// <param name="property">プロパティ情報</param>
 /// <param name="table">この列が所属する<see cref="ITable"/></param>
 /// <param name="name">DB上の列名</param>
 /// <param name="dbType">DB上の型</param>
 /// <param name="flags">列定義オプションフラグ</param>
 /// <param name="source">列を生成する元となった式</param>
 public Column(DbEnvironment environment, object instance, PropertyInfo property, ITable table, string name, IDbType dbType, ColumnFlags flags = 0, ElementCode source = null)
 {
     this.Environment = environment;
     this.Instance    = instance;
     this.Property    = property;
     this.Table       = table;
     this.Name        = name;
     this.DbType      = dbType;
     this.Flags       = flags;
     this.Source      = source;
 }
 private ColumnDefinitionPayload(string name, CharacterSet characterSet, int columnLength, ColumnType columnType, ColumnFlags columnFlags)
 {
     Name         = name;
     CharacterSet = characterSet;
     ColumnLength = columnLength;
     ColumnType   = columnType;
     ColumnFlags  = columnFlags;
 }
		private void SetFlag (ColumnFlags f, bool value)
		{
			if (value)
				flags |= f;
			else
				flags &= ~f;
		}
Example #8
0
 public override ColumnParameter GetParameter(ColumnFlags flags, int index)
 {
     return(ColumnParameter.None);
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnDefinition"/> class.
 /// For use when defining a new column.
 /// </summary>
 /// <param name="name">
 /// the name of the column to be defined
 /// </param>
 /// <param name="type">
 /// the type of the column to be defined
 /// </param>
 /// <param name="flags">
 /// the flags for the column to be defined
 /// </param>
 public ColumnDefinition(string name, Type type, ColumnFlags flags)
 {
     this.name  = name;
     this.type  = type;
     this.flags = flags;
 }
Example #10
0
        /// <summary>
        /// Converts <see cref="ColumndefGrbit"/> to <see cref="ColumnFlags"/>.
        /// </summary>
        /// <param name="grbitColumn">The grbit to convert.</param>
        /// <returns>A <see cref="ColumnFlags"/> value equivalent to <paramref name="grbitColumn"/>.</returns>
        private static ColumnFlags ColumnFlagsFromGrbits(ColumndefGrbit grbitColumn)
        {
            ColumnFlags flags = ColumnFlags.None;

            if ((grbitColumn & ColumndefGrbit.ColumnFixed) != 0)
            {
                flags = flags | ColumnFlags.Fixed;
            }

            if ((grbitColumn & (ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnTagged)) == 0)
            {
                flags = flags | ColumnFlags.Variable;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnTagged) != 0)
            {
                flags = flags | ColumnFlags.Sparse;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnNotNULL) != 0)
            {
                flags = flags | ColumnFlags.NonNull;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnVersion) != 0)
            {
                flags = flags | ColumnFlags.Version;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnAutoincrement) != 0)
            {
                flags = flags | ColumnFlags.AutoIncrement;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnUpdatable) != 0)
            {
                flags = flags | ColumnFlags.Updatable;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnMultiValued) != 0)
            {
                flags = flags | ColumnFlags.MultiValued;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnEscrowUpdate) != 0)
            {
                flags = flags | ColumnFlags.EscrowUpdate;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnFinalize) != 0)
            {
                flags = flags | ColumnFlags.Finalize;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnUserDefinedDefault) != 0)
            {
                flags = flags | ColumnFlags.UserDefinedDefault;
            }

            if ((grbitColumn & Server2003Grbits.ColumnDeleteOnZero) != 0)
            {
                flags = flags | ColumnFlags.DeleteOnZero;
            }

            return(flags);
        }
Example #11
0
 /// <summary>
 /// プロパティを<see cref="Column"/>に結びつける、プロパティの get 内から呼び出す必要がある
 /// </summary>
 /// <param name="getter">列定義シングルトンのプロパティ取得を呼び出す処理</param>
 /// <param name="flags">列定義のオプションフラグ</param>
 /// <param name="propertyName">プロパティ名</param>
 /// <returns>ダミー値</returns>
 protected char?As(Func <char?> getter, ColumnFlags flags = 0, [CallerMemberName] string propertyName = null)
 {
     Mediator.ColumnFlags  = flags;
     Mediator.PropertyName = propertyName;
     return(getter());
 }
Example #12
0
 /// <summary>
 /// 列を定義する、<see cref="CodeDb.Internal.Mediator.Table"/>の<see cref="ITable.BindColumn"/>を呼び出し結果の列定義が<see cref="CodeDb.Internal.Mediator.Column"/>に代入される
 /// </summary>
 /// <param name="name">DB上での列名</param>
 /// <param name="flags">列に対するオプションフラグ</param>
 /// <returns>ダミー値</returns>
 public abstract bool Bool(string name, ColumnFlags flags = 0);
Example #13
0
 /// <summary>
 /// 列を定義する、<see cref="CodeDb.Internal.Mediator.Table"/>の<see cref="ITable.BindColumn"/>を呼び出し結果の列定義が<see cref="CodeDb.Internal.Mediator.Column"/>に代入される
 /// </summary>
 /// <param name="name">DB上での列名</param>
 /// <param name="flags">列に対するオプションフラグ</param>
 /// <returns>ダミー値</returns>
 public abstract DateTime?DateTimeNull(string name, ColumnFlags flags = 0);
Example #14
0
 /// <summary>
 /// 列を定義する、<see cref="CodeDb.Internal.Mediator.Table"/>の<see cref="ITable.BindColumn"/>を呼び出し結果の列定義が<see cref="CodeDb.Internal.Mediator.Column"/>に代入される
 /// </summary>
 /// <param name="name">DB上での列名</param>
 /// <param name="flags">列に対するオプションフラグ</param>
 /// <returns>ダミー値</returns>
 public abstract DateTime[] DateTimeArray(string name, ColumnFlags flags = 0);
Example #15
0
		public void SetTypeAndFlags(MySqlDbType type, ColumnFlags flags) {
			this.colFlags = flags;
			this.mySqlDbType = type;
			if ((string.IsNullOrEmpty(this.TableName) && string.IsNullOrEmpty(this.RealTableName)) && this.connection.Settings.FunctionsReturnString) {
				this.mySqlDbType = MySqlDbType.VarString;
				this.CharacterSetIndex = this.connection.driver.ConnectionCharSetIndex;
				this.binaryOk = false;
			}
			if (this.IsUnsigned) {
				switch (type) {
					case MySqlDbType.Byte:
						this.mySqlDbType = MySqlDbType.UByte;
						return;

					case MySqlDbType.Int16:
						this.mySqlDbType = MySqlDbType.UInt16;
						return;

					case MySqlDbType.Int32:
						this.mySqlDbType = MySqlDbType.UInt32;
						return;

					case MySqlDbType.Int64:
						this.mySqlDbType = MySqlDbType.UInt64;
						return;

					case MySqlDbType.Int24:
						this.mySqlDbType = MySqlDbType.UInt24;
						return;
				}
			}
			if (this.IsBlob) {
				if (this.IsBinary && this.connection.Settings.TreatBlobsAsUTF8) {
					bool flag = false;
					Regex regex = this.connection.Settings.BlobAsUTF8IncludeRegex;
					Regex regex2 = this.connection.Settings.BlobAsUTF8ExcludeRegex;
					if ((regex != null) && regex.IsMatch(this.ColumnName)) {
						flag = true;
					} else if (((regex == null) && (regex2 != null)) && !regex2.IsMatch(this.ColumnName)) {
						flag = true;
					}
					if (flag) {
						this.binaryOk = false;
						this.Encoding = System.Text.Encoding.GetEncoding("UTF-8");
						this.charSetIndex = -1;
						this.maxLength = 4;
					}
				}
				if (!this.IsBinary) {
					if (type == MySqlDbType.TinyBlob) {
						this.mySqlDbType = MySqlDbType.TinyText;
					} else if (type == MySqlDbType.MediumBlob) {
						this.mySqlDbType = MySqlDbType.MediumText;
					} else if (type == MySqlDbType.Blob) {
						this.mySqlDbType = MySqlDbType.Text;
					} else if (type == MySqlDbType.LongBlob) {
						this.mySqlDbType = MySqlDbType.LongText;
					}
				}
			}
			if (this.connection.Settings.RespectBinaryFlags) {
				this.CheckForExceptions();
			}
			if (this.IsBinary) {
				if (this.connection.Settings.RespectBinaryFlags) {
					if (type == MySqlDbType.String) {
						this.mySqlDbType = MySqlDbType.Binary;
					} else if ((type == MySqlDbType.VarChar) || (type == MySqlDbType.VarString)) {
						this.mySqlDbType = MySqlDbType.VarBinary;
					}
				}
				if (this.CharacterSetIndex == 0x3f) {
					this.CharacterSetIndex = this.connection.driver.ConnectionCharSetIndex;
				}
			}
		}
Example #16
0
        public void SetTypeAndFlags(MySqlDbType type, ColumnFlags flags)
        {
            colFlags = flags;
            mySqlDbType = type;

            if (String.IsNullOrEmpty(TableName) && String.IsNullOrEmpty(RealTableName) &&
                IsBinary && driver.Settings.FunctionsReturnString)
            {
                CharacterSetIndex = driver.ConnectionCharSetIndex;
            }

            // if our type is an unsigned number, then we need
            // to bump it up into our unsigned types
            // we're trusting that the server is not going to set the UNSIGNED
            // flag unless we are a number
            if (IsUnsigned)
            {
                switch (type)
                {
                    case MySqlDbType.Byte:
                        mySqlDbType = MySqlDbType.UByte;
                        return;
                    case MySqlDbType.Int16:
                        mySqlDbType = MySqlDbType.UInt16;
                        return;
                    case MySqlDbType.Int24:
                        mySqlDbType = MySqlDbType.UInt24;
                        return;
                    case MySqlDbType.Int32:
                        mySqlDbType = MySqlDbType.UInt32;
                        return;
                    case MySqlDbType.Int64:
                        mySqlDbType = MySqlDbType.UInt64;
                        return;
                }
            }

            if (IsBlob)
            {
                // handle blob to UTF8 conversion if requested.  This is only activated
                // on binary blobs
                if (IsBinary && driver.Settings.TreatBlobsAsUTF8)
                {
                    bool convertBlob = false;
                    Regex includeRegex = driver.Settings.GetBlobAsUTF8IncludeRegex();
                    Regex excludeRegex = driver.Settings.GetBlobAsUTF8ExcludeRegex();
                    if (includeRegex != null && includeRegex.IsMatch(ColumnName))
                        convertBlob = true;
                    else if (includeRegex == null && excludeRegex != null &&
                        !excludeRegex.IsMatch(ColumnName))
                        convertBlob = true;

                    if (convertBlob)
                    {
                        binaryOk = false;
                        Encoding = System.Text.Encoding.GetEncoding("UTF-8");
                        charSetIndex = -1;  // lets driver know we are in charge of encoding
                        maxLength = 4;
                    }
                }

                if (!IsBinary)
                {
                    if (type == MySqlDbType.TinyBlob)
                        mySqlDbType = MySqlDbType.TinyText;
                    else if (type == MySqlDbType.MediumBlob)
                        mySqlDbType = MySqlDbType.MediumText;
                    else if (type == MySqlDbType.Blob)
                        mySqlDbType = MySqlDbType.Text;
                    else if (type == MySqlDbType.LongBlob)
                        mySqlDbType = MySqlDbType.LongText;
                }
            }

            // now determine if we really should be binary
            if (driver.Settings.RespectBinaryFlags)
                CheckForExceptions();

            if (Type == MySqlDbType.String && CharacterLength == 36 && !driver.Settings.OldGuids)
                mySqlDbType = MySqlDbType.Guid;

            if (!IsBinary) return;

            if (driver.Settings.RespectBinaryFlags)
            {
                if (type == MySqlDbType.String)
                    mySqlDbType = MySqlDbType.Binary;
                else if (type == MySqlDbType.VarChar ||
                         type == MySqlDbType.VarString)
                    mySqlDbType = MySqlDbType.VarBinary;
            }

            if (CharacterSetIndex == 63)
                CharacterSetIndex = driver.ConnectionCharSetIndex;

            if (Type == MySqlDbType.Binary && ColumnLength == 16 && driver.Settings.OldGuids)
                mySqlDbType = MySqlDbType.Guid;
        }
Example #17
0
 public abstract ColumnParameter GetParameter(ColumnFlags flags, int index);
Example #18
0
 /// <summary>
 /// 列を定義する、<see cref="CodeDb.Internal.Mediator.Table"/>の<see cref="ITable.BindColumn"/>を呼び出し結果の列定義が<see cref="CodeDb.Internal.Mediator.Column"/>に代入される
 /// </summary>
 /// <param name="name">DB上での列名</param>
 /// <param name="flags">列に対するオプションフラグ</param>
 /// <returns>ダミー値</returns>
 public abstract DateTime DateTime(string name, ColumnFlags flags = 0);
        public static Token MatchToken(string name, out TokenType id, out ColumnFlags flags)
        {
            name = name.ToLowerInvariant();

            for (byte i = 0; i < _Tokens.Length; i++)
            {
                var token = _Tokens[i];
                if (token == null)
                {
                    continue;
                }

                if (token.NameDirectValue != null &&
                    name == token.NameDirectValue.ToLowerInvariant())
                {
                    id    = (TokenType)i;
                    flags = ColumnFlags.None;
                    return(token);
                }

                if (token.NameDirectFixedArray != null &&
                    name == token.NameDirectFixedArray.ToLowerInvariant())
                {
                    id    = (TokenType)i;
                    flags = ColumnFlags.FIXED_ARRAY;
                    return(token);
                }

                if (token.NameDirectArray != null &&
                    name == token.NameDirectArray.ToLowerInvariant())
                {
                    id    = (TokenType)i;
                    flags = ColumnFlags.EARRAY;
                    return(token);
                }

                if (token.NameIndirectValue != null &&
                    name == token.NameIndirectValue.ToLowerInvariant())
                {
                    id    = (TokenType)i;
                    flags = ColumnFlags.INDIRECT;
                    return(token);
                }

                if (token.NameIndirectFixedArray != null &&
                    name == token.NameIndirectFixedArray.ToLowerInvariant())
                {
                    id    = (TokenType)i;
                    flags = ColumnFlags.INDIRECT | ColumnFlags.FIXED_ARRAY;
                    return(token);
                }

                if (token.NameIndirectArray != null &&
                    name == token.NameIndirectArray.ToLowerInvariant())
                {
                    id    = (TokenType)i;
                    flags = ColumnFlags.INDIRECT | ColumnFlags.EARRAY;
                    return(token);
                }
            }

            throw new ArgumentException("token not found", "name");
        }
 public ColumnAttribute(int value, ColumnFlags flags = ColumnFlags.Default)
 {
     Value = value;
     Flags = flags;
 }
Example #21
0
        /// <summary>
        /// Converts <see cref="ColumndefGrbit"/> to <see cref="ColumnFlags"/>.
        /// </summary>
        /// <param name="grbitColumn">The grbit to convert.</param>
        /// <returns>A <see cref="ColumnFlags"/> value equivalent to <paramref name="grbitColumn"/>.</returns>
        private static ColumnFlags ColumnFlagsFromGrbits(ColumndefGrbit grbitColumn)
        {
            ColumnFlags flags = ColumnFlags.None;

            if ((grbitColumn & ColumndefGrbit.ColumnFixed) != 0)
            {
                flags = flags | ColumnFlags.Fixed;
            }

            if ((grbitColumn & (ColumndefGrbit.ColumnFixed | ColumndefGrbit.ColumnTagged)) == 0)
            {
                flags = flags | ColumnFlags.Variable;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnTagged) != 0)
            {
                flags = flags | ColumnFlags.Sparse;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnNotNULL) != 0)
            {
                flags = flags | ColumnFlags.NonNull;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnVersion) != 0)
            {
                flags = flags | ColumnFlags.Version;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnAutoincrement) != 0)
            {
                flags = flags | ColumnFlags.AutoIncrement;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnUpdatable) != 0)
            {
                flags = flags | ColumnFlags.Updatable;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnMultiValued) != 0)
            {
                flags = flags | ColumnFlags.MultiValued;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnEscrowUpdate) != 0)
            {
                flags = flags | ColumnFlags.EscrowUpdate;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnFinalize) != 0)
            {
                flags = flags | ColumnFlags.Finalize;
            }

            if ((grbitColumn & ColumndefGrbit.ColumnUserDefinedDefault) != 0)
            {
                flags = flags | ColumnFlags.UserDefinedDefault;
            }

            if ((grbitColumn & Server2003Grbits.ColumnDeleteOnZero) != 0)
            {
                flags = flags | ColumnFlags.DeleteOnZero;
            }

            return flags;
        }
Example #22
0
 private ColumnDefinitionPayload(ResizableArraySegment <byte> originalData, CharacterSet characterSet, uint columnLength, ColumnType columnType, ColumnFlags columnFlags, byte decimals)
 {
     OriginalData = originalData;
     CharacterSet = characterSet;
     ColumnLength = columnLength;
     ColumnType   = columnType;
     ColumnFlags  = columnFlags;
     Decimals     = decimals;
 }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColumnDefinition"/> class. 
 /// For use when defining a new column.
 /// </summary>
 /// <param name="name">
 /// the name of the column to be defined
 /// </param>
 /// <param name="type">
 /// the type of the column to be defined
 /// </param>
 /// <param name="flags">
 /// the flags for the column to be defined
 /// </param>
 public ColumnDefinition(string name, Type type, ColumnFlags flags)
 {
     this.name = name;
     this.type = type;
     this.flags = flags;
 }
Example #24
0
 internal Column(int id, string name, ColumnFlags flags)
 {
     Id         = id;
     Name       = name;
     this.flags = flags;
 }
Example #25
0
 /// <summary>
 /// Converts <see cref="ColumnFlags"/> to a <see cref="ColumndefGrbit"/>, suitable for ESE function calls.
 /// </summary>
 /// <param name="columnFlags">A <see cref="ColumnFlags"/> value.</param>
 /// <returns>A ColumndefGrbit suitable for function calls.</returns>
 internal static ColumndefGrbit ColumndefGrbitFromColumnFlags(ColumnFlags columnFlags)
 {
     return((ColumndefGrbit)columnFlags);
 }
Example #26
0
 public override DateTime DateTime(string name, ColumnFlags flags = 0)
 {
     Mediator.Column = Mediator.Table.BindColumn(Mediator.PropertyName, name, new PgDbType(typeof(DateTime)), flags | Mediator.ColumnFlags);
     return(default(DateTime));
 }
Example #27
0
 /// <summary>
 /// コンストラクタ、全要素を指定して初期化する
 /// </summary>
 /// <param name="name">DB上での列名</param>
 /// <param name="dbType">列の型</param>
 /// <param name="flags">列のオプションフラグ</param>
 public PgColumnDef(string name, PgDbType dbType, ColumnFlags flags)
 {
     this.Name   = name;
     this.DbType = dbType;
     this.Flags  = flags;
 }
Example #28
0
 public override double[] Real64Array(string name, ColumnFlags flags = 0)
 {
     Mediator.Column = Mediator.Table.BindColumn(Mediator.PropertyName, name, new PgDbType(typeof(double[])), flags | Mediator.ColumnFlags);
     return(default(double[]));
 }
Example #29
0
 private bool GetFlag(ColumnFlags f)
 {
     return((flags & f) != 0);
 }
Example #30
0
        public void SetTypeAndFlags(MySqlDbType type, ColumnFlags flags)
        {
            this.colFlags    = flags;
            this.mySqlDbType = type;
            if ((string.IsNullOrEmpty(this.TableName) && string.IsNullOrEmpty(this.RealTableName)) && this.connection.Settings.FunctionsReturnString)
            {
                this.mySqlDbType       = MySqlDbType.VarString;
                this.CharacterSetIndex = this.connection.driver.ConnectionCharSetIndex;
                this.binaryOk          = false;
            }
            if (this.IsUnsigned)
            {
                switch (type)
                {
                case MySqlDbType.Byte:
                    this.mySqlDbType = MySqlDbType.UByte;
                    return;

                case MySqlDbType.Int16:
                    this.mySqlDbType = MySqlDbType.UInt16;
                    return;

                case MySqlDbType.Int32:
                    this.mySqlDbType = MySqlDbType.UInt32;
                    return;

                case MySqlDbType.Int64:
                    this.mySqlDbType = MySqlDbType.UInt64;
                    return;

                case MySqlDbType.Int24:
                    this.mySqlDbType = MySqlDbType.UInt24;
                    return;
                }
            }
            if (this.IsBlob)
            {
                if (this.IsBinary && this.connection.Settings.TreatBlobsAsUTF8)
                {
                    bool  flag   = false;
                    Regex regex  = this.connection.Settings.BlobAsUTF8IncludeRegex;
                    Regex regex2 = this.connection.Settings.BlobAsUTF8ExcludeRegex;
                    if ((regex != null) && regex.IsMatch(this.ColumnName))
                    {
                        flag = true;
                    }
                    else if (((regex == null) && (regex2 != null)) && !regex2.IsMatch(this.ColumnName))
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        this.binaryOk     = false;
                        this.Encoding     = System.Text.Encoding.GetEncoding("UTF-8");
                        this.charSetIndex = -1;
                        this.maxLength    = 4;
                    }
                }
                if (!this.IsBinary)
                {
                    if (type == MySqlDbType.TinyBlob)
                    {
                        this.mySqlDbType = MySqlDbType.TinyText;
                    }
                    else if (type == MySqlDbType.MediumBlob)
                    {
                        this.mySqlDbType = MySqlDbType.MediumText;
                    }
                    else if (type == MySqlDbType.Blob)
                    {
                        this.mySqlDbType = MySqlDbType.Text;
                    }
                    else if (type == MySqlDbType.LongBlob)
                    {
                        this.mySqlDbType = MySqlDbType.LongText;
                    }
                }
            }
            if (this.connection.Settings.RespectBinaryFlags)
            {
                this.CheckForExceptions();
            }
            if (this.IsBinary)
            {
                if (this.connection.Settings.RespectBinaryFlags)
                {
                    if (type == MySqlDbType.String)
                    {
                        this.mySqlDbType = MySqlDbType.Binary;
                    }
                    else if ((type == MySqlDbType.VarChar) || (type == MySqlDbType.VarString))
                    {
                        this.mySqlDbType = MySqlDbType.VarBinary;
                    }
                }
                if (this.CharacterSetIndex == 0x3f)
                {
                    this.CharacterSetIndex = this.connection.driver.ConnectionCharSetIndex;
                }
            }
        }
Example #31
0
        public PgDatabaseDef(NpgsqlConnection connection)
        {
            try {
                using (var cmd = connection.CreateCommand()) {
                    // データベース名の取得
                    cmd.CommandText = "SELECT * FROM current_catalog;";
                    using (var dr = cmd.ExecuteReader()) {
                        while (dr.Read())
                        {
                            this.Name = dr[0] as string;
                        }
                    }

                    // テーブル一覧と列の取得
                    var tables = new Dictionary <string, PgTableDef>();
                    cmd.CommandText = @"
SELECT
	table_name
	,column_name
	,ordinal_position
	,column_default
	,udt_name
FROM
	information_schema.columns
WHERE
	table_catalog=@0 AND table_schema='public'
ORDER BY
	table_name, ordinal_position
;
";
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@0", this.Name);
                    using (var dr = cmd.ExecuteReader()) {
                        while (dr.Read())
                        {
                            var         table_name       = dr[0] as string;
                            var         column_name      = dr[1] as string;
                            var         ordinal_position = dr[2] as string;
                            var         column_default   = dr[3] as string;
                            var         udt_name         = dr[4] as string;
                            ColumnFlags flags            = 0;
                            if (!string.IsNullOrEmpty(column_default))
                            {
                                if (column_default.StartsWith("nextval('"))
                                {
                                    flags |= ColumnFlags.Serial;
                                }
                                if (column_default == "CURRENT_TIMESTAMP")
                                {
                                    flags |= ColumnFlags.DefaultCurrentTimestamp;
                                }
                            }

                            PgTableDef tableDef;
                            if (!tables.TryGetValue(table_name, out tableDef))
                            {
                                tables[table_name] = tableDef = new PgTableDef(table_name);
                            }
                            tableDef.ColumnDefs.Add(new PgColumnDef(column_name, new PgDbType(udt_name), flags));
                        }
                    }

                    // プライマリキーとインデックス、ユニークキーの取得
                    cmd.CommandText = @"
SELECT
--	t.relname,
	i.relname AS index_name,
	ix.indisprimary AS is_primary_key,
	ix.indisunique AS is_unique_key,
	ix.indkey AS combination,
	att.attname AS column_name,
	att.attnum AS attnum,
	a.amname AS index_type 
FROM
	pg_class t 
	INNER JOIN pg_index ix ON ix.indrelid=t.oid 
	INNER JOIN pg_class i ON i.oid=ix.indexrelid 
	INNER JOIN pg_am a ON a.oid=i.relam 
	INNER JOIN pg_attribute att ON att.attrelid=t.oid AND att.attnum=ANY(ix.indkey) 
WHERE
	t.relname=@0 AND t.relkind='r';
";
                    foreach (var table in tables.Values)
                    {
                        var indicesDic = new Dictionary <string, ConstraintInfo>();
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@0", table.Name);
                        using (var dr = cmd.ExecuteReader()) {
                            while (dr.Read())
                            {
                                var index_name     = dr[0] as string;
                                var is_primary_key = (bool)dr[1];
                                var is_unique_key  = (bool)dr[2];
                                var combination    = dr[3] as short[];
                                var column_name    = dr[4] as string;
                                var attnum         = Convert.ToInt32(dr[5]);
                                var index_type     = dr[6] as string;

                                ConstraintInfo info;
                                if (!indicesDic.TryGetValue(index_name, out info))
                                {
                                    indicesDic[index_name] = info = new ConstraintInfo(index_name, is_primary_key, is_unique_key, combination, index_type);
                                }
                                var column = (from c in table.ColumnDefs where c.Name == column_name select c).FirstOrDefault();
                                info.Columns[attnum] = column ?? throw new ApplicationException();
                            }
                        }
                        var indices = new List <Tuple <string, string, PgColumnDef[]> >();
                        var uniques = new List <Tuple <string, PgColumnDef[]> >();
                        foreach (var kvp in indicesDic)
                        {
                            var info    = kvp.Value;
                            var columns = (from i in info.Combination select info.Columns[i]).ToArray();
                            if (info.IsPrimaryKey)
                            {
                                table.PrimaryKey = new PrimaryKeyDef(kvp.Key, columns);
                            }
                            else if (info.IsUniqueKey)
                            {
                                uniques.Add(new Tuple <string, PgColumnDef[]>(kvp.Key, columns));
                            }
                            else
                            {
                                indices.Add(new Tuple <string, string, PgColumnDef[]>(kvp.Key, info.IndexType, columns));
                            }
                        }
                        table.Indices = (from i in indices select new IndexDef(i.Item1, i.Item2 == "gin" ? IndexFlags.Gin : 0, i.Item3)).ToArray();
                        table.Uniques = (from u in uniques select new UniqueDef(u.Item1, u.Item2)).ToArray();
                    }

                    this.Tables = (from t in tables.Values select t).ToArray();
                }
            } catch (PostgresException ex) {
                throw new PgEnvironmentException(ex);
            }
        }
Example #32
0
        public void SetTypeAndFlags(MySqlDbType type, ColumnFlags flags)
        {
            this.colFlags    = flags;
            this.mySqlDbType = type;
            if (string.IsNullOrEmpty(this.TableName) && string.IsNullOrEmpty(this.RealTableName) && this.IsBinary && this.driver.Settings.FunctionsReturnString)
            {
                this.CharacterSetIndex = this.driver.ConnectionCharSetIndex;
            }
            if (this.IsUnsigned)
            {
                switch (type)
                {
                case MySqlDbType.Byte:
                    this.mySqlDbType = MySqlDbType.UByte;
                    return;

                case MySqlDbType.Int16:
                    this.mySqlDbType = MySqlDbType.UInt16;
                    return;

                case MySqlDbType.Int32:
                    this.mySqlDbType = MySqlDbType.UInt32;
                    return;

                case MySqlDbType.Int64:
                    this.mySqlDbType = MySqlDbType.UInt64;
                    return;

                case MySqlDbType.Int24:
                    this.mySqlDbType = MySqlDbType.UInt24;
                    return;
                }
            }
            if (this.IsBlob)
            {
                if (this.IsBinary && this.driver.Settings.TreatBlobsAsUTF8)
                {
                    bool  flag = false;
                    Regex blobAsUTF8IncludeRegex = this.driver.Settings.GetBlobAsUTF8IncludeRegex();
                    Regex blobAsUTF8ExcludeRegex = this.driver.Settings.GetBlobAsUTF8ExcludeRegex();
                    if (blobAsUTF8IncludeRegex != null && blobAsUTF8IncludeRegex.IsMatch(this.ColumnName))
                    {
                        flag = true;
                    }
                    else if (blobAsUTF8IncludeRegex == null && blobAsUTF8ExcludeRegex != null && !blobAsUTF8ExcludeRegex.IsMatch(this.ColumnName))
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        this.binaryOk     = false;
                        this.Encoding     = Encoding.GetEncoding("gbk");
                        this.charSetIndex = -1;
                        this.maxLength    = 4;
                    }
                }
                if (!this.IsBinary)
                {
                    if (type == MySqlDbType.TinyBlob)
                    {
                        this.mySqlDbType = MySqlDbType.TinyText;
                    }
                    else if (type == MySqlDbType.MediumBlob)
                    {
                        this.mySqlDbType = MySqlDbType.MediumText;
                    }
                    else if (type == MySqlDbType.Blob)
                    {
                        this.mySqlDbType = MySqlDbType.Text;
                    }
                    else if (type == MySqlDbType.LongBlob)
                    {
                        this.mySqlDbType = MySqlDbType.LongText;
                    }
                }
            }
            if (this.driver.Settings.RespectBinaryFlags)
            {
                this.CheckForExceptions();
            }
            if (this.Type == MySqlDbType.String && this.CharacterLength == 36 && !this.driver.Settings.OldGuids)
            {
                this.mySqlDbType = MySqlDbType.Guid;
            }
            if (!this.IsBinary)
            {
                return;
            }
            if (this.driver.Settings.RespectBinaryFlags)
            {
                if (type == MySqlDbType.String)
                {
                    this.mySqlDbType = MySqlDbType.Binary;
                }
                else if (type == MySqlDbType.VarChar || type == MySqlDbType.VarString)
                {
                    this.mySqlDbType = MySqlDbType.VarBinary;
                }
            }
            if (this.CharacterSetIndex == 63)
            {
                this.CharacterSetIndex = this.driver.ConnectionCharSetIndex;
            }
            if (this.Type == MySqlDbType.Binary && this.ColumnLength == 16 && this.driver.Settings.OldGuids)
            {
                this.mySqlDbType = MySqlDbType.Guid;
            }
        }
Example #33
0
        private static ActionResult <List <T> > DataRead <T>(string sql, object[] parameters, ColumnFlags flags)
        {
            var lt = new List <T>();

            try
            {
                DataTable dt = DbFactory.Execute().ExecuteTable(sql, CommandType.Text, parameters);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var            model      = (T)Assembly.Load("AutomaticTestingSystem").CreateInstance(typeof(T).FullName);
                        PropertyInfo[] properties = model.GetType().GetProperties();
                        foreach (var property in properties)
                        {
                            try
                            {
                                var attr = property.GetCustomAttribute <ColumnAttribute>();

                                if ((attr?.Flag & flags) != 0 && attr != null)
                                {
                                    property.SetValue(model, dr[attr.Name]);
                                }
                            }
                            catch { }
                        }

                        lt.Add(model);
                    }
                }
                return(ActionResult <List <T> > .SetSuccess("Access data successful.", lt));
            }
            catch (Exception e)
            {
                return(ActionResult <List <T> > .SetError(e.Message));
            }
        }
Example #34
0
 public Column BindColumn(string propertyName, string name, IDbType dbType, ColumnFlags flags = 0, ElementCode source = null)
 {
     return(null);
 }
		private bool GetFlag (ColumnFlags f)
		{
			return (flags & f) != 0;
		}
Example #36
0
        private void SetColumnMetaData(object compilationColumns, int hiddenColumns)
        {
            Debug.WriteLineIf(CLI.FnTrace.Enabled, "ManagedCommand.SetColumnMetaData");
            object[] descriptions = null;
            if (compilationColumns is object[])
            {
                descriptions = (object[])compilationColumns;
            }

            if (descriptions == null || descriptions.Length == 0)
            {
                columns = null;
                return;
            }

            bool hasKeyColumns = false;

            columns = new ColumnData[descriptions.Length];
            for (int i = 0; i < columns.Length; i++)
            {
                object[] description = (object[])descriptions[i];

                ColumnData column = new ColumnData();
                columns[i] = column;

                ColumnFlags flags = (ColumnFlags)description[11];

                column.columnName = (string)description[0];
                column.columnType = DataTypeInfo.MapDvType((BoxTag)description[1]);
                if (0 != (flags & ColumnFlags.CDF_XMLTYPE))
                {
                    Debug.WriteLineIf(SqlXml.Switch.TraceVerbose,
                                      String.Format("Set XML type for {0}", column.columnName));
                    column.columnType = DataTypeInfo.Xml;
                }
                if (column.columnType == null)
                {
                    throw new SystemException("Unknown data type");
                }
                column.bufferType = column.columnType.bufferType;

                column.columnSize = column.columnType.GetFieldSize((int)description[3]);
                column.precision  = (short)column.columnSize;
                column.scale      = (short)((int)description[2]);
                column.IsLong     = column.columnType.isLong;
                column.IsNullable = (0 != (int)description[4]);

                CLI.Updatable updatable = (CLI.Updatable)(int) description[5];
                column.IsReadOnly = (updatable == CLI.Updatable.SQL_ATTR_READONLY);

                column.IsAutoIncrement = (0 != (flags & ColumnFlags.CDF_AUTOINCREMENT));
                column.IsKey           = (0 != (flags & ColumnFlags.CDF_KEY));
                if (column.IsKey)
                {
                    hasKeyColumns = true;
                }

                column.IsHidden     = (i >= (columns.Length - hiddenColumns));
                column.IsRowVersion = (column.columnType == DataTypeInfo.Timestamp);
                // TODO: check for unique columns as well.
                column.IsUnique = false;

                column.baseCatalogName = (string)Values.NullIfZero(description[7]);
                column.baseColumnName  = (string)Values.NullIfZero(description[8]);
                column.baseSchemaName  = (string)Values.NullIfZero(description[9]);
                column.baseTableName   = (string)Values.NullIfZero(description[10]);

                if (column.baseTableName == null || column.baseTableName == "")
                {
                    column.IsExpression = true;
                }
                else
                {
                    column.IsExpression = false;
                }
            }

            if (uniqueRows && !hasKeyColumns)
            {
                uniqueRows = false;
            }
        }
Example #37
0
 /// <summary>
 /// 列を定義する、<see cref="CodeDb.Internal.Mediator.Table"/>の<see cref="ITable.BindColumn"/>を呼び出し結果の列定義が<see cref="CodeDb.Internal.Mediator.Column"/>に代入される
 /// </summary>
 /// <param name="name">DB上での列名</param>
 /// <param name="flags">列に対するオプションフラグ</param>
 /// <returns>ダミー値</returns>
 public abstract Guid?UuidNull(string name, ColumnFlags flags = 0);