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); }
public override void Describe() { lock (_db) { // Clear the status vector ClearStatusVector(); // Update structure _fields = new Descriptor(_fields.ActualCount); // Marshal structures to pointer IntPtr sqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _fields); int stmtHandle = _handle; _db.FbClient.isc_dsql_describe( _statusVector, ref stmtHandle, IscCodes.SQLDA_VERSION1, sqlda); // Marshal Pointer Descriptor descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, sqlda); // Free memory XsqldaMarshaler.CleanUpNativeData(ref sqlda); // Parse status vector _db.ParseStatusVector(_statusVector); // Update field descriptor _fields = descriptor; } }
/// <include file='Doc/en_EN/FbDataReader.xml' path='doc/class[@name="FbDataReader"]/method[@name="Close"]/*'/> public void Close() { bool closeConnection = false; if (this.IsClosed) { return; } this.isClosed = true; this.position = STARTPOS; if (this.connection != null) { if ((this.behavior & CommandBehavior.CloseConnection) == CommandBehavior.CloseConnection) { closeConnection = true; } } if (this.command != null && !this.command.IsDisposed) { if (this.command.CommandType == CommandType.StoredProcedure) { // Set values of output parameters this.command.SetOutputParameters(); } if (this.command.HasImplicitTransaction) { // Commit implicit transaction if needed this.command.CommitImplicitTransaction(); } // Set null the active reader of the command this.command.ActiveReader = null; } if (closeConnection) { this.connection.Close(); } this.command = null; this.connection = null; this.row = null; this.schemaTable = null; this.fields = null; }
private bool BuildParameterDescriptor(Descriptor descriptor, FbParameter parameter, int index) { if (!parameter.IsTypeSet) { return false; } FbDbType type = parameter.FbDbType; Charset charset = this.connection.InnerConnection.Database.Charset; // Check the parameter character set if (parameter.Charset == FbCharset.Octets && !(parameter.InternalValue is byte[])) { throw new InvalidOperationException("Value for char octets fields should be a byte array"); } else if (type == FbDbType.Guid) { charset = Charset.GetCharset("OCTETS"); } else if (parameter.Charset != FbCharset.Default) { charset = Charset.GetCharset((int)parameter.Charset); } // Set parameter Data Type descriptor[index].DataType = (short)TypeHelper.GetFbType((DbDataType)type, parameter.IsNullable); // Set parameter Sub Type switch (type) { case FbDbType.Binary: descriptor[index].SubType = 0; break; case FbDbType.Text: descriptor[index].SubType = 1; break; case FbDbType.Guid: descriptor[index].SubType = (short)charset.Identifier; break; case FbDbType.Char: case FbDbType.VarChar: descriptor[index].SubType = (short)charset.Identifier; if (charset.IsOctetsCharset) { descriptor[index].Length = (short)parameter.Size; } else if (parameter.HasSize) { short len = (short)(parameter.Size * charset.BytesPerCharacter); descriptor[index].Length = len; } break; } // Set parameter length if (descriptor[index].Length == 0) { descriptor[index].Length = TypeHelper.GetSize((DbDataType)type); } // Verify parameter if (descriptor[index].SqlType == 0 || descriptor[index].Length == 0) { return false; } return true; }
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); }
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 object Clone() { Descriptor descriptor = new Descriptor(this.Count); descriptor.Version = this.version; for (int i = 0; i < descriptor.Count; i++) { descriptor[i].DataType = this.fields[i].DataType; descriptor[i].NumericScale = this.fields[i].NumericScale; descriptor[i].SubType = this.fields[i].SubType; descriptor[i].Length = this.fields[i].Length; descriptor[i].Value = this.fields[i].Value; descriptor[i].NullFlag = this.fields[i].NullFlag; descriptor[i].Name = this.fields[i].Name; descriptor[i].Relation = this.fields[i].Relation; descriptor[i].Owner = this.fields[i].Owner; descriptor[i].Alias = this.fields[i].Alias; } return descriptor; }
protected void DoFreePacket(int option) { try { SendFreeToBuffer(option); // Reset statement information if (option == IscCodes.DSQL_drop) { this.parameters = null; this.fields = null; } this.Clear(); } catch (IOException) { this.state = StatementState.Error; throw new IscException(IscCodes.isc_net_read_err); } }
protected void ParseSqlInfo(byte[] info, byte[] items, ref Descriptor[] rowDescs) { this.ParseTruncSqlInfo(info, items, ref rowDescs); }
public void Write(Descriptor descriptor) { for (int i = 0; i < descriptor.Count; i++) { this.Write(descriptor[i]); } }
protected void ProcessPrepareResponse(GenericResponse response) { Descriptor[] descriptors = new Descriptor[] { null, null }; this.ParseSqlInfo(response.Data, DescribeInfoAndBindInfoItems, ref descriptors); this.fields = descriptors[0]; this.parameters = descriptors[1]; }
private void ClearAll() { Clear(); _parameters = null; _fields = null; }
protected override void Free(int option) { // Does not seem to be possible or necessary to close // an execute procedure statement. if (StatementType == DbStatementType.StoredProcedure && option == IscCodes.DSQL_close) { return; } lock (_db) { // Clear the status vector ClearStatusVector(); int stmtHandle = _handle; _db.FbClient.isc_dsql_free_statement( _statusVector, ref stmtHandle, (short)option); _handle = stmtHandle; // Reset statement information if (option == IscCodes.DSQL_drop) { _parameters = null; _fields = null; } Clear(); _allRowsFetched = false; _db.ParseStatusVector(_statusVector); } }
public override void DescribeParameters() { lock (_db) { // Clear the status vector ClearStatusVector(); // Marshal structures to pointer _parameters = new Descriptor(1); IntPtr sqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, _parameters); int stmtHandle = _handle; _db.FbClient.isc_dsql_describe_bind( _statusVector, ref stmtHandle, IscCodes.SQLDA_VERSION1, sqlda); Descriptor descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, sqlda); // Parse status vector _db.ParseStatusVector(_statusVector); if (descriptor.ActualCount != 0 && descriptor.Count != descriptor.ActualCount) { short n = descriptor.ActualCount; descriptor = new Descriptor(n); // Fre memory XsqldaMarshaler.CleanUpNativeData(ref sqlda); // Marshal new structure sqlda = XsqldaMarshaler.MarshalManagedToNative(_db.Charset, descriptor); _db.FbClient.isc_dsql_describe_bind( _statusVector, ref stmtHandle, IscCodes.SQLDA_VERSION1, sqlda); descriptor = XsqldaMarshaler.MarshalNativeToManaged(_db.Charset, sqlda); // Free memory XsqldaMarshaler.CleanUpNativeData(ref sqlda); // Parse status vector _db.ParseStatusVector(_statusVector); } else { if (descriptor.ActualCount == 0) { descriptor = new Descriptor(0); } } // Free memory if (sqlda != IntPtr.Zero) { XsqldaMarshaler.CleanUpNativeData(ref sqlda); } // Update parameter descriptor _parameters = descriptor; } }
protected override void Free(int option) { // Does not seem to be possible or necessary to close // an execute procedure statement. if (this.StatementType == DbStatementType.StoredProcedure && option == IscCodes.DSQL_close) { return; } lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); int stmtHandle = this.handle; SafeNativeMethods.isc_dsql_free_statement( statusVector, ref stmtHandle, (short)option); this.handle = stmtHandle; // Reset statement information if (option == IscCodes.DSQL_drop) { this.parameters = null; this.fields = null; } this.Clear(); this.allRowsFetched = false; this.db.ParseStatusVector(statusVector); } }
protected void ParseTruncSqlInfo(byte[] info, byte[] items, ref Descriptor[] rowDescs) { int currentPosition = 0; int currentDescriptorIndex = -1; int currentItemIndex = 0; while (info[currentPosition] != IscCodes.isc_info_end) { bool jumpOutOfInnerLoop = false; byte item; while ((item = info[currentPosition++]) != IscCodes.isc_info_sql_describe_end) { switch (item) { case IscCodes.isc_info_truncated: currentItemIndex--; List<byte> newItems = new List<byte>(items.Length); int part = 0; int chock = 0; for (int i = 0; i < items.Length; i++) { if (items[i] == IscCodes.isc_info_sql_describe_end) { newItems.Insert(chock, IscCodes.isc_info_sql_sqlda_start); newItems.Insert(chock + 1, 2); short processedItems = (rowDescs[part] != null ? rowDescs[part].Count : (short)0); newItems.Insert(chock + 2, (byte)((part == currentDescriptorIndex ? currentItemIndex : processedItems) & 255)); newItems.Insert(chock + 3, (byte)((part == currentDescriptorIndex ? currentItemIndex : processedItems) >> 8)); part++; chock = i + 4 + 1; } newItems.Add(items[i]); } info = this.GetSqlInfo(newItems.ToArray(), info.Length); currentPosition = 0; currentDescriptorIndex = -1; jumpOutOfInnerLoop = true; break; case IscCodes.isc_info_sql_select: case IscCodes.isc_info_sql_bind: currentDescriptorIndex++; if (info[currentPosition] == IscCodes.isc_info_truncated) break; currentPosition++; int len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; if (rowDescs[currentDescriptorIndex] == null) { int n = IscHelper.VaxInteger(info, currentPosition, len); rowDescs[currentDescriptorIndex] = new Descriptor((short)n); jumpOutOfInnerLoop = (n == 0); } currentPosition += len; break; case IscCodes.isc_info_sql_sqlda_seq: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; currentItemIndex = IscHelper.VaxInteger(info, currentPosition, len); currentPosition += len; break; case IscCodes.isc_info_sql_type: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; rowDescs[currentDescriptorIndex][currentItemIndex - 1].DataType = (short)IscHelper.VaxInteger(info, currentPosition, len); currentPosition += len; break; case IscCodes.isc_info_sql_sub_type: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; rowDescs[currentDescriptorIndex][currentItemIndex - 1].SubType = (short)IscHelper.VaxInteger(info, currentPosition, len); currentPosition += len; break; case IscCodes.isc_info_sql_scale: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; rowDescs[currentDescriptorIndex][currentItemIndex - 1].NumericScale = (short)IscHelper.VaxInteger(info, currentPosition, len); currentPosition += len; break; case IscCodes.isc_info_sql_length: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; rowDescs[currentDescriptorIndex][currentItemIndex - 1].Length = (short)IscHelper.VaxInteger(info, currentPosition, len); currentPosition += len; break; case IscCodes.isc_info_sql_field: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; rowDescs[currentDescriptorIndex][currentItemIndex - 1].Name = this.database.Charset.GetString(info, currentPosition, len); currentPosition += len; break; case IscCodes.isc_info_sql_relation: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; rowDescs[currentDescriptorIndex][currentItemIndex - 1].Relation = this.database.Charset.GetString(info, currentPosition, len); currentPosition += len; break; case IscCodes.isc_info_sql_owner: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; rowDescs[currentDescriptorIndex][currentItemIndex - 1].Owner = this.database.Charset.GetString(info, currentPosition, len); currentPosition += len; break; case IscCodes.isc_info_sql_alias: len = IscHelper.VaxInteger(info, currentPosition, 2); currentPosition += 2; rowDescs[currentDescriptorIndex][currentItemIndex - 1].Alias = this.database.Charset.GetString(info, currentPosition, len); currentPosition += len; break; default: throw new IscException(IscCodes.isc_dsql_sqlda_err); } if (jumpOutOfInnerLoop) break; } } }
private void ClearAll() { this.Clear(); this.parameters = null; this.fields = null; }
protected void ClearAll() { this.Clear(); this.parameters = null; this.fields = null; }
public FbCursor(FbCommand command) { this.command = command; this.fields = this.command.GetFieldsDescriptor(); }
public override void Describe() { lock (this.db) { // Update structure this.fields = new Descriptor(this.fields.ActualCount); // Marshal structures to pointer XsqldaMarshaler marshaler = XsqldaMarshaler.Instance; IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, fields); int[] statusVector = ExtConnection.GetNewStatusVector(); int stmtHandle = this.handle; SafeNativeMethods.isc_dsql_describe( statusVector, ref stmtHandle, IscCodes.SQLDA_VERSION1, sqlda); // Marshal Pointer Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda); // Free memory marshaler.CleanUpNativeData(ref sqlda); // Parse status vector this.db.ParseStatusVector(statusVector); // Update field descriptor this.fields = descriptor; } }
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; }
public override void DescribeParameters() { lock (this.db) { // Marshal structures to pointer XsqldaMarshaler marshaler = XsqldaMarshaler.Instance; this.parameters = new Descriptor(1); IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, parameters); int[] statusVector = ExtConnection.GetNewStatusVector(); int stmtHandle = this.handle; SafeNativeMethods.isc_dsql_describe_bind( statusVector, ref stmtHandle, IscCodes.SQLDA_VERSION1, sqlda); Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda); // Parse status vector this.db.ParseStatusVector(statusVector); if (descriptor.ActualCount != 0 && descriptor.Count != descriptor.ActualCount) { short n = descriptor.ActualCount; descriptor = new Descriptor(n); // Fre memory marshaler.CleanUpNativeData(ref sqlda); // Marshal new structure sqlda = marshaler.MarshalManagedToNative(this.db.Charset, descriptor); SafeNativeMethods.isc_dsql_describe_bind( statusVector, ref stmtHandle, IscCodes.SQLDA_VERSION1, sqlda); descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda); // Free memory marshaler.CleanUpNativeData(ref sqlda); // Parse status vector this.db.ParseStatusVector(statusVector); } else { if (descriptor.ActualCount == 0) { descriptor = new Descriptor(0); } } // Free memory if (sqlda != IntPtr.Zero) { marshaler.CleanUpNativeData(ref sqlda); } // Update parameter descriptor this.parameters = descriptor; } }
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; }
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; }
private Descriptor BuildNamedParametersDescriptor(short count) { Descriptor descriptor = new Descriptor(count); int index = 0; for (int i = 0; i < this.namedParameters.Count; i++) { if (this.Parameters.IndexOf(this.namedParameters[i]) == -1) { throw new FbException(String.Format("Must declare the variable '{0}'", this.namedParameters[i])); } FbParameter parameter = this.Parameters[this.namedParameters[i]]; if (parameter.Direction == ParameterDirection.Input || parameter.Direction == ParameterDirection.InputOutput) { if (!this.BuildParameterDescriptor(descriptor, parameter, index++)) { return null; } } } return descriptor; }
public override void Prepare(string commandText) { // Clear data this.ClearAll(); lock (this.db) { if (this.state == StatementState.Deallocated) { // Allocate statement this.Allocate(); } // Marshal structures to pointer XsqldaMarshaler marshaler = XsqldaMarshaler.Instance; // Setup fields structure this.fields = new Descriptor(1); IntPtr sqlda = marshaler.MarshalManagedToNative(this.db.Charset, this.fields); int[] statusVector = ExtConnection.GetNewStatusVector(); int trHandle = this.transaction.Handle; int stmtHandle = this.handle; byte[] buffer = this.db.Charset.GetBytes(commandText); SafeNativeMethods.isc_dsql_prepare( statusVector, ref trHandle, ref stmtHandle, (short)buffer.Length, buffer, this.db.Dialect, sqlda); // Marshal Pointer Descriptor descriptor = marshaler.MarshalNativeToManaged(this.db.Charset, sqlda); // Free memory marshaler.CleanUpNativeData(ref sqlda); // Parse status vector this.db.ParseStatusVector(statusVector); // Describe fields this.fields = descriptor; if (this.fields.ActualCount > 0 && this.fields.ActualCount != this.fields.Count) { this.Describe(); } else { if (this.fields.ActualCount == 0) { this.fields = new Descriptor(0); } } // Reset actual field values this.fields.ResetValues(); // Get Statement type this.statementType = this.GetStatementType(); // Update state this.state = StatementState.Prepared; } }
private Descriptor BuildPlaceHoldersDescriptor(short count) { Descriptor descriptor = new Descriptor(count); int index = 0; for (int i = 0; i < this.Parameters.Count; i++) { FbParameter parameter = this.Parameters[i]; if (parameter.Direction == ParameterDirection.Input || parameter.Direction == ParameterDirection.InputOutput) { if (!this.BuildParameterDescriptor(descriptor, parameter, index++)) { return null; } } } return descriptor; }
protected override void Dispose(bool disposing) { if (!this.IsDisposed) { try { // release any unmanaged resources this.Release(); // release any managed resources if (disposing) { this.Clear(); this.db = null; this.fields = null; this.parameters = null; this.transaction = null; this.outputParams = null; this.allRowsFetched = false; this.recordsAffected = 0; this.state = StatementState.Deallocated; this.handle = 0; } } finally { base.Dispose(disposing); } } }
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; }
internal FbDataReader( FbCommand command, FbConnection connection, CommandBehavior behavior) { this.position = STARTPOS; this.command = command; this.behavior = behavior; this.connection = connection; this.fields = this.command.GetFieldsDescriptor(); this.UpdateRecordsAffected(); }