[英]Firebird: Alter table and create stored procedure from out C#
I'm trying to create a stored procedure from out C# into Firebird 2.1. 我正在尝试从C#到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):
FirebirdSql.Data.FirebirdClient.FbException(0x80004005):
Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 24 ALTER动态SQL错误SQL错误代码= -104令牌未知-第1行,第24列,ALTER
Must be something small, but I can't get it. 一定很小,但我听不懂。
DDL is not allowed in PSQL (stored procedures, triggers, execute block), so executing an ALTER TABLE
like this is rejected. 在PSQL中(存储过程,触发器,执行块)不允许DDL,因此拒绝执行像这样的
ALTER TABLE
。
Also SET TERM
is not part of the Firebird statement syntax. 此外,
SET TERM
也不是Firebird语句语法的一部分。 It is specific to query tools like isql and FlameRobin, as they use statement terminators like ;
它特定于查询工具(如isql和FlameRobin),因为它们使用语句终止符(如
;
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.
在执行PSQL块时,这些工具需要注意其他语句终止符,以防止它们将不完整的语句发送到服务器。 In the actual Firebird statement syntax
;
在实际的Firebird语句语法中
;
is only part of PSQL blocks. 只是PSQL块的一部分。
You will need to execute the ALTER TABLE
and the CREATE PROCEDURE
separately without an EXECUTE BLOCK
. 您将需要分别执行
ALTER TABLE
和CREATE PROCEDURE
而无需EXECUTE BLOCK
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.