示例#1
0
        /// <summary>
        /// isc_database_info
        /// </summary>
        private void DatabaseInfo(byte[] items, byte[] buffer, int bufferLength)
        {
            lock (SyncObject)
            {
                try
                {
                    // see src/remote/protocol.h for packet	definition (p_info struct)
                    XdrStream.Write(IscCodes.op_info_database);               //	operation
                    XdrStream.Write(_handle);                                 //	db_handle
                    XdrStream.Write(0);                                       //	incarnation
                    XdrStream.WriteBuffer(items, items.Length);               //	items
                    XdrStream.Write(bufferLength);                            //	result buffer length

                    XdrStream.Flush();

                    GenericResponse response = (GenericResponse)ReadResponse();

                    int responseLength = bufferLength;

                    if (response.Data.Length < bufferLength)
                    {
                        responseLength = response.Data.Length;
                    }

                    Buffer.BlockCopy(response.Data, 0, buffer, 0, responseLength);
                }
                catch (IOException ex)
                {
                    throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
                }
            }
        }
示例#2
0
        private void DatabaseInfo(byte[] items, byte[] buffer, int bufferLength)
        {
            try
            {
                XdrStream.Write(IscCodes.op_info_database);
                XdrStream.Write(_handle);
                XdrStream.Write(Incarnation);
                XdrStream.WriteBuffer(items, items.Length);
                XdrStream.Write(bufferLength);

                XdrStream.Flush();

                GenericResponse response = (GenericResponse)ReadResponse();

                int responseLength = bufferLength;

                if (response.Data.Length < bufferLength)
                {
                    responseLength = response.Data.Length;
                }

                Buffer.BlockCopy(response.Data, 0, buffer, 0, responseLength);
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_network_error, ex);
            }
        }
示例#3
0
        public void QueueEvents(RemoteEvent remoteEvent)
        {
            try
            {
                if (_eventManager == null)
                {
                    ConnectionRequest(out var auxHandle, out var ipAddress, out var portNumber);
                    _eventManager = new GdsEventManager(auxHandle, ipAddress, portNumber);
                    var dummy = _eventManager.WaitForEventsAsync(remoteEvent);
                }

                remoteEvent.LocalId++;

                EventParameterBuffer epb = remoteEvent.BuildEpb();
                byte[] epbData           = epb.ToArray();

                XdrStream.Write(IscCodes.op_que_events);
                XdrStream.Write(_handle);
                XdrStream.WriteBuffer(epbData);
                XdrStream.Write(AddressOfAstRoutine);
                XdrStream.Write(ArgumentToAstRoutine);
                XdrStream.Write(remoteEvent.LocalId);

                XdrStream.Flush();

                GenericResponse response = (GenericResponse)ReadResponse();

                remoteEvent.RemoteId = response.ObjectHandle;
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
            }
        }
示例#4
0
 protected virtual void SendAttachToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     XdrStream.Write(IscCodes.op_attach);
     XdrStream.Write(0);
     if (!string.IsNullOrEmpty(Password))
     {
         dpb.Append(IscCodes.isc_dpb_password, Password);
     }
     XdrStream.WriteBuffer(Encoding.Default.GetBytes(database));
     XdrStream.WriteBuffer(dpb.ToArray());
 }
 protected virtual void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
 {
     XdrStream.Write(IscCodes.op_create);
     XdrStream.Write(DatabaseObjectId);
     if (!string.IsNullOrEmpty(Password))
     {
         dpb.Append(IscCodes.isc_dpb_password, Password);
     }
     XdrStream.WriteBuffer(Encoding2.Default.GetBytes(database));
     XdrStream.WriteBuffer(dpb.ToArraySegment());
 }
示例#6
0
        protected virtual void SendCreateToBuffer(DatabaseParameterBuffer dpb, string database)
        {
            XdrStream.Write(IscCodes.op_create);
#warning Some constant for default database object ID
            XdrStream.Write(0);
            if (!string.IsNullOrEmpty(Password))
            {
                dpb.Append(IscCodes.isc_dpb_password, Password);
            }
            XdrStream.WriteBuffer(Encoding.Default.GetBytes(database));
            XdrStream.WriteBuffer(dpb.ToArray());
        }
