|
ECPG is the standard, in the PostgreSQL database built-in, client programming interface for embedding SQL in programs written in the C programming language. It provides the option for accessing the PostgreSQL database directly from the C code in the application, using SQL commands. == Usage == The usage can be divided to 2 steps. First, a .pcg file has to be created, which consists of C code with embedded SQL code. In such file SQL code will be inserted directly to the application's C code. The SQL commands have to be inserted into the C code in following way: // ... C code ... EXEC SQL // ... C code ... An example how to connect to a database: EXEC SQL CONNECT TO databasename()() (connectionname ) (username ); The embedded SQL part will be processed trough ECPG preprocessor where SQL code will be replaced with the calls to the ecpg library (libecpg.a or libecpg.so). The .pcg file will be also preprocessed with ecpg, which converts it to a .c file according to the ANSI standards. Therefore, in the second step, the generated .c file can be directly compiled with a standard C compiler. Following command will create from the ''my_c_file_with_embedded_sql_commands.pcg'' file a ''my_c_file_with_embedded_sql_commands.c'' file, which can be processed further as a pure C code. $ ecpg my_c_file_with_embedded_sql_commands.pcg There is also source code of the ecpg available in the (PostgreSQL Source Code git ) repository. Note: While compiling the preprocessed .c code, do not forget to link the ecpg library (libepcg), so that the generated calls can find their linked methods. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「ECPG」の詳細全文を読む スポンサード リンク
|