コード例 #1
0
		public static IntPtr MarshalManagedToNative(Charset charset, Descriptor descriptor)
		{
			// Set up XSQLDA structure
			var xsqlda = new XSQLDA
			{
				version = descriptor.Version,
				sqln = descriptor.Count,
				sqld = descriptor.ActualCount
			};

			var xsqlvar = new XSQLVAR[descriptor.Count];

			for (var i = 0; i < xsqlvar.Length; i++)
			{
				// Create a	new	XSQLVAR	structure and fill it
				xsqlvar[i] = new XSQLVAR
				{
					sqltype = descriptor[i].DataType,
					sqlscale = descriptor[i].NumericScale,
					sqlsubtype = descriptor[i].SubType,
					sqllen = descriptor[i].Length
				};


				// Create a	new	pointer	for	the	xsqlvar	data
				if (descriptor[i].HasDataType() && descriptor[i].DbDataType != DbDataType.Null)
				{
					var buffer = descriptor[i].DbValue.GetBytes();
					xsqlvar[i].sqldata = Marshal.AllocHGlobal(buffer.Length);
					Marshal.Copy(buffer, 0, xsqlvar[i].sqldata, buffer.Length);
				}
				else
				{
					xsqlvar[i].sqldata = Marshal.AllocHGlobal(0);
				}

				// Create a	new	pointer	for	the	sqlind value
				xsqlvar[i].sqlind = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(short)));
				Marshal.WriteInt16(xsqlvar[i].sqlind, descriptor[i].NullFlag);

				// Name
				xsqlvar[i].sqlname = GetStringBuffer(charset, descriptor[i].Name);
				xsqlvar[i].sqlname_length = (short)descriptor[i].Name.Length;

				// Relation	Name
				xsqlvar[i].relname = GetStringBuffer(charset, descriptor[i].Relation);
				xsqlvar[i].relname_length = (short)descriptor[i].Relation.Length;

				// Owner name
				xsqlvar[i].ownername = GetStringBuffer(charset, descriptor[i].Owner);
				xsqlvar[i].ownername_length = (short)descriptor[i].Owner.Length;

				// Alias name
				xsqlvar[i].aliasname = GetStringBuffer(charset, descriptor[i].Alias);
				xsqlvar[i].aliasname_length = (short)descriptor[i].Alias.Length;
			}

			return MarshalManagedToNative(xsqlda, xsqlvar);
		}
コード例 #2
0
        public GdsConnection(string dataSource, int portNumber, int packetSize, Charset characterSet)
        {
            this.dataSource = dataSource;
            this.portNumber = portNumber;
            this.packetSize = packetSize;
            this.characterSet = characterSet;

            GC.SuppressFinalize(this);
        }
コード例 #3
0
ファイル: XdrStream.cs プロジェクト: kingpong/NETProvider
        public XdrStream(Stream innerStream, Charset charset)
            : base()
        {
            this.innerStream = innerStream;
            this.charset = charset;
            this.ResetOperation();

            GC.SuppressFinalize(innerStream);
        }
コード例 #4
0
ファイル: ExtDatabase.cs プロジェクト: kingpong/NETProvider
        public ExtDatabase()
        {
            this.charset = Charset.DefaultCharset;
            this.dialect = 3;
            this.packetSize = 8192;
            this.statusVector = new int[IscCodes.ISC_STATUS_LENGTH];

            GC.SuppressFinalize(this);
        }
コード例 #5
0
ファイル: FesDatabase.cs プロジェクト: kingpong/NETProvider
        public FesDatabase(string dllName, Charset charset)
        {
            this.fbClient = FbClientFactory.GetFbClient(dllName);
            this.charset = (charset != null ? charset : Charset.DefaultCharset);
            this.dialect = 3;
            this.packetSize = 8192;
            this.statusVector = new IntPtr[IscCodes.ISC_STATUS_LENGTH];

            GC.SuppressFinalize(this);
        }
