aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-07-21 15:24:46 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-07-22 17:57:00 +0200
commit794b3767df6f39e9b195e3a3735edf665f660c21 (patch)
tree7d7147d58fd282ab3f150e2f1d272d052c985e60
parent5cf8ecfc25d56e733e2c803942f1bee0378e6639 (diff)
Add support for SQL string quoting
-rw-r--r--odb/relational/context.cxx19
-rw-r--r--odb/relational/context.hxx14
-rw-r--r--odb/relational/context.ixx6
3 files changed, 39 insertions, 0 deletions
diff --git a/odb/relational/context.cxx b/odb/relational/context.cxx
index fcf3ac2..e8be832 100644
--- a/odb/relational/context.cxx
+++ b/odb/relational/context.cxx
@@ -59,6 +59,25 @@ namespace relational
}
string context::
+ quote_string_impl (string const& s) const
+ {
+ string r;
+ r.reserve (s.size ());
+ r += '\'';
+
+ for (string::size_type i (0), n (s.size ()); i < n; ++i)
+ {
+ if (s[i] == '\'')
+ r += "''";
+ else
+ r += s[i];
+ }
+
+ r += '\'';
+ return r;
+ }
+
+ string context::
quote_id_impl (string const& id) const
{
string r;
diff --git a/odb/relational/context.hxx b/odb/relational/context.hxx
index 08f8b81..e654aee 100644
--- a/odb/relational/context.hxx
+++ b/odb/relational/context.hxx
@@ -28,6 +28,11 @@ namespace relational
grow (semantics::data_member&, semantics::type&, string const& key_prefix);
public:
+ // Quote SQL string.
+ //
+ string
+ quote_string (string const&) const;
+
// Quote SQL identifier.
//
string
@@ -75,6 +80,15 @@ namespace relational
semantics::type&,
string const&);
+ // The default implementation uses the ISO quoting ('') and
+ // escapes singe quotes inside the string by double-quoting
+ // (' -> ''). Some (most?) database systems support escape
+ // sequences. We may want to provide utilize that to support
+ // things like \n, \t, etc.
+ //
+ virtual string
+ quote_string_impl (string const&) const;
+
// The default implementation uses the ISO quoting ("").
//
virtual string
diff --git a/odb/relational/context.ixx b/odb/relational/context.ixx
index da24d39..8bc10fa 100644
--- a/odb/relational/context.ixx
+++ b/odb/relational/context.ixx
@@ -24,6 +24,12 @@ namespace relational
}
inline context::string context::
+ quote_string (string const& str) const
+ {
+ return current ().quote_string_impl (str);
+ }
+
+ inline context::string context::
quote_id (string const& id) const
{
return current ().quote_id_impl (id);