简体   繁体   English

Firebird:更改表并从C#中创建存储过程

[英]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 TABLECREATE PROCEDURE而无需EXECUTE BLOCK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从C#调用Firebird存储过程中的更新表 - Update table in firebird stored procedure called from c# C#以编程方式更改存储过程 - C# alter stored procedure programmatically 从C#中删除并创建存储过程 - Drop and Create Stored Procedure from C# C#-从存储过程返回的项目列表之外创建自定义对象 - C# - Create custom object out of list of items returned from stored procedure 如何将表 OBJECT 输出参数从 C# ASP.NET 核心传递到 Z30162ED78B6C10F231411F2F4 - How to pass a TABLE OBJECT out parameter from C# ASP.NET Core to Oracle Stored Procedure 创建用于在C#中调用Oracle存储过程的输入表参数 - Create input table parameter for calling Oracle stored procedure in C# 从C#代码调用存储过程时,为什么不能创建全局临时表或截断它? - Why cannot create global temporary table or truncate it when call a stored procedure from C# code? 使用c#从存储过程中读取参数时出现问题 - Problem reading out parameter from stored procedure using c# 无法从C#中的Oracle存储过程中检索参数 - Unable to retrieve out params from Oracle stored procedure in C# 在没有存储过程的情况下从C#Visual Studio执行Alter Tablespace语句 - Execute Alter Tablespace Statement from C# Visual Studio without stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM