public GenericResponse(int objectHandle, long blobId, byte[] data, IscException exception)
		{
			_objectHandle = objectHandle;
			_blobId = blobId;
			_data = data;
			_exception = exception;
		}
		public GenericResponse(int objectHandle, long blobId, byte[] data, IscException exception)
		{
			this.objectHandle	= objectHandle;
			this.blobId			= blobId;
			this.data			= data;
			this.exception      = exception;
		}
		internal FbException(string message, IscException ex) : base(message)
		{
			this.errorCode = ex.ErrorCode;
#if	(!NETCF)
			this.Source = ex.Source;
#endif

			this.GetIscExceptionErrors(ex);
		}
        internal FbInfoMessageEventArgs(IscException ex)
        {
            this.message = ex.Message;

            foreach (IscError error in ex.Errors)
            {
                this.errors.Add(error.Message, error.ErrorCode);
            }
        }
		internal FbInfoMessageEventArgs(IscException ex)
		{
			_message = ex.Message;
			_errors = new FbErrorCollection();
			foreach (IscError error in ex.Errors)
			{
				_errors.Add(error.Message, error.ErrorCode);
			}
		}
Example #6
0
 public static IscException ForIOException(IOException exception)
 {
     return(IscException.ForErrorCodes(new[] { IscCodes.isc_net_write_err, IscCodes.isc_net_read_err }, exception));
 }
		internal void GetIscExceptionErrors(IscException ex)
		{
			foreach (IscError error in ex.Errors)
			{
				this.errors.Add(error.Message, error.ErrorCode);
			}
		}
        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;
        }
Example #9
0
		public int GetErrorMessage(ref StringBuilder errorMessage)
		{
			if (this.lastError != null)
			{
				errorMessage.Append(this.lastError.Message);

				this.lastError = null;
			}

			return 0;
		}
Example #10
0
		public int Rollback(int transID)
		{
			try
			{
				if (this.Transactions.ContainsKey(transID))
				{
					ITransaction transaction = (ITransaction)this.Transactions[transID];
					if (transaction.State != TransactionState.NoTransaction)
					{
						transaction.Rollback();
					}
				}
				else
				{
					throw new InvalidOperationException();
				}
			}
			catch (IscException e)
			{
				this.lastError = e;
			}
			finally
			{
				this.Transactions.Remove(transID);

				if (transID > 0)
				{
					this.transactionId = -1;
				}
			}

			return this.GetErrorCode();
		}
Example #11
0
		public int BeginTransaction(int transID, int isolationLevel)
		{
			IsolationLevel isolLevel = (IsolationLevel)isolationLevel;

			try
			{
				ITransaction transaction = this.db.BeginTransaction(this.BuildTpb(isolLevel));                
				this.Transactions.Add(transID, transaction);

				if (transID > 0)
				{
					this.transactionId = transID;
				}
			}
			catch (IscException e)
			{
				this.lastError = e;
			}

			return this.GetErrorCode();
		}
