Exemple #1
0
            // generate parameter (name based on parameter ordinal)
            internal SQLiteParameter CreateParameter(object value, TypeUsage type)
            {
                PrimitiveTypeKind primitiveType = MetadataHelpers.GetPrimitiveTypeKind(type);
                DbType            dbType        = MetadataHelpers.GetDbType(primitiveType);

                return(CreateParameter(value, dbType));
            }
        /// <summary>
        /// Determines IngresType for the given primitive type. Extracts facet
        /// information as well.
        /// </summary>
        private static IngresType GetIngresType(TypeUsage type)
        {
            // only supported for primitive type
            var primitiveTypeKind = MetadataHelpers.GetPrimitiveTypeKind(type);

            switch (primitiveTypeKind)
            {
            case PrimitiveTypeKind.Binary:
                return(GetBinaryDbType(type));

            case PrimitiveTypeKind.Boolean:
                return(IngresType.Int);

            case PrimitiveTypeKind.Byte:
                return(IngresType.TinyInt);

            case PrimitiveTypeKind.Time:
                return(IngresType.Time);

            case PrimitiveTypeKind.DateTimeOffset:
                throw new Exception("unknown PrimitiveTypeKind " + primitiveTypeKind);

            case PrimitiveTypeKind.DateTime:
                return(IngresType.DateTime);

            case PrimitiveTypeKind.Decimal:
                return(IngresType.Decimal);

            case PrimitiveTypeKind.Double:
                return(IngresType.Double);

            case PrimitiveTypeKind.Guid:
                throw new Exception("unknown PrimitiveTypeKind " + primitiveTypeKind);

            case PrimitiveTypeKind.Int16:
                return(IngresType.SmallInt);

            case PrimitiveTypeKind.Int32:
                return(IngresType.Int);

            case PrimitiveTypeKind.Int64:
                return(IngresType.BigInt);

            case PrimitiveTypeKind.SByte:
                return(IngresType.TinyInt);

            case PrimitiveTypeKind.Single:
                return(IngresType.Real);

            case PrimitiveTypeKind.String:
                return(GetStringDbType(type));

            default:
                Debug.Fail("unknown PrimitiveTypeKind " + primitiveTypeKind);
                throw new Exception("unknown PrimitiveTypeKind " + primitiveTypeKind);
            }
        }
