Reputation: 399
I'm trying to create a stored procedure from out C# into Firebird 2.1. The code is:
String sql = @"EXECUTE BLOCK AS BEGIN " +
"ALTER TABLE EXAMPLE ALTER FIELD1 TYPE Char(50); " +
"SET TERM ^ ; CREATE PROCEDURE name ( input_parameter_name < datatype>, ... )" +
"RETURNS ( output_parameter_name < datatype>, ... ) AS DECLARE VARIABLE variable_name < datatype>;" +
"BEGIN /* write your code here */ END^ SET TERM ; ^" +
" END";
public int Execute(string sql)
{
int result = 0;
if (this.OpenConnection() == true)
{
FbTransaction transaction = Fbconnection.BeginTransaction();
try
{
FbCommand command = new FbCommand(sql, Fbconnection, transaction);
int rc = command.ExecuteNonQuery();
result = rc;
transaction.Commit();
}
catch (Exception e)
{
globals.logfile.log(e.ToString());
globals.logfile.flush();
result = 0;
}
finally
{
this.CloseConnection();
}
}
return result;
}
The error message given is:
FirebirdSql.Data.FirebirdClient.FbException (0x80004005):
Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 24 ALTER
Must be something small, but I can't get it.
Upvotes: 0
Views: 1766
Reputation: 109012
DDL is not allowed in PSQL (stored procedures, triggers, execute block), so executing an ALTER TABLE
like this is rejected.
Also SET TERM
is not part of the Firebird statement syntax. It is specific to query tools like isql and FlameRobin, as they use statement terminators like ;
to know when they end of a statement is reached and can be sent to the server. When executing PSQL blocks those tools need to watch for a different statement terminator to prevent them from sending incomplete statements to the server. In the actual Firebird statement syntax ;
is only part of PSQL blocks.
You will need to execute the ALTER TABLE
and the CREATE PROCEDURE
separately without an EXECUTE BLOCK
.
Upvotes: 1