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; } }
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); } }
public override byte[] GetSlice(int sliceLength) { int[] statusVector = ExtConnection.GetNewStatusVector(); int dbHandle = this.db.Handle; int trHandle = this.transaction.Handle; ArrayDescMarshaler marshaler = ArrayDescMarshaler.Instance; IntPtr arrayDesc = marshaler.MarshalManagedToNative(this.Descriptor); byte[] buffer = new byte[sliceLength]; SafeNativeMethods.isc_array_get_slice( statusVector, ref dbHandle, ref trHandle, ref this.handle, arrayDesc, buffer, ref sliceLength); // Free memory marshaler.CleanUpNativeData(ref arrayDesc); ExtConnection.ParseStatusVector(statusVector); return(buffer); }
private object GetValue(string name, bool oldValue) { int[] statusVector = ExtConnection.GetNewStatusVector(); byte[] fieldName = new byte[32]; object value = null; _database.Charset.GetBytes(name, 0, name.Length, fieldName, 0); // Marshal structures to pointer ParamDscMarshaler marshaler = ParamDscMarshaler.Instance; IntPtr valuePtr = marshaler.MarshalManagedToNative(); bool result = SafeNativeMethods.isc_get_trigger_field( statusVector, (oldValue) ? 0 : 1, fieldName, valuePtr); value = marshaler.MarshalNativeToManaged(_database.Charset, valuePtr); marshaler.CleanUpNativeData(ref valuePtr); ExtConnection.ParseStatusVector(statusVector); return(value); }
public void Query( ServiceParameterBuffer spb, int requestLength, byte[] requestBuffer, int bufferLength, byte[] buffer) { int[] statusVector = ExtConnection.GetNewStatusVector(); int svcHandle = this.Handle; int reserved = 0; SafeNativeMethods.isc_service_query( statusVector, ref svcHandle, ref reserved, (short)spb.Length, spb.ToArray(), (short)requestLength, requestBuffer, (short)buffer.Length, buffer); // Parse status vector this.ParseStatusVector(statusVector); }
public int GetTriggerAction() { int[] statusVector = ExtConnection.GetNewStatusVector(); int action = SafeNativeMethods.isc_get_trigger_action(statusVector); ExtConnection.ParseStatusVector(statusVector); return(action); }
public string GetTableName() { int[] statusVector = ExtConnection.GetNewStatusVector(); byte[] tableName = new byte[255]; int count = SafeNativeMethods.isc_get_trigger_table_name(statusVector, tableName, 255); ExtConnection.ParseStatusVector(statusVector); return(_database.Charset.GetString(tableName, 0, count)); }
protected override void Cancel() { lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); SafeNativeMethods.isc_cancel_blob(statusVector, ref this.blobHandle); ExtConnection.ParseStatusVector(statusVector); } }
protected override void Close() { lock (_db) { int[] statusVector = ExtConnection.GetNewStatusVector(); SafeNativeMethods.isc_close_blob(statusVector, ref _blobHandle); ExtConnection.ParseStatusVector(statusVector); } }
public void Detach() { int[] statusVector = ExtConnection.GetNewStatusVector(); int svcHandle = this.Handle; SafeNativeMethods.isc_service_detach(statusVector, ref svcHandle); // Parse status vector this.ParseStatusVector(statusVector); // Update status vector this.handle = svcHandle; }
protected override void PutSegment(byte[] buffer) { lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); SafeNativeMethods.isc_put_segment( statusVector, ref this.blobHandle, (short)buffer.Length, buffer); ExtConnection.ParseStatusVector(statusVector); } }
public void Start(ServiceParameterBuffer spb) { int[] statusVector = ExtConnection.GetNewStatusVector(); int svcHandle = this.Handle; int reserved = 0; SafeNativeMethods.isc_service_start( statusVector, ref svcHandle, ref reserved, (short)spb.Length, spb.ToArray()); // Parse status vector this.ParseStatusVector(statusVector); }
protected override byte[] GetSegment() { short requested = (short)this.SegmentSize; short segmentLength = 0; lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); using (MemoryStream segment = new MemoryStream()) { byte[] tmp = new byte[requested]; int status = SafeNativeMethods.isc_get_segment( statusVector, ref this.blobHandle, ref segmentLength, requested, tmp); if (segmentLength > 0) { segment.Write(tmp, 0, segmentLength > requested ? requested : segmentLength); } this.RblRemoveValue(IscCodes.RBL_segment); if (statusVector[1] == IscCodes.isc_segstr_eof) { segment.SetLength(0); this.RblAddValue(IscCodes.RBL_eof_pending); } else { if (status == 0 || statusVector[1] == IscCodes.isc_segment) { this.RblAddValue(IscCodes.RBL_segment); } else { this.db.ParseStatusVector(statusVector); } } return(segment.ToArray()); } } }
private void DatabaseInfo(byte[] items, byte[] buffer, int bufferLength) { lock (this) { int[] statusVector = ExtConnection.GetNewStatusVector(); int dbHandle = this.Handle; SafeNativeMethods.isc_database_info( statusVector, ref dbHandle, (short)items.Length, items, (short)bufferLength, buffer); this.ParseStatusVector(statusVector); } }
public void Attach(ServiceParameterBuffer spb, string dataSource, int port, string service) { int[] statusVector = ExtConnection.GetNewStatusVector(); int svcHandle = this.Handle; SafeNativeMethods.isc_service_attach( statusVector, (short)service.Length, service, ref svcHandle, (short)spb.Length, spb.ToArray()); // Parse status vector this.ParseStatusVector(statusVector); // Update status vector this.handle = svcHandle; }
private void Allocate() { lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); int dbHandle = this.db.Handle; int stmtHandle = this.handle; SafeNativeMethods.isc_dsql_allocate_statement( statusVector, ref dbHandle, ref stmtHandle); this.db.ParseStatusVector(statusVector); this.handle = stmtHandle; this.allRowsFetched = false; this.state = StatementState.Allocated; this.statementType = DbStatementType.None; } }
protected override byte[] GetSqlInfo(byte[] items, int bufferLength) { lock (this.db) { byte[] buffer = new byte[bufferLength]; int[] statusVector = ExtConnection.GetNewStatusVector(); int stmtHandle = this.handle; SafeNativeMethods.isc_dsql_sql_info( statusVector, ref stmtHandle, (short)items.Length, items, (short)bufferLength, buffer); this.db.ParseStatusVector(statusVector); return(buffer); } }
protected override void Open() { lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); int dbHandle = this.db.Handle; int trHandle = this.transaction.Handle; SafeNativeMethods.isc_open_blob2( statusVector, ref dbHandle, ref trHandle, ref this.blobHandle, ref this.blobId, 0, new byte[0]); ExtConnection.ParseStatusVector(statusVector); } }
public override void PutSlice(System.Array sourceArray, int sliceLength) { int[] statusVector = ExtConnection.GetNewStatusVector(); int dbHandle = this.db.Handle; int trHandle = this.transaction.Handle; ArrayDescMarshaler marshaler = ArrayDescMarshaler.Instance; IntPtr arrayDesc = marshaler.MarshalManagedToNative(this.Descriptor); // Obtain the System of type of Array elements and // Fill buffer Type systemType = this.GetSystemType(); byte[] buffer = new byte[sliceLength]; if (systemType.IsPrimitive) { Buffer.BlockCopy(sourceArray, 0, buffer, 0, buffer.Length); } else { buffer = this.EncodeSlice(this.Descriptor, sourceArray, sliceLength); } SafeNativeMethods.isc_array_put_slice( statusVector, ref dbHandle, ref trHandle, ref this.handle, arrayDesc, buffer, ref sliceLength); // Free memory marshaler.CleanUpNativeData(ref arrayDesc); ExtConnection.ParseStatusVector(statusVector); }
protected override void Create() { lock (this.db) { int[] statusVector = ExtConnection.GetNewStatusVector(); int dbHandle = this.db.Handle; int trHandle = this.transaction.Handle; SafeNativeMethods.isc_create_blob2( statusVector, ref dbHandle, ref trHandle, ref this.blobHandle, ref this.blobId, 0, new byte[0]); ExtConnection.ParseStatusVector(statusVector); this.RblAddValue(IscCodes.RBL_create); } }
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 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); }
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; } }
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; } }