예제 #1
0
        public static long GetIntegerValue(this ICdlValueReader reader)
        {
            switch (reader.GetFieldType())
            {
            case TypeStorage.Byte:
                return(reader.GetByte());

            case TypeStorage.Int16:
                return(reader.GetInt16());

            case TypeStorage.Int32:
                return(reader.GetInt32());

            case TypeStorage.Int64:
                return(reader.GetInt64());

            case TypeStorage.SByte:
                return(reader.GetSByte());

            case TypeStorage.UInt16:
                return(reader.GetUInt16());

            case TypeStorage.UInt32:
                return(reader.GetUInt32());

            case TypeStorage.UInt64:
                unchecked
                {
                    return((long)reader.GetUInt64());
                }

            case TypeStorage.Float:
                return((long)reader.GetFloat());

            case TypeStorage.Double:
                return((long)reader.GetDouble());

            case TypeStorage.Decimal:
                return((long)reader.GetDecimal());

            default:
                return(0);
            }
        }
예제 #2
0
 public static void GetValueAsSqlLiteral(ICdlValueReader rec, out string sqldata)
 {
     var type = rec.GetFieldType();
     if (type == TypeStorage.Null)
     {
         sqldata = "null";
         return;
     }
     switch (type)
     {
         case TypeStorage.Boolean:
             sqldata = rec.GetBoolean() ? "1" : "0";
             break;
         case TypeStorage.Byte:
             sqldata = rec.GetByte().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Int16:
             sqldata = rec.GetInt16().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Int32:
             sqldata = rec.GetInt32().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Int64:
             sqldata = rec.GetInt64().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.SByte:
             sqldata = rec.GetSByte().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.UInt16:
             sqldata = rec.GetUInt16().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.UInt32:
             sqldata = rec.GetUInt32().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.UInt64:
             sqldata = rec.GetUInt64().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.DateTime:
             sqldata = "'" + StringTool.DateTimeToIsoStringExact(rec.GetDateTime()) + "'";
             break;
         case TypeStorage.DateTimeEx:
             sqldata = "'" + rec.GetDateTimeEx().ToStringNormalized() + "'";
             break;
         case TypeStorage.DateEx:
             sqldata = "'" + rec.GetDateEx().ToStringNormalized() + "'";
             break;
         case TypeStorage.TimeEx:
             sqldata = "'" + rec.GetTimeEx().ToStringNormalized() + "'";
             break;
         case TypeStorage.Decimal:
             sqldata = rec.GetDecimal().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Float:
             sqldata = rec.GetFloat().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Double:
             sqldata = rec.GetDouble().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.String:
             sqldata = "'" + rec.GetString().Replace("'", "''") + "'";
             break;
         case TypeStorage.Guid:
             sqldata = "'" + rec.GetGuid().ToString() + "'";
             break;
         case TypeStorage.ByteArray:
             {
                 byte[] data = rec.GetByteArray();
                 sqldata = "X'" + StringTool.EncodeHex(data) + "'";
             }
             break;
             //case TypeStorage.Array:
             //    {
             //        xtype = "array";
             //        xdata = CdlArray.ToString(rec.GetArray());
             //    }
             //    break;
         default:
             throw new Exception("DBSH-00166 Unsupported field type:" + type.ToString());
     }
 }
예제 #3
0
        public static void GetValueAsSqlLiteral(ICdlValueReader rec, out string sqldata)
        {
            var type = rec.GetFieldType();

            if (type == TypeStorage.Null)
            {
                sqldata = "null";
                return;
            }
            switch (type)
            {
            case TypeStorage.Boolean:
                sqldata = rec.GetBoolean() ? "1" : "0";
                break;

            case TypeStorage.Byte:
                sqldata = rec.GetByte().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Int16:
                sqldata = rec.GetInt16().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Int32:
                sqldata = rec.GetInt32().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Int64:
                sqldata = rec.GetInt64().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.SByte:
                sqldata = rec.GetSByte().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.UInt16:
                sqldata = rec.GetUInt16().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.UInt32:
                sqldata = rec.GetUInt32().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.UInt64:
                sqldata = rec.GetUInt64().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.DateTime:
                sqldata = "'" + StringTool.DateTimeToIsoStringExact(rec.GetDateTime()) + "'";
                break;

            case TypeStorage.DateTimeEx:
                sqldata = "'" + rec.GetDateTimeEx().ToStringNormalized() + "'";
                break;

            case TypeStorage.DateEx:
                sqldata = "'" + rec.GetDateEx().ToStringNormalized() + "'";
                break;

            case TypeStorage.TimeEx:
                sqldata = "'" + rec.GetTimeEx().ToStringNormalized() + "'";
                break;

            case TypeStorage.Decimal:
                sqldata = rec.GetDecimal().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Float:
                sqldata = rec.GetFloat().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Double:
                sqldata = rec.GetDouble().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.String:
                sqldata = "'" + rec.GetString().Replace("'", "''") + "'";
                break;

            case TypeStorage.Guid:
                sqldata = "'" + rec.GetGuid().ToString() + "'";
                break;

            case TypeStorage.ByteArray:
            {
                byte[] data = rec.GetByteArray();
                sqldata = "X'" + StringTool.EncodeHex(data) + "'";
            }
            break;

            //case TypeStorage.Array:
            //    {
            //        xtype = "array";
            //        xdata = CdlArray.ToString(rec.GetArray());
            //    }
            //    break;
            default:
                throw new Exception("DBSH-00166 Unsupported field type:" + type.ToString());
            }
        }
