SOCI Logo Get SOCI at SourceForge.net. Fast, secure and Free Open Source software downloads

factory.cpp

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004-2007 Maciej Sobczak, Stephen Hutton
00003 // Distributed under the Boost Software License, Version 1.0.
00004 // (See accompanying file LICENSE_1_0.txt or copy at
00005 // http://www.boost.org/LICENSE_1_0.txt)
00006 //
00007 
00008 #define SOCI_ORACLE_SOURCE
00009 #include "soci-oracle.h"
00010 #include <cctype>
00011 #include <cstdio>
00012 #include <cstring>
00013 #include <ctime>
00014 #include <sstream>
00015 
00016 #ifdef _MSC_VER
00017 #pragma warning(disable:4355)
00018 #endif
00019 
00020 using namespace soci;
00021 using namespace soci::details;
00022 
00023 // retrieves service name, user name and password from the
00024 // uniform connect string
00025 void chop_connect_string(std::string const & connectString,
00026     std::string & serviceName, std::string & userName,
00027     std::string & password, int & mode)
00028 {
00029     // transform the connect string into a sequence of tokens
00030     // separated by spaces, this is done by replacing each first '='
00031     // in each original token with space
00032     // note: each original token is a key=value pair and only the first
00033     // '=' there is replaced with space, so that potential '=' signs
00034     // in the value part are left intact
00035 
00036     std::string tmp;
00037     bool in_value = false;
00038     for (std::string::const_iterator i = connectString.begin(),
00039              end = connectString.end(); i != end; ++i)
00040     {
00041         if (*i == '=' && in_value == false)
00042         {
00043             // this is the first '=' in the key=value pair
00044             tmp += ' ';
00045             in_value = true;
00046         }
00047         else
00048         {
00049             tmp += *i;
00050             if (*i == ' ' || *i == '\t')
00051             {
00052                 // follow with the next key=value pair
00053                 in_value = false;
00054             }
00055         }
00056     }
00057 
00058     serviceName.clear();
00059     userName.clear();
00060     password.clear();
00061     mode = OCI_DEFAULT;
00062 
00063     std::istringstream iss(tmp);
00064     std::string key, value;
00065     while (iss >> key >> value)
00066     {
00067         if (key == "service")
00068         {
00069             serviceName = value;
00070         }
00071         else if (key == "user")
00072         {
00073             userName = value;
00074         }
00075         else if (key == "password")
00076         {
00077             password = value;
00078         }
00079         else if (key == "mode")
00080         {
00081             if (value == "sysdba")
00082             {
00083                 mode = OCI_SYSDBA;
00084             }
00085             else if (value == "sysoper")
00086             {
00087                 mode = OCI_SYSOPER;
00088             }
00089             else if (value == "default")
00090             {
00091                 mode = OCI_DEFAULT;
00092             }
00093             else
00094             {
00095                 throw soci_error("Invalid connection mode.");
00096             }
00097         }
00098     }
00099 }
00100 
00101 // concrete factory for Empty concrete strategies
00102 oracle_session_backend * oracle_backend_factory::make_session(
00103      std::string const &connectString) const
00104 {
00105     std::string serviceName, userName, password;
00106     int mode;
00107 
00108     chop_connect_string(connectString, serviceName, userName, password, mode);
00109 
00110     return new oracle_session_backend(serviceName, userName, password, mode);
00111 }
00112 
00113 oracle_backend_factory const soci::oracle;
00114 
00115 extern "C"
00116 {
00117 
00118 // for dynamic backend loading
00119 SOCI_ORACLE_DECL backend_factory const * factory_oracle()
00120 {
00121     return &soci::oracle;
00122 }
00123 
00124 } // extern "C"
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
SourceForge Logo

Generated on Sun Oct 3 2010 17:42:16 for EXTRAS-SOCI by Doxygen 1.7.1