Exemple #3
0
        /// <summary>
        /// Creates a SQLiteParameter given a name, type, and direction
        /// </summary>
        internal static SQLiteParameter CreateSqlParameter(SQLiteProviderManifest manifest, string name, TypeUsage type, ParameterMode mode, object value)
        {
            int?size;

            //
            // NOTE: Adjust the parameter type so that it will work with textual
            //       GUIDs.  Please see ticket [a4d9c7ee94] for more details.
            //
            if ((manifest != null) && !manifest._binaryGuid &&
                (MetadataHelpers.GetPrimitiveTypeKind(type) == PrimitiveTypeKind.Guid))
            {
                type = TypeUsage.CreateStringTypeUsage(
                    PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String),
                    false, true);
            }

            SQLiteParameter result = new SQLiteParameter(name, value);

            // .Direction
            ParameterDirection direction = MetadataHelpers.ParameterModeToParameterDirection(mode);

            if (result.Direction != direction)
            {
                result.Direction = direction;
            }

            // .Size and .DbType
            // output parameters are handled differently (we need to ensure there is space for return
            // values where the user has not given a specific Size/MaxLength)
            bool   isOutParam = mode != ParameterMode.In;
            DbType sqlDbType  = GetSqlDbType(type, isOutParam, out size);

            if (result.DbType != sqlDbType)
            {
                result.DbType = sqlDbType;
            }

            // Note that we overwrite 'facet' parameters where either the value is different or
            // there is an output parameter.
            if (size.HasValue && (isOutParam || result.Size != size.Value))
            {
                result.Size = size.Value;
            }

            // .IsNullable
            bool isNullable = MetadataHelpers.IsNullable(type);

            if (isOutParam || isNullable != result.IsNullable)
            {
                result.IsNullable = isNullable;
            }

            return(result);
        }
        /// <summary>
        /// Determines SqlDbType for the given primitive type. Extracts facet
        /// information as well.
        /// </summary>
        private static FbDbType GetSqlDbType(TypeUsage type, bool isOutParam, out int?size)
        {
            // only supported for primitive type
            PrimitiveTypeKind primitiveTypeKind = MetadataHelpers.GetPrimitiveTypeKind(type);

            size = default(int?);

            switch (primitiveTypeKind)
            {
            case PrimitiveTypeKind.Boolean:
                return(FbDbType.SmallInt);

            case PrimitiveTypeKind.Int16:
                return(FbDbType.SmallInt);

            case PrimitiveTypeKind.Int32:
                return(FbDbType.Integer);

            case PrimitiveTypeKind.Int64:
                return(FbDbType.BigInt);

            case PrimitiveTypeKind.Double:
                return(FbDbType.Double);

            case PrimitiveTypeKind.Single:
                return(FbDbType.Float);

            case PrimitiveTypeKind.Decimal:
                return(FbDbType.Decimal);

            case PrimitiveTypeKind.Binary:
                // for output parameters, ensure there is space...
                size = GetParameterSize(type, isOutParam);
                return(GetBinaryDbType(type));

            case PrimitiveTypeKind.String:
                size = GetParameterSize(type, isOutParam);
                return(GetStringDbType(type));

            case PrimitiveTypeKind.DateTime:
                return(FbDbType.TimeStamp);

            case PrimitiveTypeKind.Time:
                return(FbDbType.Time);

            case PrimitiveTypeKind.Guid:
                return(FbDbType.Guid);

            default:
                Debug.Fail("unknown PrimitiveTypeKind " + primitiveTypeKind);
                throw new InvalidOperationException("unknown PrimitiveTypeKind " + primitiveTypeKind);
            }
        }
Exemple #5
0
        /// <summary>
        /// Determines DbType for the given primitive type. Extracts facet
        /// information as well.
        /// </summary>
        private static DbType GetSqlDbType(TypeUsage type, bool isOutParam, out int?size)
        {
            // only supported for primitive type
            PrimitiveTypeKind primitiveTypeKind = MetadataHelpers.GetPrimitiveTypeKind(type);

            size = default(int?);

            switch (primitiveTypeKind)
            {
            case PrimitiveTypeKind.Binary:
                // for output parameters, ensure there is space...
                size = GetParameterSize(type, isOutParam);
                return(GetBinaryDbType(type));

            case PrimitiveTypeKind.Boolean:
                return(DbType.Boolean);

            case PrimitiveTypeKind.Byte:
                return(DbType.Byte);

            case PrimitiveTypeKind.Time:
                return(DbType.Time);

            case PrimitiveTypeKind.DateTimeOffset:
                return(DbType.DateTimeOffset);

            case PrimitiveTypeKind.DateTime:
                return(DbType.DateTime);

            case PrimitiveTypeKind.Decimal:
                return(DbType.Decimal);

            case PrimitiveTypeKind.Double:
                return(DbType.Double);

            case PrimitiveTypeKind.Guid:
                return(DbType.Guid);

            case PrimitiveTypeKind.Int16:
                return(DbType.Int16);

            case PrimitiveTypeKind.Int32:
                return(DbType.Int32);

            case PrimitiveTypeKind.Int64:
                return(DbType.Int64);

            case PrimitiveTypeKind.SByte:
                return(DbType.SByte);

            case PrimitiveTypeKind.Single:
                return(DbType.Single);

            case PrimitiveTypeKind.String:
                size = GetParameterSize(type, isOutParam);
                return(GetStringDbType(type));

            default:
                Debug.Fail("unknown PrimitiveTypeKind " + primitiveTypeKind);
                return(DbType.Object);
            }
        }