Turn: http://blog.csdn.net/clever101/article/details/1792075
Last Saturday, I took the time to learn about Pro * C/C ++. I used the reference book "proficient in Oracle 10gPro * C/C ++ programming". In my opinion, the Pro * C/C ++ syntax is not difficult, that is, it is a bit difficult to set the environment. Programming is like this. It starts with a hurdle. If the compiling environment is not well set and the output result is not visible, it is difficult to get that sense of accomplishment. The following is a simple example to illustrate how to set the compiling environment of Pro * C/C ++. The development environment is: Win XP sp2, VC ++ 6.0, OCI: version 9.2, Oracle DataBase 10g Enterprise Edition Release 10.1.0.2.0. It is said that Oracle provides the Pro * C/C ++ graphical interface tool for the Windows platform, but the Oracle 10 Gb I installed does not contain this graphic interface tool. Well, use the Proc on the console. Pro * C/C ++ is generally divided into four steps: 1. specify the executable file path, header file path, and library file path. In fact, in Visual C ++, specify the Pro * C/c00000000precompiled proc.exe that runs Oracle 10 Gb. This proc.exe is available on both the server side and the client side. I think it is the same. Here, the server is used. The specific method is: On the Directory tab of the TOOl> Option menu item in VC 6.0, select Executable files in the Show directoryes for Option to add the proc.exe path, as shown in: as for adding header files and library files, I think people who have been engaged in secondary development are clear, so I will not elaborate on them one by one. What header files should be added? There are mainly two headers, one being sqlca. the directory where h is located is generally precomp/public, and the header file of OCI, as shown in: As for the library file, you only need to add the OCI library file, as shown in: in the future, you may need to add the corresponding header files and library files as needed. 2. Use the configuration file to set the pre-compilation options. Because we just got started, this time we use the system configuration file, but the system configuration file does not fully meet our needs. For example, the system configuration file does not contain the parsing embedded SQL syntax, therefore, edit the system configuration file. The system configuration file is usually % precomp/admin/pcscfg. cfg. Here we will refer to my Oracle installation directory. my options are: D:/Oracle/Server/precomp/admin/pcscfg. cfg. Open this file using notepad (other text editing tools) and add the following content to it: parse = fullinclude = "C: /Program Files/Microsoft Visual Studio/VC98/INCLUDE "include =" D:/Oracle/Server/precomp/public "include =" D: /Oracle/Server/OCI/include "parse = full indicates all the syntaxes for parsing the source file, including C and embedded SQL syntaxes. include specifies the path of the header file, including the Visual C ++ header file path, ProC/C ++ header file path, and OCI header file path. 3. Establishing engineering documents and officially starting programming the exciting programming time has finally arrived. First, use NotePad to create a text file and enter the following code: # include <stdio. h> # include <string. h> # include <stdlib. h> # include <conio. h> # include <sqlca. h> int main () {char username [10], password [10], server [10]; printf ("input username:/n"); gets (username ); printf ("Enter password:/n"); gets (password); printf ("enter network service name:/n"); gets (server); exec SQL CONNECT: username identified by: password USING: server; if (sqlca. sqlcode = 0) printf ("connection successful! /N "); else printf (" %. * s/n ", sqlca. sqlerrm. sqlerrml, sqlca. sqlerrm. sqlerrmc); getch (); return 0;} is saved as demo. pc (note the suffix here. pc) Create an empty console project demo on VC, select Source File on the FileView page, and set demo. add the pc to the project (), as shown in. Then, enter demo in the file name using the same method. c. Because the file does not exist at this time, the following prompt dialog box is displayed: Click Yes, so that. add the c file to the project file. Note that demo. c is generated after pre-compilation. Then Add the SQLLIB library, specifically: select Source Fil on the FileView page, select Add Files To Folder, and Add the oraSQL10.LIB file To the project, this file is generally stored in the precomp/lib subdirectory under the Oracle Installation File directory. For example, create a pre-compilation Command, as follows: 1. right-click and select demo. pc, such as: 2. right-click setting from the menu, and enter proc F:/MyProSrc/ProC/Demo/demo.pcin the Command edit box. You can call proc.exe to set the file F:/MyProSrc/ProC/Demo/demo. in the Outputs edit box, enter F:/MyProSrc/ProC/Demo/demo. c, which means that the pre-compiled output file is: F:/MyProSrc/ProC/Demo/demo. c. Click OK to save the settings. After completing the preceding settings, you can create and generate an executable file. Press the Ctrl + F5 shortcut key. Visual C ++ calls the proc tool for pre-compilation, converts the pc source program into the c code, and then compiles the c code to generate the target code, finally, link the target code and the sqllib library file to generate the executable file. The program runs as follows: