37.10. Processing Embedded SQL Programs
Now that you have an idea how to form embedded SQL C programs, you probably want to know how to compile them. Before compiling you run the file through the embedded SQL C preprocessor, which converts the SQL statements you used to special function calls. After compiling, you must link with a special library that contains the needed functions. These functions fetch information from the arguments, perform the SQL command using the libpq interface, and put the result in the arguments specified for output.
The preprocessor program is called
ecpg and is included in a normal Postgres Pro installation. Embedded SQL programs are typically named with an extension
.pgc. If you have a program file called
prog1.pgc, you can preprocess it by simply calling:
This will create a file called
prog1.c. If your input files do not follow the suggested naming pattern, you can specify the output file explicitly using the
The preprocessed file can be compiled normally, for example:
cc -c prog1.c
The generated C source files include header files from the Postgres Pro installation, so if you installed Postgres Pro in a location that is not searched by default, you have to add an option such as
-I/usr/local/pgsql/include to the compilation command line.
To link an embedded SQL program, you need to include the
libecpg library, like so:
cc -o myprog prog1.o prog2.o ... -lecpg
Again, you might have to add an option like
-L/usr/local/pgsql/lib to that command line.
If you manage the build process of a larger project using make, it might be convenient to include the following implicit rule to your makefiles:
ECPG = ecpg %.c: %.pgc $(ECPG) $<
The complete syntax of the
ecpg command is detailed in ecpg.
The ecpg library is thread-safe by default. However, you might need to use some threading command-line options to compile your client code.
37.10 - Utafiti wa Kuunganisha programu za SQL: Sasa kwa kuwa una wazo la jinsi ya kuunda programu za SQL C zilizowekwa, labda unataka kujua jinsi ya kuziunganisha. Kabla ya kukusanya wewe kukimbia faili kupitia embedded SQL C preprocessor, ambayo hubadilisha SQL taarifa wewe kutumika kwa wito maalum kazi. Baada ya kukusanya, lazima kuunganisha na maktaba maalum ambayo ina kazi zinahitajika. Kazi hizi kupata habari kutoka hoja, kutekeleza amri SQL kwa kutumia libpq interface, na kuweka matokeo katika hoja maalum kwa ajili ya pato. Programu ya preprocessor inaitwa ecpg na ni pamoja na katika kawaida Postgres Pro ufungaji. Programu za SQL zilizoingizwa kawaida huitwa na ugani.pgc. Kama una faili ya programu aitwaye prog1.pgc, unaweza preprocess yake kwa tu wito: Hii itaunda faili aitwaye prog1.c. "Ikiwa faili zako za kuingia hazifuati muundo wa jina uliopendekezwa, unaweza kutaja faili ya pato kwa kutumia ""Fili iliyotengenezwa kabla ya kuunganishwa kwa kawaida, kwa mfano: CC-C-PROG1.c"" faili za chanzo za C zinazozalishwa ni pamoja na faili za kichwa kutoka kwa usakinishaji wa Postgres Pro, kwa hivyo ikiwa umeweka Postgres Pro katika eneo ambalo halitafutwi kwa default, lazima uongeze chaguo kama vile ""I-U-S-R-L-O-C-L-C-G-S-L-C-L-C-L-C-L-C-L-C-C-L-C-C-L-C-C-L-C-C-L-C-C-C-L-C-C-C-C-C-L-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C-C "Kama programu ya SQL iliyoingizwa, unahitaji kujumuisha maktaba ya libpg, kama vile: ""cc"" -o ""myprog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -o ""prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -prog"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro"" -pro" Ikiwa unaendesha mchakato wa ujenzi wa mradi mkubwa kwa kutumia fomu ya fomu, inaweza kuwa rahisi kujumuisha sheria ifuatayo ya fomu ya fomu: ECPG = ECPG %c %pgc $ (ECPG) $ (ECPG) maktaba ecpg ni thread-salama kwa default. Hata hivyo, unaweza haja ya kutumia baadhi ya threading amri-line chaguzi kukusanya code yako mteja.