From: olegmad <ol...@ya...> - 2004-03-06 12:54:52
|
Hi! When i try update data in database (i use data adapter for this), i catch exception :( What i do wrong??? Here my example: using (FbConnection connection = new FbConnection(ConnectionString)) { connection.Open(); FbTransaction transaction = connection.BeginTransaction(); FbCommand selectCommand = new FbCommand("\"TEST_SELECT\"", connection, transaction); selectCommand.CommandType = CommandType.StoredProcedure; FbCommandBuilder.DeriveParameters(selectCommand); // Get data table. FbDataAdapter adapter = new FbDataAdapter(selectCommand); DataTable table = new DataTable(); adapter.Fill(table); // Delete first row. table.Rows[0].Delete(); FbCommand deleteCommand = new FbCommand("\"TEST_DELETE\"", connection, transaction); deleteCommand.CommandType = CommandType.StoredProcedure; FbCommandBuilder.DeriveParameters(deleteCommand); deleteCommand.Parameters[0].SourceColumn = "ID"; adapter.DeleteCommand = deleteCommand; adapter.Update(table); // EXCEPTION HERE !!!!!!!!!!!!!!!! transaction.Commit(); } -------------------------- Exception text: An unhandled exception of type 'FirebirdSql.Data.Firebird.FbException' occurred in system.data.dll Additional information: Dynamic SQL Error SQL error code = -84 procedure TEST_DELETE does not return any values At line 1, column 10. ----------------- I create table and two stored procedure like this: SET TERM ^ ; /*************************************************************************** ***/ /*** Stored Procedures ***/ /*************************************************************************** ***/ CREATE PROCEDURE TEST_DELETE ( ID BIGINT) AS BEGIN EXIT; END^ CREATE PROCEDURE TEST_SELECT RETURNS ( ID BIGINT, NAME VARCHAR(64)) AS BEGIN EXIT; END^ SET TERM ; ^ /*************************************************************************** ***/ /*** Tables ***/ /*************************************************************************** ***/ CREATE TABLE TEST ( ID BIGINT NOT NULL, NAME VARCHAR(64) NOT NULL ); /*************************************************************************** ***/ /*** Primary Keys ***/ /*************************************************************************** ***/ ALTER TABLE TEST ADD CONSTRAINT PK_TEST PRIMARY KEY (ID); /*************************************************************************** ***/ /*** Stored Procedures ***/ /*************************************************************************** ***/ SET TERM ^ ; ALTER PROCEDURE TEST_DELETE ( ID BIGINT) AS begin delete from test where :ID = ID; end ^ ALTER PROCEDURE TEST_SELECT RETURNS ( ID BIGINT, NAME VARCHAR(64)) AS begin for select ID, NAME from test into :ID, :NAME do suspend; end ^ SET TERM ; ^ |
From:
<car...@te...> - 2004-03-06 13:34:20
|
Hello: > adapter.Update(table); // EXCEPTION HERE !!!!!!!!!!!!!!!! This will call FbCommand.ExecuteReader method, the provider will transform the command text into: select * from "TEST_DELETE" As TEST_DELETE has no return values firebird will throw an exception. You can try using EXECUTE PROCEDURE sintax, or returning at least one value ( for example the number of rows affected ;) ) -- Best regards Carlos Guzmán Álvarez Vigo-Spain |
From: olegmad <ol...@ya...> - 2004-03-06 14:22:13
|
> > adapter.Update(table); // EXCEPTION HERE !!!!!!!!!!!!!!!! > > This will call FbCommand.ExecuteReader method, the provider will > transform the command text into: > > select * from "TEST_DELETE" > > As TEST_DELETE has no return values firebird will throw an exception. > > You can try using EXECUTE PROCEDURE sintax, or returning at least one > value ( for example the number of rows affected ;) ) In my example i use deleteCommand for call stored procedure which delete data. How provider may call select * from "TEST_DELETE"??? ------------------ FbCommand deleteCommand = new FbCommand("\"TEST_DELETE\"", connection, transaction); deleteCommand.CommandType = CommandType.StoredProcedure; FbCommandBuilder.DeriveParameters(deleteCommand); deleteCommand.Parameters[0].SourceColumn = "ID"; adapter.DeleteCommand = deleteCommand; /// !!!!!!!!!! it's NOT select stored procedure !!!!!!!!!! ------------------ I am waiting your feedback. :) |
From:
<car...@te...> - 2004-03-06 14:39:13
|
Hello: > In my example i use deleteCommand for call stored procedure which delete > data. How provider may call select * from "TEST_DELETE"??? Ask microsoft ;), the only reasin i see for this is that they use FbDatareader.NextResult to process batch commands ;) -- Best regards Carlos Guzmán Álvarez Vigo-Spain |
From:
<car...@te...> - 2004-03-06 14:55:42
|
Hello: >> In my example i use deleteCommand for call stored procedure which delete >> data. How provider may call select * from "TEST_DELETE"??? > > Ask microsoft ;), the only reasin i see for this is that they use > FbDatareader.NextResult to process batch commands ;) To clarify this, the provider transforms the TEST_DELETE to select * from TEST_DELETE because DbDataAdapter.Update is making a call to ExecuteReader ;) -- Best regards Carlos Guzmán Álvarez Vigo-Spain |
From: olegmad <ol...@ya...> - 2004-03-06 15:11:00
|
> Ask microsoft ;), the only reasin i see for this is that they use > FbDatareader.NextResult to process batch commands ;) Thanks for answer. I understand what happened :) But a still have problem :( I changes my TEST_DELETE stored procedure (return integer 345): ------------------------ SET TERM ^ ; CREATE PROCEDURE TEST_DELETE ( ID BIGINT) RETURNS ( "OUTPUT" INTEGER) AS BEGIN delete from test where :ID = ID; OUTPUT = 345; suspend; END^ SET TERM ; ^ ------------------------ Exception gone, all ok, but changes not commited :( /~~~~~/ // Delete first row. DataRow row = table.Rows[0]; row.Delete(); FbCommand deleteCommand = new FbCommand("\"TEST_DELETE\"", connection, transaction); deleteCommand.CommandType = CommandType.StoredProcedure; FbCommandBuilder.DeriveParameters(deleteCommand); deleteCommand.Parameters[0].SourceColumn = "ID"; adapter.DeleteCommand = deleteCommand; // row.RowState = Deleted !!!!!!!!!!!!!!!!!!!!!!!!!!! adapter.Update(table); // row.RowState = Detached !!!!!!!!!!!!!!!!!!!!!!!!!! transaction.Commit(); /~~~~~/ When i see table in my database - i see this row, it not deleted. Why? |
From:
<car...@te...> - 2004-03-06 15:16:26
|
Hello: > Thanks for answer. I understand what happened :) > But a still have problem :( Ok i will try to review it later. -- Best regards Carlos Guzmán Álvarez Vigo-Spain |
From:
<car...@te...> - 2004-03-08 11:55:29
|
Hello: > Thanks for answer. I understand what happened :) > But a still have problem :( Huummmm .... the problem is: 1. DbDataAdapter.Update calls ExecuteReader. 2. In ExecuteReader the provider transforms the command text as SELECT * FROM TEST_DELETE 3. DbDataAdapter.Update closes the data reader without calls to FbDataReader.Read and Firebird doesn't perform the row deletes. Now the tip is how to solve this, we can add, to the FbDataReader.Close method, a pice of code like this: if (this.position == STARTPOS && this.command.CommandType == CommandType.StoredProcedure) { this.Read(); } And it will work. Opinions ?? -- Best regards Carlos Guzmán Álvarez Vigo-Spain |
From: Oleg U. <ol...@ya...> - 2004-03-09 07:45:03
|
> Opinions ?? I think it's right! When you commit this changes? I'd like to test it. :) |
From:
<car...@te...> - 2004-03-09 10:44:09
|
Hello: > I think it's right! > When you commit this changes? I'd like to test it. :) It's on CVS yet, in both 1.5 and 1.6 sources thanks very much -- Best regards Carlos Guzmán Álvarez Vigo-Spain |