示例#1
0
文件: DbField.cs 项目: Arcantar/Lumi5
 public DbField()
 {
     this.charCount = -1;
     this.name      = string.Empty;
     this.relation  = string.Empty;
     this.owner     = string.Empty;
     this.alias     = string.Empty;
     this.dbValue   = new DbValue(this, DBNull.Value);
 }
示例#2
0
 public DbField()
 {
     _charCount = -1;
     _name      = string.Empty;
     _relation  = string.Empty;
     _owner     = string.Empty;
     _alias     = string.Empty;
     _dbValue   = new DbValue(this, DBNull.Value);
 }
示例#3
0
 public DbField()
 {
     this.charCount = -1;
     this.name = string.Empty;
     this.relation = string.Empty;
     this.owner = string.Empty;
     this.alias = string.Empty;
     this.dbValue = new DbValue(this, DBNull.Value);
 }
示例#4
0
        internal void SetOutputParameters(DbValue[] outputParameterValues)
        {
            if (this.Parameters.Count > 0 && this.statement != null)
            {
                if (this.statement != null &&
                    this.statement.StatementType == DbStatementType.StoredProcedure)
                {
                    DbValue[] values = outputParameterValues;
                    if (outputParameterValues == null)
                    {
                        values = (DbValue[])this.statement.GetOutputParameters();
                    }

                    if (values != null && values.Length > 0)
                    {
                        int i = 0;
                        foreach (FbParameter parameter in this.Parameters)
                        {
                            if (parameter.Direction == ParameterDirection.Output ||
                                parameter.Direction == ParameterDirection.InputOutput ||
                                parameter.Direction == ParameterDirection.ReturnValue)
                            {
                                parameter.Value = values[i].Value;
                                i++;
                            }
                        }
                    }
                }
            }
        }
		public DbField()
		{
			_charCount = -1;
			_name = string.Empty;
			_relation = string.Empty;
			_owner = string.Empty;
			_alias = string.Empty;
			_dbValue = new DbValue(this, DBNull.Value);
		}
示例#6
0
        public override DbValue[] Fetch()
        {
            DbValue[] row = null;

            if (this.state == StatementState.Deallocated)
            {
                throw new InvalidOperationException("Statement is not correctly created.");
            }
            if (this.statementType != DbStatementType.Select &&
                this.statementType != DbStatementType.SelectForUpdate)
            {
                return null;
            }

            lock (this.db)
            {
                if (!this.allRowsFetched)
                {
                    // Get the XSQLDA Marshaler
                    XsqldaMarshaler marshaler = XsqldaMarshaler.Instance;

                    // Reset actual	field values
                    this.fields.ResetValues();

                    // Marshal structures to pointer
                    IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, fields);

                    // Creta a new status vector
                    int[] statusVector = ExtConnection.GetNewStatusVector();

                    // Statement handle to be passed to the fetch method
                    int stmtHandle = this.handle;

                    // Fetch data
                    int status = SafeNativeMethods.isc_dsql_fetch(statusVector, ref stmtHandle, IscCodes.SQLDA_VERSION1, sqlda);

                    // Obtain values
                    Descriptor rowDesc = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda);

                    if (this.fields.Count == rowDesc.Count)
                    {
                        // Try to preserve Array Handle information
                        for (int i = 0; i < this.fields.Count; i++)
                        {
                            if (this.fields[i].IsArray() && this.fields[i].ArrayHandle != null)
                            {
                                rowDesc[i].ArrayHandle = this.fields[i].ArrayHandle;
                            }
                        }
                    }

                    this.fields = rowDesc;

                    // Free	memory
                    marshaler.CleanUpNativeData(ref	sqlda);

                    // Parse status	vector
                    this.db.ParseStatusVector(statusVector);

                    if (status == 100)
                    {
                        this.allRowsFetched = true;
                    }
                    else
                    {
                        // Set row values
                        row = new DbValue[this.fields.ActualCount];
                        for (int i = 0; i < row.Length; i++)
                        {
                            row[i] = new DbValue(this, this.fields[i]);
                        }
                    }
                }
            }

            return row;
        }
示例#7
0
        public override void Execute()
        {
            if (this.state == StatementState.Deallocated)
            {
                throw new InvalidOperationException("Statment is not correctly created.");
            }

            lock (this.db)
            {
                // Marshal structures to pointer
                XsqldaMarshaler marshaler = XsqldaMarshaler.Instance;

                IntPtr inSqlda = IntPtr.Zero;
                IntPtr outSqlda = IntPtr.Zero;

                if (this.parameters != null)
                {
                    inSqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.parameters);
                }
                if (this.statementType == DbStatementType.StoredProcedure)
                {
                    this.Fields.ResetValues();
                    outSqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.fields);
                }

                int[] statusVector = ExtConnection.GetNewStatusVector();
                int trHandle = this.transaction.Handle;
                int stmtHandle = this.handle;

                SafeNativeMethods.isc_dsql_execute2(
                    statusVector,
                    ref	trHandle,
                    ref	stmtHandle,
                    IscCodes.SQLDA_VERSION1,
                    inSqlda,
                    outSqlda);

                if (outSqlda != IntPtr.Zero)
                {
                    Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, outSqlda);

                    // This	would be an	Execute	procedure
                    DbValue[] values = new DbValue[descriptor.Count];

                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = new DbValue(this, descriptor[i]);
                    }

                    this.outputParams.Enqueue(values);
                }

                // Free	memory
                marshaler.CleanUpNativeData(ref	inSqlda);
                marshaler.CleanUpNativeData(ref	outSqlda);

                this.db.ParseStatusVector(statusVector);

                this.UpdateRecordsAffected();

                this.state = StatementState.Executed;
            }
        }
示例#8
0
		protected DbValue[] ReadDataRow()
		{
			DbValue[] row = new DbValue[this.fields.Count];
			object value = null;

			lock (this.database.SyncObject)
			{
				// This	only works if not (port->port_flags	& PORT_symmetric)				
				for (int i = 0; i < this.fields.Count; i++)
				{
					try
					{
						value = this.database.ReadValue(this.fields[i]);
						row[i] = new DbValue(this, this.fields[i], value);
					}
					catch (IOException)
					{
						throw new IscException(IscCodes.isc_net_read_err);
					}
				}
			}

			return row;
		}
		public override DbValue[] Fetch()
		{
			DbValue[] row = null;

			if (_state == StatementState.Deallocated)
			{
				throw new InvalidOperationException("Statement is not correctly created.");
			}
			if (_statementType != DbStatementType.Select &&
				_statementType != DbStatementType.SelectForUpdate)
			{
				return null;
			}

			lock (_db)
			{
				if (!_allRowsFetched)
				{
					// Get the XSQLDA Marshaler


					// Reset actual	field values
					_fields.ResetValues();

					// Marshal structures to pointer
					if (_fetchSqlDa == IntPtr.Zero)
					{
						_fetchSqlDa = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields);
					}

					// Clear the status vector
					ClearStatusVector();

					// Statement handle to be passed to the fetch method
					int stmtHandle = _handle;

					// Fetch data
					IntPtr status = _db.FbClient.isc_dsql_fetch(_statusVector, ref stmtHandle, IscCodes.SQLDA_VERSION1, _fetchSqlDa);

					// Obtain values
					Descriptor rowDesc = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, _fetchSqlDa, true);

					if (_fields.Count == rowDesc.Count)
					{
						// Try to preserve Array Handle information
						for (int i = 0; i < _fields.Count; i++)
						{
							if (_fields[i].IsArray() && _fields[i].ArrayHandle != null)
							{
								rowDesc[i].ArrayHandle = _fields[i].ArrayHandle;
							}
						}
					}

					_fields = rowDesc;

					// Parse status	vector
					_db.ParseStatusVector(_statusVector);

					if (status == new IntPtr(100))
					{
						_allRowsFetched = true;

						XsqldaMarshaler.CleanUpNativeData(ref _fetchSqlDa);
					}
					else
					{
						// Set row values
						row = new DbValue[_fields.ActualCount];
						for (int i = 0; i < row.Length; i++)
						{
							row[i] = new DbValue(this, _fields[i]);
						}
					}
				}
			}

			return row;
		}
		public override void Execute()
		{
			if (_state == StatementState.Deallocated)
			{
				throw new InvalidOperationException("Statment is not correctly created.");
			}

			lock (_db)
			{
				// Clear the status vector
				ClearStatusVector();

				// Marshal structures to pointer


				IntPtr inSqlda = IntPtr.Zero;
				IntPtr outSqlda = IntPtr.Zero;

				if (_parameters != null)
				{
					inSqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _parameters);
				}
				if (_statementType == DbStatementType.StoredProcedure)
				{
					Fields.ResetValues();
					outSqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields);
				}

				int trHandle = _transaction.Handle;
				int stmtHandle = _handle;

				_db.FbClient.isc_dsql_execute2(
					_statusVector,
					ref trHandle,
					ref stmtHandle,
					IscCodes.SQLDA_VERSION1,
					inSqlda,
					outSqlda);

				if (outSqlda != IntPtr.Zero)
				{
					Descriptor descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, outSqlda, true);

					// This	would be an	Execute	procedure
					DbValue[] values = new DbValue[descriptor.Count];

					for (int i = 0; i < values.Length; i++)
					{
						values[i] = new DbValue(this, descriptor[i]);
					}

					_outputParams.Enqueue(values);
				}

				// Free	memory
				XsqldaMarshaler.CleanUpNativeData(ref inSqlda);
				XsqldaMarshaler.CleanUpNativeData(ref outSqlda);

				_db.ParseStatusVector(_statusVector);

				UpdateRecordsAffected();

				_state = StatementState.Executed;
			}
		}
		protected DbValue[] ReadDataRow()
		{
			DbValue[] row = new DbValue[_fields.Count];
			object value = null;

			lock (_database.SyncObject)
			{
				// This only works if not (port->port_flags & PORT_symmetric)
				for (int i = 0; i < _fields.Count; i++)
				{
					try
					{
						value = _database.XdrStream.ReadValue(_fields[i]);
						row[i] = new DbValue(this, _fields[i], value);
					}
					catch (IOException ex)
					{
						throw IscException.ForErrorCode(IscCodes.isc_net_read_err, ex);
					}
				}
			}

			return row;
		}
示例#12
0
		internal void SetOutputParameters(DbValue[] outputParameterValues)
		{
			if (this.parameters.Count > 0 && this.statement != null)
			{
				IEnumerator paramEnumerator = this.parameters.GetEnumerator();
				int i = 0;

				if (this.statement != null &&
					this.statement.StatementType == DbStatementType.StoredProcedure)
				{
					DbValue[] values = outputParameterValues;
					if (outputParameterValues == null)
					{
						values = (DbValue[])this.statement.GetOuputParameters();
					}

					if (values != null && values.Length > 0)
					{
						while (paramEnumerator.MoveNext())
						{
							FbParameter parameter = (FbParameter)paramEnumerator.Current;

							if (parameter.Direction == ParameterDirection.Output ||
								parameter.Direction == ParameterDirection.InputOutput ||
								parameter.Direction == ParameterDirection.ReturnValue)
							{
								parameter.Value = values[i].Value;
								i++;
							}
						}
					}
				}
			}
		}