无法确定 SQL 语句的类型

发布于 2025-01-05 15:12:02 字数 1445 浏览 1 评论 0原文

当我尝试执行以下查询时,

<!-- language: sql -->

    CREATE TABLE STUDENT (
    ID INTEGER NOT NULL PRIMARY KEY,
    NAME VARCHAR(255) NOT NULL
    );

    CREATE GENERATOR GEN_STUDENT_ID;

    SET TERM ^ ;
    CREATE OR ALTER TRIGGER STUDENT_BI FOR STUDENT
    ACTIVE BEFORE INSERT POSITION 0
    AS
    BEGIN
       IF (NEW.ID IS NULL) THEN
       NEW.ID = GEN_ID(GEN_STUDENT_ID,1);
    END^

    SET TERM ; ^

出现错误“无法确定 SQL 语句的类型”

此脚本由 c# 代码运行

FbConnectionStringBuilder csb = new FbConnectionStringBuilder();
csb.ServerType = FbServerType.Embedded;
csb.Database = "mydb.fdb";
csb.UserID = "SYSDBA";
csb.Password = "masterkey";

string conString = csb.ToString();
FbConnection.CreateDatabase(conString);

FbScript script = new FbScript("DB_GEN.sql");
script.Parse();

using (FbConnection conn = new FbConnection(conString))
{
    conn.Open();
    Console.WriteLine("Connection opened");

    FbBatchExecution fbe = new FbBatchExecution(conn);

    foreach (string cmd in script.Results) {
        fbe.SqlStatements.Add(cmd);
    }

    try {
        fbe.Execute();
    }catch(Exception e) 
    {
        Console.WriteLine(e.Message);
    }

    conn.Close();

    Console.WriteLine("Connection closed");

    Console.WriteLine("Press any key to continue . . . ");
    Console.ReadKey(true);
}

我正在使用 Firebird Embedded v2.5.1 和 FirebirdSql.Data.FirebirdClient v2 .7.0.0

When I'm trying to execute following query

<!-- language: sql -->

    CREATE TABLE STUDENT (
    ID INTEGER NOT NULL PRIMARY KEY,
    NAME VARCHAR(255) NOT NULL
    );

    CREATE GENERATOR GEN_STUDENT_ID;

    SET TERM ^ ;
    CREATE OR ALTER TRIGGER STUDENT_BI FOR STUDENT
    ACTIVE BEFORE INSERT POSITION 0
    AS
    BEGIN
       IF (NEW.ID IS NULL) THEN
       NEW.ID = GEN_ID(GEN_STUDENT_ID,1);
    END^

    SET TERM ; ^

I'm getting the error "The type of the SQL statement could not be determinated"

This script is running by c# code

FbConnectionStringBuilder csb = new FbConnectionStringBuilder();
csb.ServerType = FbServerType.Embedded;
csb.Database = "mydb.fdb";
csb.UserID = "SYSDBA";
csb.Password = "masterkey";

string conString = csb.ToString();
FbConnection.CreateDatabase(conString);

FbScript script = new FbScript("DB_GEN.sql");
script.Parse();

using (FbConnection conn = new FbConnection(conString))
{
    conn.Open();
    Console.WriteLine("Connection opened");

    FbBatchExecution fbe = new FbBatchExecution(conn);

    foreach (string cmd in script.Results) {
        fbe.SqlStatements.Add(cmd);
    }

    try {
        fbe.Execute();
    }catch(Exception e) 
    {
        Console.WriteLine(e.Message);
    }

    conn.Close();

    Console.WriteLine("Connection closed");

    Console.WriteLine("Press any key to continue . . . ");
    Console.ReadKey(true);
}

I'm using Firebird Embedded v2.5.1 and FirebirdSql.Data.FirebirdClient v2.7.0.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你不是我要的菜∠ 2025-01-12 15:12:02

从另一个网站得到了答案。看来需要将此行替换

FbScript script = new FbScript("DB_GEN.sql");

为此

StreamReader sr = File.OpenText(@"C:\TEMP\DB_GEN.sql");
FbScript script = new FbScript(sr.ReadToEnd());

脚本已正确运行!

Got the answer from another site. It appears there was need to replace this line

FbScript script = new FbScript("DB_GEN.sql");

by this

StreamReader sr = File.OpenText(@"C:\TEMP\DB_GEN.sql");
FbScript script = new FbScript(sr.ReadToEnd());

Script was run correctly!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文