Postgresql 中文操作指南
Description
ecpg 是 C 程序的嵌入式 SQL 预处理器。它将带有嵌入式 SQL 语句的 C 程序转换为常规 C 代码,方法是用特殊函数调用替换 SQL 调用。然后,可以使用任何 C 编译器工具链处理输出文件。
ecpg is the embedded SQL preprocessor for C programs. It converts C programs with embedded SQL statements to normal C code by replacing the SQL invocations with special function calls. The output files can then be processed with any C compiler tool chain.
ecpg 将命令行中给定的每个输入文件转换为相应的 C 输出文件。如果输入文件名没有任何扩展名,则假定为 .pgc 。将用 .c 替换该文件的后缀以构建输出文件名。但是,可以使用 -o 选项覆盖输出文件名。
ecpg will convert each input file given on the command line to the corresponding C output file. If an input file name does not have any extension, .pgc is assumed. The file’s extension will be replaced by .c to construct the output file name. But the output file name can be overridden using the -o option.
如果输入文件名只是 - , ecpg 从标准输入读取程序(并写入标准输出,除非使用 -o 覆盖)。
If an input file name is just -, ecpg reads the program from standard input (and writes to standard output, unless that is overridden with -o).
此参考页面不描述嵌入式 SQL 语言。有关该主题的更多信息,请参见 Chapter 36 。
This reference page does not describe the embedded SQL language. See Chapter 36 for more information on that topic.
Options
ecpg 接受以下命令行参数:
ecpg accepts the following command-line arguments:
-
-c
-
Automatically generate certain C code from SQL code. Currently, this works for EXEC SQL TYPE.
-
-
-C _mode_
-
Set a compatibility mode. mode can be INFORMIX, INFORMIX_SE, or ORACLE.
-
-
-D _symbol[=value]_
-
Define a preprocessor symbol, equivalently to the EXEC SQL DEFINE directive. If no value is specified, the symbol is defined with the value 1.
-
-
-h
-
Process header files. When this option is specified, the output file extension becomes .h not .c, and the default input file extension is .pgh not .pgc. Also, the -c option is forced on.
-
-
-i
-
Parse system include files as well.
-
-
-I _directory_
-
Specify an additional include path, used to find files included via EXEC SQL INCLUDE. Defaults are . (current directory), /usr/local/include, the PostgreSQL include directory which is defined at compile time (default: /usr/local/pgsql/include), and /usr/include, in that order.
-
-
-o _filename_
-
Specifies that ecpg should write all its output to the given filename. Write -o - to send all output to standard output.
-
-
-r _option_
-
Selects run-time behavior. Option can be one of the following:
-
-
-t
-
Turn on autocommit of transactions. In this mode, each SQL command is automatically committed unless it is inside an explicit transaction block. In the default mode, commands are committed only when EXEC SQL COMMIT is issued.
-
-
-v
-
Print additional information including the version and the "include" path.
-
-
—version
-
Print the ecpg version and exit.
-
-
-?_—help_
-
Show help about ecpg command line arguments, and exit.
-
-
no_indicator
-
Do not use indicators but instead use special values to represent null values. Historically there have been databases using this approach.
-
-
prepare
-
Prepare all statements before using them. Libecpg will keep a cache of prepared statements and reuse a statement if it gets executed again. If the cache runs full, libecpg will free the least used statement.
-
-
questionmarks
-
Allow question mark as placeholder for compatibility reasons. This used to be the default long ago.
-
Notes
在编译预处理过的 C 代码文件时,编译器需要能够在 PostgreSQL 包含目录中找到 ECPG 头文件。因此,您在调用编译器时可能需要使用 -I 选项(例如, -I/usr/local/pgsql/include )。
When compiling the preprocessed C code files, the compiler needs to be able to find the ECPG header files in the PostgreSQL include directory. Therefore, you might have to use the -I option when invoking the compiler (e.g., -I/usr/local/pgsql/include).
使用嵌入式 SQL 的 C 代码的程序必须链接到 libecpg 库,例如使用链接器选项 -L/usr/local/pgsql/lib -lecpg 。
Programs using C code with embedded SQL have to be linked against the libecpg library, for example using the linker options -L/usr/local/pgsql/lib -lecpg.
可以使用 pg_config 找到适用于安装的这些目录的任何一个目录的值。
The value of either of these directories that is appropriate for the installation can be found out using pg_config.
Examples
如果您有一个名为 prog1.pgc 的嵌入式 SQL C 源文件,可以使用以下命令序列创建可执行程序:
If you have an embedded SQL C source file named prog1.pgc, you can create an executable program using the following sequence of commands:
ecpg prog1.pgc
cc -I/usr/local/pgsql/include -c prog1.c
cc -o prog1 prog1.o -L/usr/local/pgsql/lib -lecpg