Example #12
0
		public int Release()
		{
			this.command.CommitImplicitTransaction();
			this.command.Close();
			this.fields		= null;
			this.row		= null;
			this.lastError	= null;
			this.isReleased	= true;
			this.eof		= true;

			return 0;
		}
		public static IscException ForErrorCode(int errorCode, Exception innerException = null)
		{
			var result = new IscException(innerException);
			result.Errors.Add(new IscError(IscCodes.isc_arg_gds, errorCode));
			result.BuildExceptionData();
			return result;
		}
		public static IscException ForTypeErrorCodeIntParamStrParam(int type, int errorCode, int intParam, string strParam, Exception innerException = null)
		{
			var result = new IscException(innerException);
			result.Errors.Add(new IscError(type, errorCode));
			result.Errors.Add(new IscError(IscCodes.isc_arg_number, intParam));
			result.Errors.Add(new IscError(IscCodes.isc_arg_string, strParam));
			result.BuildExceptionData();
			return result;
		}
		public static IscException ForStrParam(string strParam, Exception innerException = null)
		{
			var result = new IscException(innerException);
			result.Errors.Add(new IscError(IscCodes.isc_arg_string, strParam));
			result.BuildExceptionData();
			return result;
		}
		public static IscException ForSQLSTATE(string sqlState, Exception innerException = null)
		{
			var result = new IscException(innerException);
			result.Errors.Add(new IscError(IscCodes.isc_arg_sql_state, sqlState));
			result.BuildExceptionData();
			return result;
		}
		public static void CreateDatabase(Hashtable values)
		{
			bool overwrite = false;
			int index = 0;
			byte dialect = 3;
			int serverType = 0;

			if (!values.ContainsKey("User") ||
				!values.ContainsKey("Password") ||
				!values.ContainsKey("Database"))
			{
				throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
			}

			if (values.ContainsKey("ServerType"))
			{
				serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
			}

			if (!values.ContainsKey("DataSource"))
			{
				values.Add("DataSource", "localhost");
			}

			if (!values.ContainsKey("Port"))
			{
				values.Add("Port", 3050);
			}

			if (values.ContainsKey("Dialect"))
			{
				dialect = Convert.ToByte(values["Dialect"], CultureInfo.InvariantCulture);
			}

			if (dialect < 1 || dialect > 3)
			{
				throw new ArgumentException("Incorrect database dialect it should be 1, 2, or 3.");
			}

			if (values.ContainsKey("Overwrite"))
			{
				overwrite = (bool)values["Overwrite"];
			}

			try
			{
				// Configure Attachment
				FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

				csb.DataSource	= values["DataSource"].ToString();
				csb.UserID		= values["User"].ToString();
				csb.Password	= values["Password"].ToString();
				csb.Database	= values["Database"].ToString();
				csb.Port		= Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
				csb.ServerType	= serverType;

				FbConnectionString options = new FbConnectionString(csb);

				// DPB configuration
				DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

				// Dpb version
				dpb.Append(IscCodes.isc_dpb_version1);

				// Dummy packet	interval
				dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

				// User	name
				dpb.Append(IscCodes.isc_dpb_user_name, values["User"].ToString());

				// User	password
				dpb.Append(IscCodes.isc_dpb_password, values["Password"].ToString());

				// Database	dialect
				dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { dialect, 0, 0, 0 });

				// Database overwrite
				dpb.Append(IscCodes.isc_dpb_overwrite, (short)(overwrite ? 1 : 0));

				// Character set
				if (values.ContainsKey("Charset"))
				{
					index = Charset.SupportedCharsets.IndexOf(values["Charset"].ToString());

					if (index == -1)
					{
						throw new ArgumentException("Character set is not valid.");
					}
					else
					{
						dpb.Append(
							IscCodes.isc_dpb_set_db_charset,
							Charset.SupportedCharsets[index].Name);
					}
				}

				// Page	Size
				if (values.ContainsKey("PageSize"))
				{
					dpb.Append(IscCodes.isc_dpb_page_size, Convert.ToInt32(values["PageSize"], CultureInfo.InvariantCulture));
				}

				// Forced writes
				if (values.ContainsKey("ForcedWrite"))
				{
					dpb.Append(IscCodes.isc_dpb_force_write,
						(short)((bool)values["ForcedWrite"] ? 1 : 0));
				}

				if (!overwrite)
				{
					try
					{
						// Check if	the	database exists
						FbConnectionInternal check = new FbConnectionInternal(options);

						check.Connect();
						check.Disconnect();

						IscException ex = new IscException(IscCodes.isc_db_or_file_exists);

						throw new FbException(ex.Message, ex);
					}
					catch (Exception)
					{
						throw;
					}
				}

				// Create the new database
				FbConnectionInternal c = new FbConnectionInternal(options);
				c.CreateDatabase(dpb);
			}
			catch (IscException ex)
			{
				throw new FbException(ex.Message, ex);
			}
		}
		/// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="CreateDatabase(System.String,System.Int32,System.Boolean,System.Boolean)"]/*'/>
		public static void CreateDatabase(
			string connectionString, int pageSize, bool forcedWrites, bool overwrite)
		{
			FbConnectionString options = new FbConnectionString(connectionString);
			options.Validate();

			try
			{
				// DPB configuration
				DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

				// Dpb version
				dpb.Append(IscCodes.isc_dpb_version1);

				// Dummy packet	interval
				dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

				// User	name
				dpb.Append(IscCodes.isc_dpb_user_name, options.UserID);

				// User	password
				dpb.Append(IscCodes.isc_dpb_password, options.Password);

				// Database	dialect
				dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { options.Dialect, 0, 0, 0 });

				// Database overwrite
				dpb.Append(IscCodes.isc_dpb_overwrite, (short)(overwrite ? 1 : 0));

				// Character set
				if (options.Charset.Length > 0)
				{
					int index = Charset.SupportedCharsets.IndexOf(options.Charset);

					if (index == -1)
					{
						throw new ArgumentException("Character set is not valid.");
					}
					else
					{
						dpb.Append(
							IscCodes.isc_dpb_set_db_charset,
							Charset.SupportedCharsets[index].Name);
					}
				}

				// Page	Size
				if (pageSize > 0)
				{
					dpb.Append(IscCodes.isc_dpb_page_size, pageSize);
				}

				// Forced writes
				dpb.Append(IscCodes.isc_dpb_force_write, (short)(forcedWrites ? 1 : 0));

				if (!overwrite)
				{
					// Check if	the	database exists
					FbConnectionInternal c = new FbConnectionInternal(options);

					try
					{
						c.Connect();
						c.Disconnect();

						IscException ex = new IscException(IscCodes.isc_db_or_file_exists);
						throw new FbException(ex.Message, ex);
					}
					catch (FbException ex)
					{
						if (ex.ErrorCode != 335544344)
						{
							throw;
						}
					}
				}

				// Create the new database
				FbConnectionInternal db = new FbConnectionInternal(options);
				db.CreateDatabase(dpb);
			}
			catch (IscException ex)
			{
				throw new FbException(ex.Message, ex);
			}
		}
		public static IscException ForErrorCodes(IEnumerable<int> errorCodes, Exception innerException = null)
		{
			var result = new IscException(innerException);
			foreach (int errorCode in errorCodes)
			{
				result.Errors.Add(new IscError(IscCodes.isc_arg_gds, errorCode));
			}
			result.BuildExceptionData();
			return result;
		}