示例#7
0
        public void QueueEvents(RemoteEvent events)
        {
            if (_eventManager == null)
            {
                string ipAddress  = string.Empty;
                int    portNumber = 0;
                int    auxHandle  = 0;

                ConnectionRequest(out auxHandle, out ipAddress, out portNumber);

                _eventManager = new GdsEventManager(auxHandle, ipAddress, portNumber);
            }

            lock (SyncObject)
            {
                try
                {
                    events.LocalId = Interlocked.Increment(ref _eventsId);

                    // Enqueue events in the event manager
                    _eventManager.QueueEvents(events);

                    EventParameterBuffer epb = events.ToEpb();

                    XdrStream.Write(IscCodes.op_que_events);
                    XdrStream.Write(_handle);                                     // Database object id
                    XdrStream.WriteBuffer(epb.ToArray());                         // Event description block
                    XdrStream.Write(0);                                           // Address of ast routine
                    XdrStream.Write(0);                                           // Argument to ast routine
                    XdrStream.Write(events.LocalId);                              // Client side id of remote event

                    XdrStream.Flush();

                    GenericResponse response = (GenericResponse)ReadResponse();

                    // Update event	Remote event ID
                    events.RemoteId = response.ObjectHandle;
                }
                catch (IOException ex)
                {
                    throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
                }
            }
        }
示例#8
0
        private byte[] ReceiveSliceResponse(ArrayDesc desc)
        {
            try
            {
                int operation = _database.ReadOperation();

                if (operation == IscCodes.op_slice)
                {
                    bool isVariying = false;
                    int  elements   = 0;
                    int  length     = _database.XdrStream.ReadInt32();

                    length = _database.XdrStream.ReadInt32();

                    switch (desc.DataType)
                    {
                    case IscCodes.blr_text:
                    case IscCodes.blr_text2:
                    case IscCodes.blr_cstring:
                    case IscCodes.blr_cstring2:
                        elements = length / desc.Length;
                        length  += elements * ((4 - desc.Length) & 3);
                        break;

                    case IscCodes.blr_varying:
                    case IscCodes.blr_varying2:
                        elements   = length / desc.Length;
                        isVariying = true;
                        break;

                    case IscCodes.blr_short:
                        length = length * desc.Length;
                        break;
                    }

                    if (isVariying)
                    {
                        using (XdrStream xdr = new XdrStream())
                        {
                            for (int i = 0; i < elements; i++)
                            {
                                byte[] buffer = _database.XdrStream.ReadOpaque(_database.XdrStream.ReadInt32());

                                xdr.WriteBuffer(buffer, buffer.Length);
                            }

                            return(xdr.ToArray());
                        }
                    }
                    else
                    {
                        return(_database.XdrStream.ReadOpaque(length));
                    }
                }
                else
                {
                    _database.SetOperation(operation);
                    _database.ReadResponse();

                    return(null);
                }
            }
            catch (IOException ex)
            {
                throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
            }
        }
		private byte[] ReceiveSliceResponse(ArrayDesc desc)
		{
			try
			{
				int operation = _database.ReadOperation();

				if (operation == IscCodes.op_slice)
				{
					// Read	slice length
					bool	isVariying = false;
					int		elements = 0;
					int		length = _database.ReadInt32();

					length = _database.ReadInt32();

					switch (desc.DataType)
					{
						case IscCodes.blr_text:
						case IscCodes.blr_text2:
						case IscCodes.blr_cstring:
						case IscCodes.blr_cstring2:
							elements = length / desc.Length;
							length += elements * ((4 - desc.Length) & 3);
							break;

						case IscCodes.blr_varying:
						case IscCodes.blr_varying2:
							elements = length / desc.Length;
							isVariying = true;
							break;

						case IscCodes.blr_short:
							length = length * desc.Length;
							break;
					}

					if (isVariying)
					{
						XdrStream xdr = new XdrStream();

						for (int i = 0; i < elements; i++)
						{
							byte[] buffer = _database.ReadOpaque(_database.ReadInt32());

							xdr.WriteBuffer(buffer, buffer.Length);
						}

						return xdr.ToArray();
					}
					else
					{
						return _database.ReadOpaque(length);
					}
				}
				else
				{
					_database.SetOperation(operation);
					_database.ReadResponse();

					return null;
				}
			}
			catch (IOException)
			{
				throw new IscException(IscCodes.isc_net_read_err);
			}
		}
示例#10
0
        protected void WriteRawParameter(XdrStream xdr, DbField field)
        {
            if (field.DbDataType != DbDataType.Null)
            {
                field.FixNull();

                switch (field.DbDataType)
                {
                case DbDataType.Char:
                    if (field.Charset.IsOctetsCharset)
                    {
                        xdr.WriteOpaque(field.DbValue.GetBinary(), field.Length);
                    }
                    else
                    {
                        var svalue = field.DbValue.GetString();

                        if ((field.Length % field.Charset.BytesPerCharacter) == 0 &&
                            svalue.Length > field.CharCount)
                        {
                            throw IscException.ForErrorCodes(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation });
                        }

                        xdr.WriteOpaque(field.Charset.GetBytes(svalue), field.Length);
                    }
                    break;

                case DbDataType.VarChar:
                    if (field.Charset.IsOctetsCharset)
                    {
                        xdr.WriteBuffer(field.DbValue.GetBinary());
                    }
                    else
                    {
                        var svalue = field.DbValue.GetString();

                        if ((field.Length % field.Charset.BytesPerCharacter) == 0 &&
                            svalue.Length > field.CharCount)
                        {
                            throw IscException.ForErrorCodes(new[] { IscCodes.isc_arith_except, IscCodes.isc_string_truncation });
                        }

                        xdr.WriteBuffer(field.Charset.GetBytes(svalue));
                    }
                    break;

                case DbDataType.SmallInt:
                    xdr.Write(field.DbValue.GetInt16());
                    break;

                case DbDataType.Integer:
                    xdr.Write(field.DbValue.GetInt32());
                    break;

                case DbDataType.BigInt:
                case DbDataType.Array:
                case DbDataType.Binary:
                case DbDataType.Text:
                    xdr.Write(field.DbValue.GetInt64());
                    break;

                case DbDataType.Decimal:
                case DbDataType.Numeric:
                    xdr.Write(field.DbValue.GetDecimal(), field.DataType, field.NumericScale);
                    break;

                case DbDataType.Float:
                    xdr.Write(field.DbValue.GetFloat());
                    break;

                case DbDataType.Guid:
                    xdr.Write(field.DbValue.GetGuid());
                    break;

                case DbDataType.Double:
                    xdr.Write(field.DbValue.GetDouble());
                    break;

                case DbDataType.Date:
                    xdr.Write(field.DbValue.GetDate());
                    break;

                case DbDataType.Time:
                    xdr.Write(field.DbValue.GetTime());
                    break;

                case DbDataType.TimeStamp:
                    xdr.Write(field.DbValue.GetDate());
                    xdr.Write(field.DbValue.GetTime());
                    break;

                case DbDataType.Boolean:
                    xdr.Write(field.DbValue.GetBoolean());
                    break;

                default:
                    throw IscException.ForStrParam($"Unknown SQL data type: {field.DataType}.");
                }
            }
        }
 public void WriteBuffer(byte[] buffer)
 {
     _outputStream.WriteBuffer(buffer);
 }
        public virtual void Identify(string database)
        {
            // handles this.networkStream
            XdrStream inputStream  = this.CreateXdrStream();
            XdrStream outputStream = this.CreateXdrStream();

            try
            {
                outputStream.Write(IscCodes.op_connect);
                outputStream.Write(IscCodes.op_attach);
                outputStream.Write(IscCodes.CONNECT_VERSION2);                  // CONNECT_VERSION2
                outputStream.Write(1);                                          // Architecture	of client -	Generic

                outputStream.Write(database);                                   // Database	path
                outputStream.Write(3);                                          // Protocol	versions understood
                outputStream.WriteBuffer(UserIdentificationStuff());            // User	identification Stuff

                outputStream.Write(IscCodes.PROTOCOL_VERSION10);                //	Protocol version
                outputStream.Write(1);                                          // Architecture	of client -	Generic
                outputStream.Write(2);                                          // Minimum type (ptype_rpc)
                outputStream.Write(3);                                          // Maximum type (ptype_batch_send)
                outputStream.Write(0);                                          // Preference weight

                outputStream.Write(IscCodes.PROTOCOL_VERSION11);                //	Protocol version
                outputStream.Write(1);                                          // Architecture	of client -	Generic
                outputStream.Write(2);                                          // Minumum type (ptype_rpc)
                outputStream.Write(5);                                          // Maximum type (ptype_lazy_send)
                outputStream.Write(1);                                          // Preference weight

                outputStream.Write(IscCodes.PROTOCOL_VERSION12);                //	Protocol version
                outputStream.Write(1);                                          // Architecture	of client -	Generic
                outputStream.Write(2);                                          // Minumum type (ptype_rpc)
                outputStream.Write(5);                                          // Maximum type (ptype_lazy_send)
                outputStream.Write(2);                                          // Preference weight

                outputStream.Flush();

                if (inputStream.ReadOperation() == IscCodes.op_accept)
                {
                    this.protocolVersion      = inputStream.ReadInt32();                // Protocol	version
                    this.protocolArchitecture = inputStream.ReadInt32();                // Architecture	for	protocol
                    this.protocolMinimunType  = inputStream.ReadInt32();                // Minimum type

                    if (this.protocolVersion < 0)
                    {
                        this.protocolVersion = (ushort)(this.protocolVersion & IscCodes.FB_PROTOCOL_MASK) | IscCodes.FB_PROTOCOL_FLAG;
                    }
                }
                else
                {
                    try
                    {
                        this.Disconnect();
                    }
                    catch
                    {
                    }
                    finally
                    {
                        throw new IscException(IscCodes.isc_connect_reject);
                    }
                }
            }
            catch (IOException)
            {
                throw new IscException(IscCodes.isc_network_error);
            }
        }
        public virtual void Identify(string database)
        {
            // handles this.networkStream
            XdrStream inputStream  = this.CreateXdrStream();
            XdrStream outputStream = this.CreateXdrStream();

            try
            {
                // Here	we identify	the	user to	the	engine.
                // This	may	or may not be used as login	info to	a database.
#if     (!NET_CF)
                byte[] user = Encoding.Default.GetBytes(System.Environment.UserName);
                byte[] host = Encoding.Default.GetBytes(System.Net.Dns.GetHostName());
#else
                byte[] user = Encoding.Default.GetBytes("fbnetcf");
                byte[] host = Encoding.Default.GetBytes(System.Net.Dns.GetHostName());
#endif

                using (MemoryStream user_id = new MemoryStream())
                {
                    // User	Name
                    user_id.WriteByte(1);
                    user_id.WriteByte((byte)user.Length);
                    user_id.Write(user, 0, user.Length);

                    // Host	name
                    user_id.WriteByte(4);
                    user_id.WriteByte((byte)host.Length);
                    user_id.Write(host, 0, host.Length);

                    // Attach/create using this connection will use user verification
                    user_id.WriteByte(6);
                    user_id.WriteByte(0);

                    outputStream.Write(IscCodes.op_connect);
                    outputStream.Write(IscCodes.op_attach);
                    outputStream.Write(IscCodes.CONNECT_VERSION2);   // CONNECT_VERSION2
                    outputStream.Write(1);                           // Architecture	of client -	Generic

                    outputStream.Write(database);                    // Database	path
                    outputStream.Write(3);                           // Protocol	versions understood
                    outputStream.WriteBuffer(user_id.ToArray());     // User	identification Stuff

                    outputStream.Write(IscCodes.PROTOCOL_VERSION10); //	Protocol version
                    outputStream.Write(1);                           // Architecture	of client -	Generic
                    outputStream.Write(2);                           // Minimum type (ptype_rpc)
                    outputStream.Write(3);                           // Maximum type (ptype_batch_send)
                    outputStream.Write(0);                           // Preference weight

                    outputStream.Write(IscCodes.PROTOCOL_VERSION11); //	Protocol version
                    outputStream.Write(1);                           // Architecture	of client -	Generic
                    outputStream.Write(2);                           // Minumum type (ptype_rpc)
                    outputStream.Write(5);                           // Maximum type (ptype_lazy_send)
                    outputStream.Write(1);                           // Preference weight

                    outputStream.Write(IscCodes.PROTOCOL_VERSION12); //	Protocol version
                    outputStream.Write(1);                           // Architecture	of client -	Generic
                    outputStream.Write(2);                           // Minumum type (ptype_rpc)
                    outputStream.Write(5);                           // Maximum type (ptype_lazy_send)
                    outputStream.Write(2);                           // Preference weight
                }
                outputStream.Flush();

                if (inputStream.ReadOperation() == IscCodes.op_accept)
                {
                    this.protocolVersion      = inputStream.ReadInt32(); // Protocol	version
                    this.protocolArchitecture = inputStream.ReadInt32(); // Architecture	for	protocol
                    this.protocolMinimunType  = inputStream.ReadInt32(); // Minimum type

                    if (this.protocolVersion < 0)
                    {
                        this.protocolVersion = (ushort)(this.protocolVersion & IscCodes.FB_PROTOCOL_MASK) | IscCodes.FB_PROTOCOL_FLAG;
                    }
                }
                else
                {
                    try
                    {
                        this.Disconnect();
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        throw new IscException(IscCodes.isc_connect_reject);
                    }
                }
            }
            catch (IOException)
            {
                throw new IscException(IscCodes.isc_network_error);
            }
        }