コード例 #6
0
		public void Connect(string dataSource, int port, int packetSize, Charset charset)
		{
			try
			{
				IPAddress hostadd = Dns.Resolve(dataSource).AddressList[0];
				IPEndPoint EPhost = new IPEndPoint(hostadd, port);

				this.socket = new Socket(
					AddressFamily.InterNetwork,
					SocketType.Stream,
					ProtocolType.Tcp);

#if (!NETCF)

				// Set Receive Buffer size.
				this.socket.SetSocketOption(
					SocketOptionLevel.Socket,
					SocketOptionName.ReceiveBuffer,
					packetSize);

				// Set Send	Buffer size.
				this.socket.SetSocketOption(
					SocketOptionLevel.Socket,
					SocketOptionName.SendBuffer,
					packetSize);
#endif

				// Disables	the	Nagle algorithm	for	send coalescing.
				this.socket.SetSocketOption(
					SocketOptionLevel.Tcp,
					SocketOptionName.NoDelay,
					1);

				// Make	the	socket to connect to the Server
				this.socket.Connect(EPhost);
				this.networkStream = new NetworkStream(this.socket, true);

#if	(NETCF)
				this.send	 = new XdrStream(this.networkStream, charset);
				this.receive = new XdrStream(this.networkStream, charset);
#else
				this.send = new XdrStream(new BufferedStream(this.networkStream), charset);
				this.receive = new XdrStream(new BufferedStream(this.networkStream), charset);
#endif

				GC.SuppressFinalize(this.socket);
				GC.SuppressFinalize(this.networkStream);
				GC.SuppressFinalize(this.send);
				GC.SuppressFinalize(this.receive);
			}
			catch (SocketException)
			{
				throw new IscException(IscCodes.isc_arg_gds, IscCodes.isc_network_error, dataSource);
			}
		}
コード例 #7
0
		internal Charset Add(
			int		id,
			string	charset,
			int		bytesPerCharacter,
			string	systemCharset)
		{
			Charset charSet = new Charset(
				id, charset, bytesPerCharacter, systemCharset);

			return this.Add(charSet);
		}
コード例 #8
0
ファイル: GdsDatabase.cs プロジェクト: kingpong/NETProvider
        public GdsDatabase(GdsConnection connection)
        {
            this.connection = connection;
            this.charset = Charset.DefaultCharset;
            this.dialect = 3;
            this.packetSize = 8192;
            this.inputStream = this.connection.CreateXdrStream();
            this.outputStream = this.connection.CreateXdrStream();

            GC.SuppressFinalize(this);
        }
コード例 #9
0
        public IntPtr MarshalManagedToNative(Charset charset, object value)
        {
            DbField field = new DbField();
            ParamDsc descriptor = this.BuildDescriptor(charset, value);
            DbDataType type = TypeHelper.GetTypeFromDsc(descriptor.Type, descriptor.Scale, descriptor.SubType);

            field.DataType          = (short)TypeHelper.GetFbType(type, true);
            field.SubType           = descriptor.SubType;
            field.DbValue.Value     = value;
            field.Length            = descriptor.Length;

            byte[] buffer = field.DbValue.GetBytes();

            descriptor.Data = Marshal.AllocHGlobal(buffer.Length);
            Marshal.Copy(buffer, 0, descriptor.Data, buffer.Length);

            return this.MarshalManagedToNative(descriptor);
        }
コード例 #10
0
		public override void Close()
		{
			if (this.innerStream != null)
			{
				this.innerStream.Close();
			}

			this.buffer			= null;
			this.charset		= null;
			this.innerStream	= null;
		}
コード例 #11
0
        private object GetValue(ParamDsc descriptor, Charset charset)
        {
            DbField field = new DbField();

            if (descriptor.Type == dtype_null)
            {
                return null;
            }
            if (descriptor.Type == IscCodes.dtype_byte)
            {
                return null;
            }

            DbDataType dbType = TypeHelper.GetTypeFromDsc(descriptor.Type, descriptor.Scale, descriptor.SubType);

            field.DataType      = (short)TypeHelper.GetFbType(dbType, true);
            field.NumericScale  = descriptor.Scale;
            field.SubType       = descriptor.SubType;

            byte[] data = this.GetBytes(descriptor, field.DataType);

            field.SetValue(data);

            return field.Value;
        }