Example #20
0
		public int Next()
		{
			this.CheckState();
			this.CheckPosition();

			int result = 0;

			try
			{
				row = this.command.Fetch();
				if (row == null)
				{
					result		= -1;
					this.eof	= true;
				}
			}
			catch (IscException e)
			{
				this.lastError = e;
			}

			return (this.GetErrorCode() != 0 ? this.GetErrorCode() : result);
		}
Example #21
0
        public void FixNull()
        {
            if (NullFlag == -1 && _dbValue.IsDBNull())
            {
                switch (DbDataType)
                {
                case DbDataType.Char:
                case DbDataType.VarChar:
                    Value = string.Empty;
                    break;

                case DbDataType.Guid:
                    Value = Guid.Empty;
                    break;

                case DbDataType.SmallInt:
                    Value = (short)0;
                    break;

                case DbDataType.Integer:
                    Value = (int)0;
                    break;

                case DbDataType.BigInt:
                case DbDataType.Binary:
                case DbDataType.Array:
                case DbDataType.Text:
                    Value = (long)0;
                    break;

                case DbDataType.Numeric:
                case DbDataType.Decimal:
                    Value = (decimal)0;
                    break;

                case DbDataType.Float:
                    Value = (float)0;
                    break;

                case DbDataType.Double:
                    Value = (double)0;
                    break;

                case DbDataType.Date:
                case DbDataType.TimeStamp:
                    Value = new DateTime(0 * 10000L + 621355968000000000);
                    break;

                case DbDataType.Time:
                    Value = TimeSpan.Zero;
                    break;

                case DbDataType.Boolean:
                    Value = false;
                    break;

                case DbDataType.TimeStampTZ:
                case DbDataType.TimeStampTZEx:
                    Value = new FbZonedDateTime(new DateTime(0 * 10000L + 621355968000000000), TimeZoneMapping.DefaultTimeZoneName);
                    break;

                case DbDataType.TimeTZ:
                case DbDataType.TimeTZEx:
                    Value = new FbZonedTime(TimeSpan.Zero, TimeZoneMapping.DefaultTimeZoneName);
                    break;

                case DbDataType.Dec16:
                case DbDataType.Dec34:
                    Value = new FbDecFloat(0, 0);
                    break;

                case DbDataType.Int128:
                    Value = (BigInteger)0;
                    break;

                default:
                    throw IscException.ForStrParam($"Unknown sql data type: {DataType}.");
                }
            }
        }