예제 #4
0
        public static bool GetValueAsXml(ICdlValueReader rec, ref string xtype, ref string xdata)
        {
            var type = rec.GetFieldType();

            if (type == TypeStorage.Null)
            {
                return(false);
            }
            switch (type)
            {
            case TypeStorage.Boolean:
                xtype = "bool";
                xdata = rec.GetBoolean() ? "1" : "0";
                break;

            case TypeStorage.Byte:
                xtype = "byte";
                xdata = rec.GetByte().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Int16:
                xtype = "i16";
                xdata = rec.GetInt16().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Int32:
                xtype = "i32";
                xdata = rec.GetInt32().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Int64:
                xtype = "i64";
                xdata = rec.GetInt64().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.SByte:
                xtype = "sbyte";
                xdata = rec.GetSByte().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.UInt16:
                xtype = "u16";
                xdata = rec.GetUInt16().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.UInt32:
                xtype = "u32";
                xdata = rec.GetUInt32().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.UInt64:
                xtype = "u64";
                xdata = rec.GetUInt64().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.DateTime:
                xtype = "datetime";
                xdata = rec.GetDateTime().ToString("s", CultureInfo.InvariantCulture);
                break;

            case TypeStorage.DateTimeEx:
                xtype = "dtex";
                xdata = rec.GetDateTimeEx().ToStringNormalized();
                break;

            case TypeStorage.DateEx:
                xtype = "date";
                xdata = rec.GetDateEx().ToStringNormalized();
                break;

            case TypeStorage.TimeEx:
                xtype = "time";
                xdata = rec.GetTimeEx().ToStringNormalized();
                break;

            case TypeStorage.Decimal:
                xtype = "decimal";
                xdata = rec.GetDecimal().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Float:
                xtype = "float";
                xdata = rec.GetFloat().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.Double:
                xtype = "double";
                xdata = rec.GetDouble().ToString(CultureInfo.InvariantCulture);
                break;

            case TypeStorage.String:
                xtype = "str";
                xdata = rec.GetString();
                break;

            case TypeStorage.Guid:
                xtype = "guid";
                xdata = rec.GetGuid().ToString();
                break;

            case TypeStorage.ByteArray:
            {
                xtype = "blob";
                byte[] data = rec.GetByteArray();
                xdata = Convert.ToBase64String(data);
            }
            break;
                //case TypeStorage.Array:
                //    {
                //        xtype = "array";
                //        xdata = CdlArray.ToString(rec.GetArray());
                //    }
                //    break;
            }
            return(true);
        }
예제 #5
0
        public static object BoxTypedValue(this ICdlValueReader reader)
        {
            switch (reader.GetFieldType())
            {
            case TypeStorage.Null:
                return(null);

            case TypeStorage.Boolean:
                return(reader.GetBoolean());

            case TypeStorage.Byte:
                return(reader.GetByte());

            case TypeStorage.Int16:
                return(reader.GetInt16());

            case TypeStorage.Int32:
                return(reader.GetInt32());

            case TypeStorage.Int64:
                return(reader.GetInt64());

            case TypeStorage.SByte:
                return(reader.GetSByte());

            case TypeStorage.UInt16:
                return(reader.GetUInt16());

            case TypeStorage.UInt32:
                return(reader.GetUInt32());

            case TypeStorage.UInt64:
                return(reader.GetUInt64());

            case TypeStorage.Float:
                return(reader.GetFloat());

            case TypeStorage.Double:
                return(reader.GetDouble());

            case TypeStorage.Decimal:
                return(reader.GetDecimal());

            case TypeStorage.DateTime:
                return(reader.GetDateTime());

            case TypeStorage.DateTimeEx:
                return(reader.GetDateTimeEx());

            case TypeStorage.DateEx:
                return(reader.GetDateEx());

            case TypeStorage.TimeEx:
                return(reader.GetTimeEx());

            case TypeStorage.ByteArray:
                return(reader.GetByteArray());

            case TypeStorage.Guid:
                return(reader.GetGuid());

            case TypeStorage.String:
                return(reader.GetString());
                //case TypeStorage.Array:
                //    return reader.GetArray();
            }
            return(null);
        }