コード例 #12
0
        private ParamDsc BuildDescriptor(Charset charset, object value)
        {
            ParamDsc descriptor = new ParamDsc();

            if (value == null || value == DBNull.Value)
            {
                descriptor.Flags |= IscCodes.DSC_null;
            }
            else
            {
                this.SetDscType(ref descriptor, value);
            }

            if (descriptor.Type == IscCodes.dtype_cstring || descriptor.Type == IscCodes.dtype_varying)
            {
                descriptor.SubType = (short)charset.Identifier;
            }

            return descriptor;
        }
コード例 #13
0
		public IntPtr MarshalManagedToNative(Charset charset, Descriptor descriptor)
		{
			// Set up XSQLDA structure
			XSQLDA xsqlda = new XSQLDA();

			xsqlda.version  = descriptor.Version;
			xsqlda.sqln     = descriptor.Count;
			xsqlda.sqld     = descriptor.ActualCount;

			XSQLVAR[] xsqlvar = new XSQLVAR[descriptor.Count];

			for (int i = 0; i < xsqlvar.Length; i++)
			{
				// Create a	new	XSQLVAR	structure and fill it
				xsqlvar[i] = new XSQLVAR();

				xsqlvar[i].sqltype      = descriptor[i].DataType;
				xsqlvar[i].sqlscale     = descriptor[i].NumericScale;
				xsqlvar[i].sqlsubtype   = descriptor[i].SubType;
				xsqlvar[i].sqllen       = descriptor[i].Length;

				// Create a	new	pointer	for	the	xsqlvar	data
				byte[] buffer = descriptor[i].DbValue.GetBytes();
				xsqlvar[i].sqldata = Marshal.AllocHGlobal(buffer.Length);
				Marshal.Copy(buffer, 0, xsqlvar[i].sqldata, buffer.Length);

				// Create a	new	pointer	for	the	sqlind value
				xsqlvar[i].sqlind = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Int16)));
				Marshal.WriteInt16(xsqlvar[i].sqlind, descriptor[i].NullFlag);

				// Name
				xsqlvar[i].sqlname = this.GetStringBuffer(charset, descriptor[i].Name);
				xsqlvar[i].sqlname_length = (short)descriptor[i].Name.Length;

				// Relation	Name
				xsqlvar[i].relname = this.GetStringBuffer(charset, descriptor[i].Relation);
				xsqlvar[i].relname_length = (short)descriptor[i].Relation.Length;

				// Owner name
				xsqlvar[i].ownername = this.GetStringBuffer(charset, descriptor[i].Owner);
				xsqlvar[i].ownername_length = (short)descriptor[i].Owner.Length;

				// Alias name
				xsqlvar[i].aliasname = this.GetStringBuffer(charset, descriptor[i].Alias);
				xsqlvar[i].aliasname_length = (short)descriptor[i].Alias.Length;
			}

			return this.MarshalManagedToNative(xsqlda, xsqlvar);
		}
