Menu

[r1571]: / cppdb / trunk / cppdb / utils.h  Maximize  Restore  History

Download this file

93 lines (82 with data), 3.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPDB_UTIL_H
#define CPPDB_UTIL_H
#include <cppdb/defs.h>
#include <string>
#include <ctime>
#include <map>
namespace cppdb {
///
/// \brief parse a string as time value.
///
/// Used by backend implementations;
///
CPPDB_API std::tm parse_time(char const *value);
///
/// \brief format a string as time value.
///
/// Used by backend implementations;
///
CPPDB_API std::string format_time(std::tm const &v);
///
/// \brief parse a string as time value.
///
/// Used by backend implementations;
///
CPPDB_API std::tm parse_time(std::string const &v);
///
/// \brief Parse a connection string \a cs into driver name \a driver_name and list of properties \a props
///
/// The connection string format is following:
///
/// \verbatim driver:[key=value;]* \endverbatim
///
/// Where value can be either a sequence of characters (white space is trimmed) or it may be a general
/// sequence encloded in a single quitation marks were double quote is used for insering a single quote value.
///
/// Key values starting with \@ are reserved to be used as special cppdb keys
/// For example:
///
/// \verbatim mysql:username= root;password = 'asdf''5764dg';database=test;@use_prepared=off' \endverbatim
///
/// Where driver is "mysql", username is "root", password is "asdf'5764dg", database is "test" and
/// special value "@use_prepared" is off - internal cppdb option.
CPPDB_API void parse_connection_string( std::string const &cs,
std::string &driver_name,
std::map<std::string,std::string> &props);
class CPPDB_API connection_info {
public:
std::string connection_string;
std::string driver;
typedef std::map<std::string,std::string> properties_type;
properties_type properties;
std::string get(std::string const &prop,std::string const &default_value=std::string()) const;
int get(std::string const &prop,int default_value) const;
connection_info()
{
}
explicit connection_info(std::string const &cs) :
connection_string(cs)
{
parse_connection_string(cs,driver,properties);
}
};
}
#endif
MongoDB Logo MongoDB