示例#1
0
 public void ToDbType()
 {
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.Array));
     Assert.AreEqual(DbType.Int64, HsqlConvert.ToDbType(HsqlProviderType.BigInt));
     Assert.AreEqual(DbType.Binary, HsqlConvert.ToDbType(HsqlProviderType.Binary));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.Blob));
     Assert.AreEqual(DbType.Boolean, HsqlConvert.ToDbType(HsqlProviderType.Boolean));
     Assert.AreEqual(DbType.StringFixedLength, HsqlConvert.ToDbType(HsqlProviderType.Char));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.Clob));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.DataLink));
     Assert.AreEqual(DbType.DateTime, HsqlConvert.ToDbType(HsqlProviderType.Date));
     Assert.AreEqual(DbType.Decimal, HsqlConvert.ToDbType(HsqlProviderType.Decimal));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.Distinct));
     Assert.AreEqual(DbType.Double, HsqlConvert.ToDbType(HsqlProviderType.Double));
     Assert.AreEqual(DbType.Double, HsqlConvert.ToDbType(HsqlProviderType.Float));
     Assert.AreEqual(DbType.Int32, HsqlConvert.ToDbType(HsqlProviderType.Integer));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.JavaObject));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.LongVarBinary));
     Assert.AreEqual(DbType.String, HsqlConvert.ToDbType(HsqlProviderType.LongVarChar));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.Null));
     Assert.AreEqual(DbType.VarNumeric, HsqlConvert.ToDbType(HsqlProviderType.Numeric));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.Object));
     Assert.AreEqual(DbType.Single, HsqlConvert.ToDbType(HsqlProviderType.Real));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.Ref));
     Assert.AreEqual(DbType.Int16, HsqlConvert.ToDbType(HsqlProviderType.SmallInt));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.Struct));
     Assert.AreEqual(DbType.DateTime, HsqlConvert.ToDbType(HsqlProviderType.Time));
     Assert.AreEqual(DbType.DateTime2, HsqlConvert.ToDbType(HsqlProviderType.TimeStamp));
     Assert.AreEqual(DbType.SByte, HsqlConvert.ToDbType(HsqlProviderType.TinyInt));
     Assert.AreEqual(DbType.Object, HsqlConvert.ToDbType(HsqlProviderType.VarBinary));
     Assert.AreEqual(DbType.String, HsqlConvert.ToDbType(HsqlProviderType.VarChar));
     Assert.AreEqual(DbType.Xml, HsqlConvert.ToDbType(HsqlProviderType.Xml));
 }
示例#2
0
        internal void DeriveParametersInternal()
        {
            if (CommandType != CommandType.StoredProcedure)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Operation not supported for CommandType: "
                                                        + CommandType.ToString()));
            }

            Prepare();

            HsqlStatement     statement = m_statement;
            ParameterMetaData pmd       = statement.ParameterDescriptor.metaData;

            string[] parameterNames = pmd.colNames;
            int      count          = parameterNames.Length;

            HsqlParameter[] parameters = new HsqlParameter[count];

            for (int i = 0; i < count; i++)
            {
                string        name        = parameterNames[i];
                ParameterMode mode        = (ParameterMode)pmd.paramMode[i];
                int           type        = pmd.colTypes[i];
                int           precision   = pmd.colSizes[i];
                int           scale       = pmd.colScales[i];
                int           nullability = pmd.colNullable[i];

                HsqlProviderType   providerType = (HsqlProviderType)type;
                DbType             dbType       = HsqlConvert.ToDbType(providerType);
                ParameterDirection?direction    = HsqlConvert.ToParameterDirection(mode);
                bool?isNullable  = IsNullable(nullability);
                bool isCharacter = IsCharacterType(type);
                bool isNumber    = (!isCharacter) && IsNumberType(type);
                bool isTemporal  = !(isCharacter || isNumber) && IsTemporalType(type);
                int  size        = ToBufferSize(type, precision);

                if (isCharacter)
                {
                    precision = 0;
                    scale     = 0;
                }
                else if (isNumber || isTemporal)
                {
                    if (precision == 0)
                    {
                        precision = ToDefaultPrecision(type);
                    }
                }

                HsqlParameter parameter = new HsqlParameter();

                parameter.DbType = dbType;

                if (direction != null)
                {
                    parameter.Direction = direction.Value;
                }

                if (isNullable != null)
                {
                    parameter.IsNullable = isNullable.Value;
                }

                parameter.ParameterName = name;
                parameter.Precision     = (byte)Math.Min(byte.MaxValue, precision);
                parameter.ProviderType  = providerType;
                parameter.Scale         = (byte)Math.Min(byte.MaxValue, scale);
                parameter.Size          = size;
                parameter.SourceVersion = DataRowVersion.Default;

                parameters[i] = parameter;
            }

            HsqlParameterCollection pc = Parameters;

            pc.Clear();

            foreach (HsqlParameter parameter in parameters)
            {
                pc.Add(parameter);
            }
        }