Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in BatchExecution when (FbTransaction == null) [DNET390] #138

Closed
firebird-automations opened this issue Aug 22, 2011 · 5 comments
Closed

Comments

@firebird-automations
Copy link

Submitted by: Alexander (zxsanny)

Votes: 2

When BatchExecution executing many sql command in 1 command without beginning transaction, there is error in this line: this.sqlTransaction.Commit(); // 242 line in FbBatchExecution.cs

This situation can be replaying to execute some query like this:

CREATE TABLE sample(id bigint not null);
COMMIT WORK;

and C#⁠ code like this:

FbConnection c = new FbConnection(@"Database=employee.fdb;User=SYSDBA;Password=masterkey");
c.Open();

FbBatchExecution fbe = new FbBatchExecution(c);
foreach (string cmd in script.Results) {
fbe.SqlStatements.Add(cmd);
}

fbe.Execute();
c.Close();
(copypasted from this: http://web.firebirdsql.org/dotnetfirebird/blog/2005_03_01_archive.html )

So, small fix is this:

                    case SqlStatementType\.Commit:
                       	if \(sqlTransaction\!=null\)
						\{
							// raise the event
							this\.OnCommandExecuting\(null\);

							this\.sqlTransaction\.Commit\(\);
							this\.sqlTransaction = null;

							// raise the event
							this\.OnCommandExecuted\(sqlStatement, null, \-1\);
						\}
						break;
                    case SqlStatementType\.Rollback:
						if \(sqlTransaction \!= null\)
						\{

							// raise the event
							this\.OnCommandExecuting\(null\);

							this\.sqlTransaction\.Rollback\(\);
							this\.sqlTransaction = null;

							// raise the event
							this\.OnCommandExecuted\(sqlStatement, null, \-1\);
						\}
						break;

but in my opinion this is looks like dirty hack...
(Sorry for my English )

@firebird-automations
Copy link
Author

Modified by: Alexander (zxsanny)

description: When BatchExecution executing many sql command in 1 command without beginning transaction, there is error in this line: this.sqlTransaction.Commit(); // 242 line in FbBatchExecution.cs

This situation can be replaying to execute some query like this:

CREATE TABLE sample(id bigint not null);
COMMIT WORK;

and C#⁠ code like this:

FbConnection c = new FbConnection(@"Database=employee.fdb;User=SYSDBA;Password=masterkey");
c.Open();

FbBatchExecution fbe = new FbBatchExecution(c);
foreach (string cmd in script.Results) {
fbe.SqlStatements.Add(cmd);
}

fbe.Execute();
c.Close();
(copypasted from this: http://web.firebirdsql.org/dotnetfirebird/blog/2005_03_01_archive.html)

So, small fix is this:

                    case SqlStatementType\.Commit:
                       	if \(sqlTransaction\!=null\)
						\{
							// raise the event
							this\.OnCommandExecuting\(null\);

							this\.sqlTransaction\.Commit\(\);
							this\.sqlTransaction = null;

							// raise the event
							this\.OnCommandExecuted\(sqlStatement, null, \-1\);
						\}
						break;
                    case SqlStatementType\.Rollback:
						if \(sqlTransaction \!= null\)
						\{

							// raise the event
							this\.OnCommandExecuting\(null\);

							this\.sqlTransaction\.Rollback\(\);
							this\.sqlTransaction = null;

							// raise the event
							this\.OnCommandExecuted\(sqlStatement, null, \-1\);
						\}
						break;

but in my opinion this is looks like dirty hack...

=>

When BatchExecution executing many sql command in 1 command without beginning transaction, there is error in this line: this.sqlTransaction.Commit(); // 242 line in FbBatchExecution.cs

This situation can be replaying to execute some query like this:

CREATE TABLE sample(id bigint not null);
COMMIT WORK;

and C#⁠ code like this:

FbConnection c = new FbConnection(@"Database=employee.fdb;User=SYSDBA;Password=masterkey");
c.Open();

FbBatchExecution fbe = new FbBatchExecution(c);
foreach (string cmd in script.Results) {
fbe.SqlStatements.Add(cmd);
}

fbe.Execute();
c.Close();
(copypasted from this: http://web.firebirdsql.org/dotnetfirebird/blog/2005_03_01_archive.html )

So, small fix is this:

                    case SqlStatementType\.Commit:
                       	if \(sqlTransaction\!=null\)
						\{
							// raise the event
							this\.OnCommandExecuting\(null\);

							this\.sqlTransaction\.Commit\(\);
							this\.sqlTransaction = null;

							// raise the event
							this\.OnCommandExecuted\(sqlStatement, null, \-1\);
						\}
						break;
                    case SqlStatementType\.Rollback:
						if \(sqlTransaction \!= null\)
						\{

							// raise the event
							this\.OnCommandExecuting\(null\);

							this\.sqlTransaction\.Rollback\(\);
							this\.sqlTransaction = null;

							// raise the event
							this\.OnCommandExecuted\(sqlStatement, null, \-1\);
						\}
						break;

but in my opinion this is looks like dirty hack...
(Sorry for my English )

@firebird-automations
Copy link
Author

Commented by: @cincuranet

Should the OnCommandExecuting and OnCommandExecuted be called even if the command was effectively skipped (no transaction) or not?

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-automations
Copy link
Author

Commented by: @cincuranet

OK, I decided the events will be fired. Logically the command was executed. Internals doesn't matter.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: In Progress [ 3 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: vNext [ 10704 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants