This article supporting the source code download
First, the preface
At present, many units in the system transformation and upgrading, faced with the development of various independent departments of the application of the database unified to adapt to the needs of large concentration of data, to facilitate future data mining and other high-level applications. In the process of database unification, how to transform the existing program based on heterogeneous database quickly and efficiently, especially the program under Linux/unix, which is developed by C/D + +, has become a problem faced by many units. Of course, the process based on RAD, basically does not need to be modified, can achieve the goal.
For how to quickly migrate Sybase C programs into Oracle PRO*C programs, this article will point out a direction and give a rough framework. In this article, I hope you will guide. (Plan to write a conversion series to see how you react)
Second, the principle
Sybase's C program is converted to Oracle's PRO*C program and has many advantages over other types of conversions (forgive me for choosing the simplest possible conversion):
The Sybase program uses the C function call method, which makes it very convenient to convert Sybase programs to any other database program. Only need to use the syntax of the destination database, the old program to achieve the use of Sybase functions can be! And no need for the original C program to make any logical changes!
Oracle's PRO*C provides a way to develop dynamic SQL, which is a great convenience for porting.
Oracle Pro*c also provides process multiple connectivity with Sybase.
When Oracle 9 uses the parse=full compilation option, the C definition variable can be used directly in exec SQL, which makes the program much easier to write.
There are other advantages that will not be enumerated.
Third, realize
Less nonsense, the following to the point:
For some of the main functions of Sybase, the following is an overview of the approach, the specific implementation of the reference source code:
- Dbinit (): This function initializes only some variables for database operations.
- Some user name, password settings, there is not much to say. relatively simple.
- Dbopen (): The function is actually connected to the database, during the connection, I set the global variable allopenprocess to hold all the connection pointers and generate a connection string to identify the connection. stored in global variables because the Sybase function dbexit has no input parameters.
- dbcmd (): This function carries out an analysis of the SQL statement for further judgment.
- Dbexec (): The function performs the execution of the command (it is not clear why Sybase separates the function from the dbcmd). Commands that do not return a result set (INSERT, UPDATE, delete) are executed directly through the syntax of the exec SQL at EXECUTE immediate. The Oracle dynamic SQL4 method is used to deal with the select with the return result set. Because of the relationship between time and the old program, the implementation of this function is only for strings passing in the full SQL statement.
- Dbresults (): determines the return result.
- Dbbind (): Binds the address where the value is stored and determines whether the incoming type is correct. Because the old program only uses the Ntbstringbind type, the example also only deals with this type.
- Dbnumcols (): Returns the number of data columns, valid when the statement type is select.
- dbnextrow (): Gets the next data value and fills it in the address space that dbbind is bound to. This requires data conversion based on the source type select_dp->t[] and the target type.
- Dbdead (): Determines whether the database connection is normal. Tested using a value from the dual table.
- Dbexit (): Exits the database connection.
There are many other functions, but because I did not use it, hehe, it is not implemented.
Four Transplantation
The porting method is very simple, the original C/#include "Sybfront.h" #include "sybdb.h" and other references to the Sybase header file, replace the #include "database_op.h" in the attachment, At the same time, add Database_op.cxx in the attachment to the project, add the appropriate compilation statement (PROC), and then remove the previously connected Sybase Lib to join Oracle's lib:orasql9.lib. Can be in the basic without modifying the source program to complete the transplant program! Of course, if your Sybase program uses a ntbstringbind type, you should add the relevant processing method to your cxx file. Good luck! Welcome to explore.
V. Skills
Below I summarize some of the small techniques used in the development process, you laughed. How to make full use of Visual C + + development environment for PRO*C program development:
I believe that you are familiar with the integrated development environment of Visual C + +, don't tell me you have developed the Unix-C + + program is still using VI, UltraEdit, EditPlus Bar! Of course, I don't mind if you insist, but you don't have to waste your time turning the page down now.
Oracle's PRO*C programs typically end with a PC. And the end of the program, the PC can not follow the syntax of C + + in Visual C + + integrated development environment display! It's just a piece of black and white. Unlike UltraEdit, you can customize the PC file to be displayed according to C + + syntax (Wordfile in the UltraEdit installation directory). TXT file contains "C CPP CC CXX H HPP AWK" content followed by "PC" on it (perhaps VC has this function, but I did not find). What do we do? Simple, modify the PC file suffix to cxx, at this point, the file is shown in accordance with C + + syntax! At this point, set the File property page (select the file in the VC development Environment workspace, press ALT+F7) under General's Always use custom build step is selected, Curstom the commands/o under the build page Utputs, refer to Oracle's example and enter the appropriate compilation options. Remember to change the corresponding PC suffix to the cxx suffix.