Example #22
0
		public int Disconnect()
		{
			try
			{
                if (this.Transactions.Count > 0)
                {
                    IDictionaryEnumerator e = this.Transactions.GetEnumerator();

                    while (e.MoveNext())
                    {
                        try
                        {
                            // Rollback active transactions
                            ITransaction transaction = (ITransaction)e.Value;
                            transaction.Rollback();
                        }
                        finally
                        {
                        }
                    }
                }

                this.db.Detach();
				
				this.Transactions.Clear();
				this.internalTransactionId	= -1;
				this.transactionId			= -1;
				this.lastError				= null;
				this.db						= null;
			}
			catch (IscException e)
			{
				this.lastError = e;
			}

			return this.GetErrorCode();
		}
		internal void ProcessIscExceptionErrors(IscException innerException)
		{
			foreach (IscError error in innerException.Errors)
			{
				this.Errors.Add(error.Message, error.ErrorCode);
			}
		}
Example #24
0
		public int Commit(int transID)
		{
			try
			{
				if (this.Transactions.ContainsKey(transID))
				{
					ITransaction transaction = (ITransaction)this.Transactions[transID];
					if (transaction.State != TransactionState.NoTransaction)
					{
						transaction.Commit();
					}
				}
				else
				{
					throw new InvalidOperationException();
				}

			    // RPH - Only remove transaction on success.  This allows Rollback to be called.
				this.Transactions.Remove(transID);

				if (transID > 0)
				{
					this.transactionId = -1;
				}
			}
			catch (IscException e)
			{
				this.lastError = e;
			}

            return this.GetErrorCode();
		}
		internal IscException ReadStatusVector()
		{
			IscException exception = null;
			bool eof = false;

			try
			{
				while (!eof)
				{
					int arg = this.receive.ReadInt32();

					switch (arg)
					{
						case IscCodes.isc_arg_gds:
							int er = this.receive.ReadInt32();
							if (er != 0)
							{
								if (exception == null)
								{
									exception = new IscException();
								}
								exception.Errors.Add(arg, er);
							}
							break;

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

						case IscCodes.isc_arg_interpreted:
						case IscCodes.isc_arg_string:
							exception.Errors.Add(arg, this.receive.ReadString());
							break;

						case IscCodes.isc_arg_number:
							exception.Errors.Add(arg, this.receive.ReadInt32());
							break;

						default:
							{
								int e = this.receive.ReadInt32();
								if (e != 0)
								{
									if (exception == null)
									{
										exception = new IscException();
									}
									exception.Errors.Add(arg, e);
								}
							}
							break;
					}
				}
			}
			catch (IOException)
			{
				throw new IscException(IscCodes.isc_arg_gds, IscCodes.isc_net_read_err);
			}

			if (exception != null && !exception.IsWarning)
			{
				throw exception;
			}

			return exception;
		}
