[odb-users] Re: odb for oracle ?

Boris Kolpackov boris at codesynthesis.com
Thu Feb 3 08:32:22 EST 2011


Hi Kannan,

In the future please keep your replies CC'ed to the odb-users mailing
list as discussed in the posting guidelines:

http://www.codesynthesis.com/support/posting-guidelines.xhtml

Kannan <kannan024 at gmail.com> writes:

> I meant we will need to change the odb header file if the library gets changed.
> If we could make in a way, we don't need to change the code, but just change 
> the database library to be linked will it work ? or will this approach become 
> similar to odbc ?
> 
> #include <odb/database.hxx>
> #include <odb/transaction.hxx>
> #include <odb/mysql/database.hxx>  //change will be required in the code 
> 
> #include "Person.hpp"
> #include "Person-odb.hpp"

You will need to change two lines of code in your application: the include
directive above and the line that creates the concrete database instance:

#include <odb/mysql/database.hxx>

auto_ptr<odb::database> db (new odb::mysql::database (...));

Becomes (once Oracle runtime is available):

#include <odb/oracle/database.hxx>

auto_ptr<odb::database> db (new odb::oracle::database (...));

You can also factor out the creation of the concrete database instance
into a separate source file or use preprocessor macros to control which
database is used. Both of these technique are used in the ODB examples
(see the database.hxx file). This way your application code stays unchanged
and you only change the database macro/library in your build script.


[The rest of the original email follows for context.]
> 
> 
> I use Cmake for build
> 
> project(Testodb)
> cmake_minimum_required(VERSION 2.8)
> #set(CMAKE_VERBOSE_MAKEFILE TRUE)
> set(CMAKE_BUILD_TYPE DEBUG)
> link_directories(/usr/local/lib)
> 
> set(all_SOURCES main.cpp
> 		name.cpp
> 		Person.cpp
> 		contact.cpp)
> 
> set(dba_SOURCES  Person.hpp
> 		 name.hpp
> 		 contact.hpp)
> 
> set(gen_SOURCES)
> 
> foreach(_file ${dba_SOURCES})
>   string(REPLACE ".hpp" "-odb.cpp" gencppfile ${_file})
>   add_custom_command(
> 			OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${gencppfile} 
> 			COMMAND odb -d mysql --hxx-suffix .hpp --ixx-suffix .ipp --cxx-suffix .cpp
> 				--output-dir ${CMAKE_CURRENT_SOURCE_DIR}
> 				--generate-query --generate-schema ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
> 				
> 			DEPENDS ${_file}
> 		     )
>   #list(APPEND gen_SOURCES ${gencppfile})
> list(APPEND all_SOURCES ${gencppfile})
> endforeach()
> 
> add_executable(Testodb ${all_SOURCES})
> target_link_libraries(Testodb odb-mysql odb)  //Just change to odb-oracle for 
> oracle database. will it work ?
> 
> Thanks,
> Kannan

Boris



More information about the odb-users mailing list