コード例 #1
0
        private Column(DataRow schemaTableRow, bool includeKeyInfo, DatabaseInfo databaseInfo)
        {
            ordinal = (int)schemaTableRow["ColumnOrdinal"];

            // MySQL incorrectly uses one-based ordinals; see http://bugs.mysql.com/bug.php?id=61477.
            if (databaseInfo is MySqlInfo)
            {
                ordinal -= 1;
            }

            valueContainer = new ValueContainer(
                (string)schemaTableRow["ColumnName"],
                (Type)schemaTableRow["DataType"],
                databaseInfo.GetDbTypeString(schemaTableRow["ProviderType"]),
                (int)schemaTableRow["ColumnSize"],
                (bool)schemaTableRow["AllowDBNull"],
                databaseInfo);
            isIdentity = (databaseInfo is SqlServerInfo && (bool)schemaTableRow["IsIdentity"]) ||
                         (databaseInfo is MySqlInfo && (bool)schemaTableRow["IsAutoIncrement"]);
            isRowVersion = databaseInfo is SqlServerInfo && (bool)schemaTableRow["IsRowVersion"];
            if (includeKeyInfo)
            {
                isKey = (bool)schemaTableRow["IsKey"];
            }
        }
コード例 #2
0
        private Column( DataRow schemaTableRow, bool includeKeyInfo, DatabaseInfo databaseInfo )
        {
            ordinal = (int)schemaTableRow[ "ColumnOrdinal" ];

            // MySQL incorrectly uses one-based ordinals; see http://bugs.mysql.com/bug.php?id=61477.
            if( databaseInfo is MySqlInfo )
                ordinal -= 1;

            valueContainer = new ValueContainer(
                (string)schemaTableRow[ "ColumnName" ],
                (Type)schemaTableRow[ "DataType" ],
                databaseInfo.GetDbTypeString( schemaTableRow[ "ProviderType" ] ),
                (int)schemaTableRow[ "ColumnSize" ],
                (bool)schemaTableRow[ "AllowDBNull" ],
                databaseInfo );
            isIdentity = ( databaseInfo is SqlServerInfo && (bool)schemaTableRow[ "IsIdentity" ] ) ||
                         ( databaseInfo is MySqlInfo && (bool)schemaTableRow[ "IsAutoIncrement" ] );
            isRowVersion = databaseInfo is SqlServerInfo && (bool)schemaTableRow[ "IsRowVersion" ];
            if( includeKeyInfo )
                isKey = (bool)schemaTableRow[ "IsKey" ];
        }
コード例 #3
0
        private Column(DataRow schemaTableRow, bool includeKeyInfo, bool validateIfString, List <Action> validationMethods, DatabaseInfo databaseInfo)
        {
            ordinal = (int)schemaTableRow["ColumnOrdinal"];

            // MySQL incorrectly uses one-based ordinals; see http://bugs.mysql.com/bug.php?id=61477.
            if (databaseInfo is MySqlInfo)
            {
                ordinal -= 1;
            }

            var dbTypeString = databaseInfo.GetDbTypeString(schemaTableRow["ProviderType"]);

            valueContainer = new ValueContainer(
                (string)schemaTableRow["ColumnName"],
                (Type)schemaTableRow["DataType"],
                dbTypeString,
                (int)schemaTableRow["ColumnSize"],
                databaseInfo is SqlServerInfo && dbTypeString == "Decimal" ? (short)schemaTableRow["NumericScale"] :
                databaseInfo is MySqlInfo && dbTypeString == "NewDecimal" ? (short)(int)schemaTableRow["NumericScale"] :
                databaseInfo is OracleInfo && dbTypeString == "Decimal" ? (short)schemaTableRow["NumericScale"] : (short?)null,
                (bool)schemaTableRow["AllowDBNull"],
                databaseInfo);

            isIdentity = (databaseInfo is SqlServerInfo && (bool)schemaTableRow["IsIdentity"]) ||
                         (databaseInfo is MySqlInfo && (bool)schemaTableRow["IsAutoIncrement"]);
            isRowVersion = databaseInfo is SqlServerInfo && (bool)schemaTableRow["IsRowVersion"];
            if (includeKeyInfo)
            {
                isKey = (bool)schemaTableRow["IsKey"];
            }

            validationMethods.Add(
                () => {
                if (validateIfString && !(databaseInfo is OracleInfo) && valueContainer.DataType == typeof(string) &&
                    (!(databaseInfo is MySqlInfo) || dbTypeString != "JSON") && valueContainer.AllowsNull)
                {
                    throw new UserCorrectableException("String column {0} allows null, which is not allowed.".FormatWith(valueContainer.Name));
                }
            });
        }