Example #26
0
		public int FreeConnect()
		{
			this.lastError				= null;
			this.db						= null;
			this.connectionOptions		= null;
			this.transactions			= null;
			this.connectionProps		= null;
			this.internalTransactionId	= -1;
			this.transactionId			= -1;

			return 0;
		}
 private void OnWarningMessage(IscException warning)
 {
     if (this.InfoMessage != null)
     {
         this.InfoMessage(this, new FbInfoMessageEventArgs(warning));
     }
 }
Example #28
0
		public int Connect(string database, string user, string password, string hostName)
		{
			int		port		= 3050;
			string	dataSource	= hostName;
			string	dbPath		= database;

			try
			{
				string connectionString =
					String.Format(
					"{0}={1};{2}={3};{4}={5};{6}={7};{8}",
					"DataSource", hostName,
					"Database", database,
					"User", user,
					"Password", password,
					this.connectionOptions);

				FbConnectionString cs = new FbConnectionString();
				cs.ConnectionString = connectionString;

				Regex r = new Regex(@"(?<datasource>.*)/(?<port>[0-9]*):(?<database>.*)", RegexOptions.ExplicitCapture);

				Match m = r.Match(database);

				if (m != null)
				{
					if (m.Groups["datasource"].Success)
					{
						dataSource = m.Groups["datasource"].Value;
					}

					if (m.Groups["port"].Success)
					{
						port = Int32.Parse(m.Groups["port"].Value);
					}
				
					if (m.Groups["database"].Success)
					{
						dbPath = m.Groups["database"].Value;
					}
				}

				//  Create database instance
				this.db = ClientFactory.CreateDatabase(cs.ServerType);

				// Build DPB
				DatabaseParameterBuffer dpb = this.db.CreateDatabaseParameterBuffer();

				dpb.Append(IscCodes.isc_dpb_version1);
				dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, 
					new byte[] {120, 10, 0, 0});
				dpb.Append(IscCodes.isc_dpb_sql_dialect, 
					new byte[] {Convert.ToByte(cs.Dialect), 0, 0, 0});
				dpb.Append(IscCodes.isc_dpb_lc_ctype, cs.Charset);
				if (cs.RoleName != null)
				{
					if (cs.RoleName.Length > 0)
					{
						dpb.Append(IscCodes.isc_dpb_sql_role_name, cs.RoleName);
					}
				}
				dpb.Append(IscCodes.isc_dpb_user_name, user);
				dpb.Append(IscCodes.isc_dpb_password, password);

				// Perform attach
				this.db.Attach(dpb, dataSource, port, dbPath);
			}
			catch (IscException e)
			{
				this.lastError = e;
			}

			return this.GetErrorCode();
		}