コード例 #14
0
        public static DbDataType GetDbDataTypeFromSqlType(int type, int subType, int scale, int?length = null, Charset charset = null)
        {
            // Special case for Guid handling
            if (type == IscCodes.SQL_TEXT && length == 16 && (charset?.IsOctetsCharset ?? false))
            {
                return(DbDataType.Guid);
            }

            switch (type)
            {
            case IscCodes.SQL_TEXT:
                return(DbDataType.Char);

            case IscCodes.SQL_VARYING:
                return(DbDataType.VarChar);

            case IscCodes.SQL_SHORT:
                if (subType == 2)
                {
                    return(DbDataType.Decimal);
                }
                else if (subType == 1)
                {
                    return(DbDataType.Numeric);
                }
                else if (scale < 0)
                {
                    return(DbDataType.Decimal);
                }
                else
                {
                    return(DbDataType.SmallInt);
                }

            case IscCodes.SQL_LONG:
                if (subType == 2)
                {
                    return(DbDataType.Decimal);
                }
                else if (subType == 1)
                {
                    return(DbDataType.Numeric);
                }
                else if (scale < 0)
                {
                    return(DbDataType.Decimal);
                }
                else
                {
                    return(DbDataType.Integer);
                }

            case IscCodes.SQL_QUAD:
            case IscCodes.SQL_INT64:
                if (subType == 2)
                {
                    return(DbDataType.Decimal);
                }
                else if (subType == 1)
                {
                    return(DbDataType.Numeric);
                }
                else if (scale < 0)
                {
                    return(DbDataType.Decimal);
                }
                else
                {
                    return(DbDataType.BigInt);
                }

            case IscCodes.SQL_FLOAT:
                return(DbDataType.Float);

            case IscCodes.SQL_DOUBLE:
            case IscCodes.SQL_D_FLOAT:
                if (subType == 2)
                {
                    return(DbDataType.Decimal);
                }
                else if (subType == 1)
                {
                    return(DbDataType.Numeric);
                }
                else if (scale < 0)
                {
                    return(DbDataType.Decimal);
                }
                else
                {
                    return(DbDataType.Double);
                }

            case IscCodes.SQL_BLOB:
                if (subType == 1)
                {
                    return(DbDataType.Text);
                }
                else
                {
                    return(DbDataType.Binary);
                }

            case IscCodes.SQL_TIMESTAMP:
                return(DbDataType.TimeStamp);

            case IscCodes.SQL_TYPE_TIME:
                return(DbDataType.Time);

            case IscCodes.SQL_TYPE_DATE:
                return(DbDataType.Date);

            case IscCodes.SQL_ARRAY:
                return(DbDataType.Array);

            case IscCodes.SQL_NULL:
                return(DbDataType.Null);

            case IscCodes.SQL_BOOLEAN:
                return(DbDataType.Boolean);

            case IscCodes.SQL_TIMESTAMP_TZ:
                return(DbDataType.TimeStampTZ);

            case IscCodes.SQL_TIMESTAMP_TZ_EX:
                return(DbDataType.TimeStampTZEx);

            case IscCodes.SQL_TIME_TZ:
                return(DbDataType.TimeTZ);

            case IscCodes.SQL_TIME_TZ_EX:
                return(DbDataType.TimeTZEx);

            case IscCodes.SQL_DEC16:
                return(DbDataType.Dec16);

            case IscCodes.SQL_DEC34:
                return(DbDataType.Dec34);

            case IscCodes.SQL_INT128:
                if (subType == 2)
                {
                    return(DbDataType.Decimal);
                }
                else if (subType == 1)
                {
                    return(DbDataType.Numeric);
                }
                else if (scale < 0)
                {
                    return(DbDataType.Decimal);
                }
                else
                {
                    return(DbDataType.Int128);
                }

            default:
                throw InvalidDataType(type);
            }
        }
コード例 #15
0
		public Descriptor MarshalNativeToManaged(Charset charset, IntPtr pNativeData)
		{
			return this.MarshalNativeToManaged(charset, pNativeData, false);
		}
コード例 #16
0
		private byte[] GetStringBuffer(Charset charset, string value)
		{
			byte[] buffer = new byte[32];

			charset.GetBytes(value, 0, value.Length, buffer, 0);

			return buffer;
		}
コード例 #17
0
		private void Dispose(bool disposing)
		{
			lock (this)
			{
				if (!_disposed)
				{
					try
					{
						Detach();
					}
					catch
					{ }
					finally
					{
						if (disposing)
						{
							_warningMessage = null;
							_charset = null;
							_serverVersion = null;
							_statusVector = null;
							_transactionCount = 0;
							_dialect = 0;
							_handle = 0;
							_packetSize = 0;
						}

						_disposed = true;
					}
				}
			}
		}