예제 #6
0
        public static void WriteTo(this ICdlValueReader reader, ICdlValueWriter writer)
        {
            switch (reader.GetFieldType())
            {
            case TypeStorage.Null:
                writer.SetNull();
                break;

            case TypeStorage.Boolean:
                writer.SetBoolean(reader.GetBoolean());
                break;

            case TypeStorage.Byte:
                writer.SetByte(reader.GetByte());
                break;

            case TypeStorage.Int16:
                writer.SetInt16(reader.GetInt16());
                break;

            case TypeStorage.Int32:
                writer.SetInt32(reader.GetInt32());
                break;

            case TypeStorage.Int64:
                writer.SetInt64(reader.GetInt64());
                break;

            case TypeStorage.SByte:
                writer.SetSByte(reader.GetSByte());
                break;

            case TypeStorage.UInt16:
                writer.SetUInt16(reader.GetUInt16());
                break;

            case TypeStorage.UInt32:
                writer.SetUInt32(reader.GetUInt32());
                break;

            case TypeStorage.UInt64:
                writer.SetUInt64(reader.GetUInt64());
                break;

            case TypeStorage.Float:
                writer.SetFloat(reader.GetFloat());
                break;

            case TypeStorage.Double:
                writer.SetDouble(reader.GetDouble());
                break;

            case TypeStorage.Decimal:
                writer.SetDecimal(reader.GetDecimal());
                break;

            case TypeStorage.DateTime:
                writer.SetDateTime(reader.GetDateTime());
                break;

            case TypeStorage.DateTimeEx:
                writer.SetDateTimeEx(reader.GetDateTimeEx());
                break;

            case TypeStorage.DateEx:
                writer.SetDateEx(reader.GetDateEx());
                break;

            case TypeStorage.TimeEx:
                writer.SetTimeEx(reader.GetTimeEx());
                break;

            case TypeStorage.ByteArray:
                writer.SetByteArray(reader.GetByteArray());
                break;

            case TypeStorage.Guid:
                writer.SetGuid(reader.GetGuid());
                break;

            case TypeStorage.String:
                writer.SetString(reader.GetString());
                break;
            }
        }
예제 #7
0
파일: CdlTool.cs 프로젝트: dbshell/dbshell
 public static bool GetValueAsXml(ICdlValueReader rec, ref string xtype, ref string xdata)
 {
     var type = rec.GetFieldType();
     if (type == TypeStorage.Null) return false;
     switch (type)
     {
         case TypeStorage.Boolean:
             xtype = "bool";
             xdata = rec.GetBoolean() ? "1" : "0";
             break;
         case TypeStorage.Byte:
             xtype = "byte";
             xdata = rec.GetByte().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Int16:
             xtype = "i16";
             xdata = rec.GetInt16().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Int32:
             xtype = "i32";
             xdata = rec.GetInt32().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Int64:
             xtype = "i64";
             xdata = rec.GetInt64().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.SByte:
             xtype = "sbyte";
             xdata = rec.GetSByte().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.UInt16:
             xtype = "u16";
             xdata = rec.GetUInt16().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.UInt32:
             xtype = "u32";
             xdata = rec.GetUInt32().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.UInt64:
             xtype = "u64";
             xdata = rec.GetUInt64().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.DateTime:
             xtype = "datetime";
             xdata = rec.GetDateTime().ToString("s", CultureInfo.InvariantCulture);
             break;
         case TypeStorage.DateTimeEx:
             xtype = "dtex";
             xdata = rec.GetDateTimeEx().ToStringNormalized();
             break;
         case TypeStorage.DateEx:
             xtype = "date";
             xdata = rec.GetDateEx().ToStringNormalized();
             break;
         case TypeStorage.TimeEx:
             xtype = "time";
             xdata = rec.GetTimeEx().ToStringNormalized();
             break;
         case TypeStorage.Decimal:
             xtype = "decimal";
             xdata = rec.GetDecimal().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Float:
             xtype = "float";
             xdata = rec.GetFloat().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.Double:
             xtype = "double";
             xdata = rec.GetDouble().ToString(CultureInfo.InvariantCulture);
             break;
         case TypeStorage.String:
             xtype = "str";
             xdata = rec.GetString();
             break;
         case TypeStorage.Guid:
             xtype = "guid";
             xdata = rec.GetGuid().ToString();
             break;
         case TypeStorage.ByteArray:
             {
                 xtype = "blob";
                 byte[] data = rec.GetByteArray();
                 xdata = Convert.ToBase64String(data);
             }
             break;
         //case TypeStorage.Array:
         //    {
         //        xtype = "array";
         //        xdata = CdlArray.ToString(rec.GetArray());
         //    }
         //    break;
     }
     return true;
 }