2

I've been attempting to write embedded SQL statements for DB2 that ultimately gets compiled in C.

I couldn't find a tutorial or manual on the embedded SQL syntax for C for reference. One case I would like to do is to insert data into a table. I know most embedded sql statements need the initalizer EXEC SQL, but that's the extent of my knowledge generally. I'm doing this for an assignment and would appreciate if there are more information regarding this or solution.

Example of a statement to query the database:

EXEC SQL SELECT SNAME, AGE into :sname, :sage
    FROM ONE.SAILOR
    WHERE sid = :sid;

I like to see what statement allows me to INSERT into the database. I've tried something like the following, but it doesn't work.

 EXEC SQL INSERT ....
4

3 回答 3

2

请参阅 IBM 的嵌入式 SQL手册。

无论宿主语言是什么,嵌入式 SQL 基本相同。

于 2008-11-19T01:25:13.223 回答
2

这四个点在语法上无效:-D

可靠的方法与任何其他 INSERT 语句相同:列出列和值。

EXEC SQL INSERT INTO SomeTable(Col1, Col2, Col3) VALUES(:hv1, :hv2, :hv3);

在这里,:hv1、:hv2 和:hv3 代表与表中的列相应的类型的三个主变量。请注意,该表可以包含除这三个之外的其他列,只要这些列具有指定的默认值或接受 NULL(在这种情况下实际上只是默认值)。不可靠的方式不列出列:

EXEC SQL INSERT INTO SomeTable VALUES(:hv1, :hv2, :hv3);

现在您依赖于获得正确的序列,并且您必须为每一列提供一个值——SomeTable 中不能有额外的列。

于 2008-11-19T05:36:52.560 回答
1

我刚开始使用sqllite。除了 C++ 的良好文档之外,拥有 SQLlist 可能是一件好事,因为您可以在不依赖 DB2 的情况下对代码进行单元测试,并且很容易添加到您的代码中。

于 2008-11-19T03:45:44.640 回答