コード例 #18
0
        public void SetValue(byte[] buffer)
        {
            if (buffer == null || NullFlag == -1)
            {
                Value = DBNull.Value;
            }
            else
            {
                switch (SqlType)
                {
                case IscCodes.SQL_TEXT:
                case IscCodes.SQL_VARYING:
                    if (DbDataType == DbDataType.Guid)
                    {
                        Value = TypeDecoder.DecodeGuid(buffer);
                    }
                    else
                    {
                        if (Charset.IsOctetsCharset)
                        {
                            Value = buffer;
                        }
                        else
                        {
                            string s = Charset.GetString(buffer, 0, buffer.Length);

                            if ((Length % Charset.BytesPerCharacter) == 0 &&
                                s.Length > CharCount)
                            {
                                s = s.Substring(0, CharCount);
                            }

                            Value = s;
                        }
                    }
                    break;

                case IscCodes.SQL_SHORT:
                    if (_numericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt16(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt16(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_LONG:
                    if (NumericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt32(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt32(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_FLOAT:
                    Value = BitConverter.ToSingle(buffer, 0);
                    break;

                case IscCodes.SQL_DOUBLE:
                case IscCodes.SQL_D_FLOAT:
                    Value = BitConverter.ToDouble(buffer, 0);
                    break;

                case IscCodes.SQL_QUAD:
                case IscCodes.SQL_INT64:
                case IscCodes.SQL_BLOB:
                case IscCodes.SQL_ARRAY:
                    if (NumericScale < 0)
                    {
                        Value = TypeDecoder.DecodeDecimal(
                            BitConverter.ToInt64(buffer, 0),
                            _numericScale,
                            _dataType);
                    }
                    else
                    {
                        Value = BitConverter.ToInt64(buffer, 0);
                    }
                    break;

                case IscCodes.SQL_TIMESTAMP:
                    DateTime date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    TimeSpan time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));

                    Value = date.Add(time);
                    break;

                case IscCodes.SQL_TYPE_TIME:
                    Value = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    break;

                case IscCodes.SQL_TYPE_DATE:
                    Value = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    break;

                case IscCodes.SQL_BOOLEAN:
                    Value = TypeDecoder.DecodeBoolean(buffer);
                    break;

                default:
                    throw TypeHelper.InvalidDataType(SqlType);
                }
            }
        }
コード例 #19
0
 protected BlobBase(IDatabase db)
 {
     _segmentSize = db.PacketSize;
     _charset     = db.Charset;
 }
コード例 #20
0
		public static Descriptor MarshalNativeToManaged(Charset charset, IntPtr pNativeData, bool fetching)
		{
			// Obtain XSQLDA information
			var xsqlda = (XSQLDA)Marshal.PtrToStructure(pNativeData, typeof(XSQLDA));

			// Create a	new	Descriptor
			var descriptor = new Descriptor(xsqlda.sqln) { ActualCount = xsqlda.sqld };

			// Obtain XSQLVAR members information
			var xsqlvar = new XSQLVAR();
			for (var i = 0; i < xsqlda.sqln; i++)
			{
				var ptr = GetIntPtr(pNativeData, ComputeLength(i));
				MarshalXSQLVARNativeToManaged(ptr, xsqlvar);

				// Map XSQLVAR information to Descriptor
				descriptor[i].DataType = xsqlvar.sqltype;
				descriptor[i].NumericScale = xsqlvar.sqlscale;
				descriptor[i].SubType = xsqlvar.sqlsubtype;
				descriptor[i].Length = xsqlvar.sqllen;

				// Decode sqlind value
				descriptor[i].NullFlag = xsqlvar.sqlind == IntPtr.Zero
					? (short)0
					: Marshal.ReadInt16(xsqlvar.sqlind);

				// Set value
				if (fetching)
				{
					if (descriptor[i].NullFlag != -1)
					{
						descriptor[i].SetValue(GetBytes(xsqlvar));
					}
				}

				descriptor[i].Name = GetString(charset, xsqlvar.sqlname, xsqlvar.sqlname_length);
				descriptor[i].Relation = GetString(charset, xsqlvar.relname, xsqlvar.relname_length);
				descriptor[i].Owner = GetString(charset, xsqlvar.ownername, xsqlvar.ownername_length);
				descriptor[i].Alias = GetString(charset, xsqlvar.aliasname, xsqlvar.aliasname_length);
			}

			return descriptor;
		}
コード例 #21
0
        public void SetValue(byte[] buffer)
        {
            if (buffer == null || NullFlag == -1)
            {
                DbValue.SetValue(DBNull.Value);
            }
            else
            {
                switch (SqlType)
                {
                case IscCodes.SQL_TEXT:
                case IscCodes.SQL_VARYING:
                    if (DbDataType == DbDataType.Guid)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeGuid(buffer));
                    }
                    else
                    {
                        if (Charset.IsOctetsCharset)
                        {
                            DbValue.SetValue(buffer);
                        }
                        else
                        {
                            var s = Charset.GetString(buffer, 0, buffer.Length);

                            if ((Length % Charset.BytesPerCharacter) == 0 &&
                                s.Length > CharCount)
                            {
                                s = s.Substring(0, CharCount);
                            }

                            DbValue.SetValue(s);
                        }
                    }
                    break;

                case IscCodes.SQL_SHORT:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt16(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt16(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_LONG:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt32(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt32(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_FLOAT:
                    DbValue.SetValue(BitConverter.ToSingle(buffer, 0));
                    break;

                case IscCodes.SQL_DOUBLE:
                case IscCodes.SQL_D_FLOAT:
                    DbValue.SetValue(BitConverter.ToDouble(buffer, 0));
                    break;

                case IscCodes.SQL_QUAD:
                case IscCodes.SQL_INT64:
                case IscCodes.SQL_BLOB:
                case IscCodes.SQL_ARRAY:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(BitConverter.ToInt64(buffer, 0), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(BitConverter.ToInt64(buffer, 0));
                    }
                    break;

                case IscCodes.SQL_TIMESTAMP:
                {
                    var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    DbValue.SetValue(date.Add(time));
                    break;
                }

                case IscCodes.SQL_TYPE_TIME:
                    DbValue.SetValue(TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0)));
                    break;

                case IscCodes.SQL_TYPE_DATE:
                    DbValue.SetValue(TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0)));
                    break;

                case IscCodes.SQL_BOOLEAN:
                    DbValue.SetValue(TypeDecoder.DecodeBoolean(buffer));
                    break;

                case IscCodes.SQL_TIMESTAMP_TZ:
                {
                    var date = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    var tzId = BitConverter.ToUInt16(buffer, 8);
                    var dt   = DateTime.SpecifyKind(date.Add(time), DateTimeKind.Utc);
                    DbValue.SetValue(TypeHelper.CreateZonedDateTime(dt, tzId, null));
                    break;
                }

                case IscCodes.SQL_TIMESTAMP_TZ_EX:
                {
                    var date   = TypeDecoder.DecodeDate(BitConverter.ToInt32(buffer, 0));
                    var time   = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 4));
                    var tzId   = BitConverter.ToUInt16(buffer, 8);
                    var offset = BitConverter.ToInt16(buffer, 10);
                    var dt     = DateTime.SpecifyKind(date.Add(time), DateTimeKind.Utc);
                    DbValue.SetValue(TypeHelper.CreateZonedDateTime(dt, tzId, offset));
                    break;
                }

                case IscCodes.SQL_TIME_TZ:
                {
                    var time = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    var tzId = BitConverter.ToUInt16(buffer, 4);
                    DbValue.SetValue(TypeHelper.CreateZonedTime(time, tzId, null));
                    break;
                }

                case IscCodes.SQL_TIME_TZ_EX:
                {
                    var time   = TypeDecoder.DecodeTime(BitConverter.ToInt32(buffer, 0));
                    var tzId   = BitConverter.ToUInt16(buffer, 4);
                    var offset = BitConverter.ToInt16(buffer, 6);
                    DbValue.SetValue(TypeHelper.CreateZonedTime(time, tzId, offset));
                    break;
                }

                case IscCodes.SQL_DEC16:
                    DbValue.SetValue(DecimalCodec.DecFloat16.ParseBytes(buffer));
                    break;

                case IscCodes.SQL_DEC34:
                    DbValue.SetValue(DecimalCodec.DecFloat34.ParseBytes(buffer));
                    break;

                case IscCodes.SQL_INT128:
                    if (_numericScale < 0)
                    {
                        DbValue.SetValue(TypeDecoder.DecodeDecimal(Int128Helper.GetInt128(buffer), _numericScale, _dataType));
                    }
                    else
                    {
                        DbValue.SetValue(Int128Helper.GetInt128(buffer));
                    }
                    break;

                default:
                    throw TypeHelper.InvalidDataType(SqlType);
                }
            }
        }
