1

我计划使用 PostgreSQL SPI 将 SQL 嵌入到我的 C 代码中,并且我想引用 NAMEDATALEN const,因此我的代码将足够灵活,可以随数据库进行更改。

有没有#include <>我可以在我的 C 代码中引用这个常量的?

4

1 回答 1

1

答案引用自:完整的 C 类型表 (PostgreSQL v.9.1)

----------------------------------
| SQL Type | C Type | Defined In |
----------------------------------
|   name   |  Name  | postgres.h |
----------------------------------

看起来我需要做以下事情来实现我的目标......

 #include <postgres.h>

 //char my_name[NAMEDATALEN];  // Theoretically, this should also be valid.
 Name my_name;


编辑:经过更多的挖掘,我能够证明我的预感是正确的。


粘贴自postgres.h

00047 #include "c.h"

粘贴自c.h

00443 /*
00444  * Representation of a Name: effectively just a C string, but null-padded to
00445  * exactly NAMEDATALEN bytes.  The use of a struct is historical.
00446  */
00447 typedef struct nameData
00448 {
00449     char        data[NAMEDATALEN];
00450 } NameData;
00451 typedef NameData *Name;
于 2012-11-13T18:25:08.430 回答