开发者

Executing multiple statements in a single roundtrip with Informix

Is it possible to run multiple DML statements开发者_如何学编程 in a single roundtrip using Informix and .Net?

Example (of course this doesn't work):

var cmd = someIfxConnection.CreateCommand();
cmd.CommandText = @"
    insert into Foo(Bar, Baz) values (1, 2);
    insert into Foo(Bar, Baz) values (3, 4);";
cmd.ExecuteNonQuery();


As far as I'm aware, Informix allows you to perform multiple INSERT/UPDATE statements as you have in your example. What you CANNOT do is perform multiple statements that contain a SELECT.

For example, in SQL Server it is common to see code as follows:

INSERT INTO Foo(Bar, Baz) VALUES (1, 2); SELECT @@IDENTITY AS Id

This can be performed in a single command and would return the auto-incrementing primary key value from the newly inserted record.

This does not work within Informix however. You have to perform two distinct SQL commands. One to insert the record and one to retrieve the Id from the systables table:

SELECT DBINFO('sqlca.sqlerrd1') FROM systables WHERE tabid = 1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