Example #29
0
		public int Prepare(string sql, short paramCount)
		{
			try
			{
				if (this.statement != null)
				{
					this.Release();
				}

				this.transactionId = this.connection.GetTransactionId();
				if (this.transactionId < 0)
				{
					this.connection.BeginTransaction(this.transactionId, (int)(IsolationLevel.ReadCommitted));
				}

				ITransaction transaction = (ITransaction)this.connection.Transactions[this.transactionId];

				this.statement = this.connection.Database.CreateStatement(transaction);
				
				this.statement.Prepare(sql);
				this.statement.Describe();
				this.statement.DescribeParameters();
			}
			catch (IscException e)
			{
				this.lastError = e;
				this.RollbackImplicitTransaction();
			}

			return this.GetErrorCode();
		}
        public static IscException ParseStatusVector(int[] statusVector)
        {
            IscException exception = null;
            bool eof = false;

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

                switch (arg)
                {
                    case IscCodes.isc_arg_gds:
                        int er = statusVector[i++];
                        if (er != 0)
                        {
                            if (exception == null)
                            {
                                exception = new IscException();
                            }
                            exception.Errors.Add(new IscError(arg, er));
                        }
                        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 = new IntPtr(statusVector[i++]);
                            string arg_value = Marshal.PtrToStringAnsi(ptr);

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

                    case IscCodes.isc_arg_cstring:
                        {
                            i++;

                            IntPtr ptr = new IntPtr(statusVector[i++]);
                            string arg_value = Marshal.PtrToStringAnsi(ptr);

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

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

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

                if (eof)
                {
                    break;
                }
            }

            return exception;
        }
Example #31
0
		protected void EnsureActiveTransactionState()
		{
			if (State != TransactionState.Active)
				throw IscException.ForTypeErrorCodeIntParamStrParam(IscCodes.isc_arg_gds, IscCodes.isc_tra_state, Handle, "no valid");
		}
Example #32
0
        public virtual IscException ReadStatusVector()
        {
            IscException exception = null;
            bool eof = false;

            while (!eof)
            {
                int arg = this.ReadInt32();

                switch (arg)
                {
                    case IscCodes.isc_arg_gds:
                        int er = this.ReadInt32();
                        if (er != 0)
                        {
                            if (exception == null)
                            {
                                exception = new IscException();
                            }
                            exception.Errors.Add(new IscError(arg, er));
                        }
                        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:
                        exception.Errors.Add(new IscError(arg, this.ReadString()));
                        break;

                    case IscCodes.isc_arg_number:
                        exception.Errors.Add(new IscError(arg, this.ReadInt32()));
                        break;

                    case IscCodes.isc_arg_sql_state:
                        exception.Errors.Add(new IscError(arg, this.ReadString()));
                        break;

                    default:
                        int e = this.ReadInt32();
                        if (e != 0)
                        {
                            if (exception == null)
                            {
                                exception = new IscException();
                            }
                            exception.Errors.Add(new IscError(arg, e));
                        }
                        break;
                }
            }

            return exception;
        }
        public async Task FixNull(AsyncWrappingCommonArgs async)
        {
            if (NullFlag == -1 && await _dbValue.IsDBNull(async).ConfigureAwait(false))
            {
                switch (DbDataType)
                {
                case DbDataType.Char:
                case DbDataType.VarChar:
                    DbValue.SetValue(string.Empty);
                    break;

                case DbDataType.Guid:
                    DbValue.SetValue(Guid.Empty);
                    break;

                case DbDataType.SmallInt:
                    DbValue.SetValue((short)0);
                    break;

                case DbDataType.Integer:
                    DbValue.SetValue((int)0);
                    break;

                case DbDataType.BigInt:
                case DbDataType.Binary:
                case DbDataType.Array:
                case DbDataType.Text:
                    DbValue.SetValue((long)0);
                    break;

                case DbDataType.Numeric:
                case DbDataType.Decimal:
                    DbValue.SetValue((decimal)0);
                    break;

                case DbDataType.Float:
                    DbValue.SetValue((float)0);
                    break;

                case DbDataType.Double:
                    DbValue.SetValue((double)0);
                    break;

                case DbDataType.Date:
                case DbDataType.TimeStamp:
                    DbValue.SetValue(new DateTime(0 * 10000L + 621355968000000000));
                    break;

                case DbDataType.Time:
                    DbValue.SetValue(TimeSpan.Zero);
                    break;

                case DbDataType.Boolean:
                    DbValue.SetValue(false);
                    break;

                case DbDataType.TimeStampTZ:
                case DbDataType.TimeStampTZEx:
                    DbValue.SetValue(new FbZonedDateTime(new DateTime(0 * 10000L + 621355968000000000), TimeZoneMapping.DefaultTimeZoneName));
                    break;

                case DbDataType.TimeTZ:
                case DbDataType.TimeTZEx:
                    DbValue.SetValue(new FbZonedTime(TimeSpan.Zero, TimeZoneMapping.DefaultTimeZoneName));
                    break;

                case DbDataType.Dec16:
                case DbDataType.Dec34:
                    DbValue.SetValue(new FbDecFloat(0, 0));
                    break;

                case DbDataType.Int128:
                    DbValue.SetValue((BigInteger)0);
                    break;

                default:
                    throw IscException.ForStrParam($"Unknown sql data type: {DataType}.");
                }
            }
        }
Example #34
0
        public byte[] GetBytes()
        {
            if (IsDBNull())
            {
                int length = _field.Length;

                if (Field.SqlType == IscCodes.SQL_VARYING)
                {
                    // Add two bytes more for store	value length
                    length += 2;
                }

                return(new byte[length]);
            }


            switch (Field.DbDataType)
            {
            case DbDataType.Char:
            {
                var    buffer = new byte[Field.Length];
                byte[] bytes;

                if (Field.Charset.IsOctetsCharset)
                {
                    bytes = GetBinary();
                }
                else
                {
                    var svalue = GetString();

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

                    bytes = Field.Charset.GetBytes(svalue);
                }

                for (var i = 0; i < buffer.Length; i++)
                {
                    buffer[i] = (byte)' ';
                }
                Buffer.BlockCopy(bytes, 0, buffer, 0, bytes.Length);
                return(buffer);
            }

            case DbDataType.VarChar:
            {
                var    buffer = new byte[Field.Length + 2];
                byte[] bytes;

                if (Field.Charset.IsOctetsCharset)
                {
                    bytes = GetBinary();
                }
                else
                {
                    var svalue = GetString();

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

                    bytes = Field.Charset.GetBytes(svalue);
                }

                Buffer.BlockCopy(BitConverter.GetBytes((short)bytes.Length), 0, buffer, 0, 2);
                Buffer.BlockCopy(bytes, 0, buffer, 2, bytes.Length);
                return(buffer);
            }

            case DbDataType.Numeric:
            case DbDataType.Decimal:
                return(GetNumericBytes());

            case DbDataType.SmallInt:
                return(BitConverter.GetBytes(GetInt16()));

            case DbDataType.Integer:
                return(BitConverter.GetBytes(GetInt32()));

            case DbDataType.Array:
            case DbDataType.Binary:
            case DbDataType.Text:
            case DbDataType.BigInt:
                return(BitConverter.GetBytes(GetInt64()));

            case DbDataType.Float:
                return(BitConverter.GetBytes(GetFloat()));

            case DbDataType.Double:
                return(BitConverter.GetBytes(GetDouble()));

            case DbDataType.Date:
                return(BitConverter.GetBytes(TypeEncoder.EncodeDate(GetDateTime())));

            case DbDataType.Time:
                return(BitConverter.GetBytes(GetTime()));

            case DbDataType.TimeStamp:
                var dt   = GetDateTime();
                var date = BitConverter.GetBytes(TypeEncoder.EncodeDate(dt));
                var time = BitConverter.GetBytes(TypeEncoder.EncodeTime(TypeHelper.DateTimeToTimeSpan(dt)));

                var result = new byte[8];

                Buffer.BlockCopy(date, 0, result, 0, date.Length);
                Buffer.BlockCopy(time, 0, result, 4, time.Length);

                return(result);

            case DbDataType.Guid:
                return(GetGuid().ToByteArray());

            case DbDataType.Boolean:
                return(BitConverter.GetBytes(GetBoolean()));

            default:
                throw TypeHelper.InvalidDataType((int)Field.DbDataType);
            }
        }
Example #35
0
		public int SetParameter(
			short				index, 
			short				childPos, 
			ParameterDirection	paramDir, 
			BdpType				dataType, 
			BdpType				subType, 
			int					maxPrecision, 
			int					maxScale, 
			int					length, 
			object				value, 
			bool				isNullable)
		{
			try
			{
                if (paramDir == ParameterDirection.Input ||
                    paramDir == ParameterDirection.InputOutput)
                {
                    this.SetInputParameter(
			                index, 
			                childPos, 
			                paramDir, 
			                dataType, 
                            subType, 
                            maxPrecision, 
			                maxScale, 
			                length, 
			                value, 
			                isNullable);
                }
            }
			catch (IscException e)
			{
				this.lastError = e;
			}

			return this.GetErrorCode();
		}