コード例 #22
0
		private static string GetString(Charset charset, byte[] buffer, short bufferLength)
		{
			return charset.GetString(buffer, 0, bufferLength);
		}
コード例 #23
0
		public XdrStream(Charset charset)
			: this(new MemoryStream(), charset)
		{ }
コード例 #24
0
        public static IscException ParseStatusVector(IntPtr[] statusVector, Charset charset)
        {
            IscException exception = null;
            bool eof = false;

            for (int i = 0; i < statusVector.Length; )
            {
                IntPtr arg = statusVector[i++];

                switch (arg.ToInt32())
                {
                    case IscCodes.isc_arg_gds:
                        IntPtr er = statusVector[i++];
                        if (er != IntPtr.Zero)
                        {
                            if (exception == null)
                            {
                                exception = new IscException();
                            }
                            exception.Errors.Add(new IscError(arg.ToInt32(), er.ToInt32()));
                        }
                        break;

                    case IscCodes.isc_arg_end:
                        if (exception != null && exception.Errors.Count != 0)
                        {
							exception.BuildExceptionData();
                        }
                        eof = true;
                        break;

                    case IscCodes.isc_arg_interpreted:
                    case IscCodes.isc_arg_string:
                        {
                            IntPtr ptr = statusVector[i++];
                            string s = Marshal.PtrToStringAnsi(ptr);
                            string arg_value = charset.GetString(
                                System.Text.Encoding.Default.GetBytes(s));

                            exception.Errors.Add(new IscError(arg.ToInt32(), arg_value));
                        }
                        break;

                    case IscCodes.isc_arg_cstring:
                        {
                            i++;

                            IntPtr ptr = statusVector[i++];
                            string s = Marshal.PtrToStringAnsi(ptr);
                            string arg_value = charset.GetString(
                                System.Text.Encoding.Default.GetBytes(s));

                            exception.Errors.Add(new IscError(arg.ToInt32(), arg_value));
                        }
                        break;

                    case IscCodes.isc_arg_win32:
                    case IscCodes.isc_arg_number:
                        exception.Errors.Add(new IscError(arg.ToInt32(), statusVector[i++].ToInt32()));
                        break;

                    default:
						IntPtr e = statusVector[i++];
						if (e != IntPtr.Zero)
						{
							if (exception == null)
							{
								exception = new IscException();
							}
							exception.Errors.Add(new IscError(arg.ToInt32(), e.ToInt32()));
						}
                        break;
                }

                if (eof)
                {
                    break;
                }
            }

            return exception;
        }
