【问题标题】:Firebird Execute StatementFirebird 执行语句
【发布时间】:2014-05-23 20:30:03
【问题描述】:

我正在尝试使用执行块将多行插入到 firebird 表中。但我收到一条错误消息,提示“术语”无效。

"Dynamic SQL Error nSQL error code = -104 Token unknown - line 1, column 5 term"

这是我用于插入的 C# 代码

connection.Open();
string insertData = "set term ^ ; execute block as begin;";

foreach (dataPoint dataPointInsert in dataPointList)
{                      
    insertData += string.Format(" insert into data (trip_id, trip_type, longitude, latitude, speed, date_time, heading, valid) values ('{0}','{1}','{2}','{3}',{4},'{5}','{6}',{7});",
                                  dataPointInsert.GUID, dataPointInsert.tripType, dataPointInsert.longitude, dataPointInsert.latitude, dataPointInsert.speed, dataPointInsert.dateTime, dataPointInsert.heading, Convert.ToInt32(dataPointInsert.valid));
}

insertData += " end^";

var createCommand = new FbCommand(insertData, connection);
createCommand.ExecuteNonQuery();

我试图在 firebird 网站 here 上复制该示例。

我使用的是 firebird 2.5.2 版和 Firebird ADO.NET Data provider 4.1.5.0

【问题讨论】:

标签: c# sql .net firebird


【解决方案1】:

你不必(事实上你不应该,因为它是一个客户端命令,Firebird 不理解它)必须使用set term,因为FbCommand 和 Firebird 本身(在协议中)只能执行一个“批量”查询。

所以只需创建你的execute block 声明就可以了。

【讨论】:

  • 我最终做了一个执行块,但遇到了我认为语句不能大于 64KB 的问题。我最终将我的陈述分成 50000 个字符的块,现在效果很好。现在在 2 秒内输入大约 10000 条记录。
  • 是的,大小有很多限制。最明显的可能是您提到的那个。
【解决方案2】:

你不必使用 set term ^;

只需用 ^ 结束您的代码

如果您必须将 term 设置为 ^,请将其放回 set term ;^

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多