コード例 #25
0
		public XdrStream(byte[] buffer, Charset charset)
			: this(new MemoryStream(buffer), charset)
		{ }
コード例 #26
0
		public FesDatabase(string dllName, Charset charset)
		{
			_fbClient = FbClientFactory.GetFbClient(dllName);
			_charset = (charset != null ? charset : Charset.DefaultCharset);
			_dialect = 3;
			_packetSize = 8192;
			_statusVector = new IntPtr[IscCodes.ISC_STATUS_LENGTH];
		}
コード例 #27
0
		public override void Close()
		{
			try
			{
				if (this.innerStream != null)
				{
					this.innerStream.Close();
				}
			}
			catch
			{
			}
			finally
			{
				this.charset = null;
				this.innerStream = null;
			}
		}
コード例 #28
0
		private void Dispose(bool disposing)
		{
			lock (this)
			{
				if (!this.disposed)
				{
					try
					{
						// release any unmanaged resources
						this.Detach();

						// release any managed resources
						if (disposing)
						{
							this.warningMessage = null;
							this.charset = null;
							this.serverVersion = null;
							this.transactionCount = 0;
							this.dialect = 0;
							this.handle = 0;
							this.packetSize = 0;
						}
					}
					finally
					{
						this.disposed = true;
					}
				}
			}
		}
コード例 #29
0
		public string ReadString(Charset charset)
		{
			return this.ReadString(charset, this.ReadInt32());
		}
コード例 #30
0
		public Descriptor MarshalNativeToManaged(Charset charset, IntPtr pNativeData, bool fetching)
		{
			// Obtain XSQLDA information
			XSQLDA xsqlda = new XSQLDA();

			xsqlda = (XSQLDA)Marshal.PtrToStructure(pNativeData, typeof(XSQLDA));

			// Create a	new	Descriptor
			Descriptor descriptor   = new Descriptor(xsqlda.sqln);
			descriptor.ActualCount  = xsqlda.sqld;

			// Obtain XSQLVAR members information
			XSQLVAR[] xsqlvar = new XSQLVAR[xsqlda.sqln];

			for (int i = 0; i < xsqlvar.Length; i++)
			{
				IntPtr ptr = this.GetIntPtr(pNativeData, this.ComputeLength(i));
				xsqlvar[i] = (XSQLVAR)Marshal.PtrToStructure(ptr, typeof(XSQLVAR));

				// Map XSQLVAR information to Descriptor
				descriptor[i].DataType      = xsqlvar[i].sqltype;
				descriptor[i].NumericScale  = xsqlvar[i].sqlscale;
				descriptor[i].SubType       = xsqlvar[i].sqlsubtype;
				descriptor[i].Length        = xsqlvar[i].sqllen;

				// Decode sqlind value
				if (xsqlvar[i].sqlind == IntPtr.Zero)
				{
					descriptor[i].NullFlag = 0;
				}
				else
				{
					descriptor[i].NullFlag = Marshal.ReadInt16(xsqlvar[i].sqlind);
				}

				// Set value
				if (fetching)
				{
					if (descriptor[i].NullFlag != -1)
					{
						descriptor[i].SetValue(this.GetBytes(xsqlvar[i]));
					}
				}

				descriptor[i].Name      = this.GetString(charset, xsqlvar[i].sqlname);
				descriptor[i].Relation  = this.GetString(charset, xsqlvar[i].relname);
				descriptor[i].Owner     = this.GetString(charset, xsqlvar[i].ownername);
				descriptor[i].Alias     = this.GetString(charset, xsqlvar[i].aliasname);
			}

			return descriptor;
		}
コード例 #31
0
		public string ReadString(Charset charset, int length)
		{
			byte[] buffer = this.ReadOpaque(length);

			return charset.GetString(buffer, 0, buffer.Length);
		}
コード例 #32
0
		private string GetString(Charset charset, byte[] buffer)
		{
			string value = charset.GetString(buffer);

			return value.TrimEnd('\0', ' ');
		}
コード例 #33
0
        public object MarshalNativeToManaged(Charset charset, IntPtr pNativeData)
        {
            // Obtain ParamDsc information
            ParamDsc descriptor = (ParamDsc)Marshal.PtrToStructure(pNativeData, typeof(ParamDsc));

            return this.GetValue(descriptor, charset);
        }
コード例 #34
0
		public GdsConnection(string dataSource, int portNumber, int packetSize, Charset characterSet)
		{
			_dataSource = dataSource;
			_portNumber = portNumber;
			_packetSize = packetSize;
			_characterSet = characterSet;
		}
コード例 #35
0
 protected BlobBase(IDatabase db)
 {
     this.segmentSize = db.PacketSize;
     this.charset     = db.Charset;
 }