summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpqpp/pq-binarycolumn.cpp2
-rw-r--r--libpqpp/pq-column.cpp7
-rw-r--r--libpqpp/pq-column.h2
-rw-r--r--libpqpp/pq-command.cpp7
-rw-r--r--libpqpp/pq-command.h3
-rw-r--r--libpqpp/unittests/testpq.cpp4
6 files changed, 15 insertions, 10 deletions
diff --git a/libpqpp/pq-binarycolumn.cpp b/libpqpp/pq-binarycolumn.cpp
index ff49b26..1c6f9e2 100644
--- a/libpqpp/pq-binarycolumn.cpp
+++ b/libpqpp/pq-binarycolumn.cpp
@@ -19,7 +19,7 @@ PQ::BinaryColumn::apply(DB::HandleField & h) const
case 1043: //VARCHAROID:
case 25: //TEXTOID:
case 142: //XMLOID:
- h.string(value(), length());
+ h.string({ value(), length() });
break;
case 16: //BOOLOID:
h.boolean(valueAs<bool>());
diff --git a/libpqpp/pq-column.cpp b/libpqpp/pq-column.cpp
index 6dbbfd2..5e02015 100644
--- a/libpqpp/pq-column.cpp
+++ b/libpqpp/pq-column.cpp
@@ -25,7 +25,7 @@ PQ::Column::isNull() const
return PQgetisnull(sc->execRes, sc->tuple, colNo);
}
-int
+std::size_t
PQ::Column::length() const
{
return PQgetlength(sc->execRes, sc->tuple, colNo);
@@ -49,7 +49,8 @@ PQ::Column::apply(DB::HandleField & h) const
case 1043: //VARCHAROID:
case 25: //TEXTOID:
case 142: //XMLOID:
- h.string(value(), length());
+ default:
+ h.string({ value(), length() });
break;
case 16: //BOOLOID:
h.boolean(value()[0] == 't');
@@ -97,8 +98,6 @@ PQ::Column::apply(DB::HandleField & h) const
h.blob(DB::Blob(buf, len));
break;
}
- default:
- h.string(value(), length());
}
}
diff --git a/libpqpp/pq-column.h b/libpqpp/pq-column.h
index f6050ea..5c71d86 100644
--- a/libpqpp/pq-column.h
+++ b/libpqpp/pq-column.h
@@ -20,7 +20,7 @@ namespace PQ {
template<typename T>
inline T * valueAsPtr() const { return (T*)(value()); }
const char * value() const;
- int length() const;
+ std::size_t length() const;
const SelectBase * sc;
const Oid oid;
diff --git a/libpqpp/pq-command.cpp b/libpqpp/pq-command.cpp
index 58b5c49..97f649c 100644
--- a/libpqpp/pq-command.cpp
+++ b/libpqpp/pq-command.cpp
@@ -103,7 +103,7 @@ PQ::Command::paramSet(unsigned int n, const char * fmt, const T & ... v)
}
void
-PQ::Command::paramSet(unsigned int n, const std::string & b)
+PQ::Command::paramSet(unsigned int n, const std::string_view & b)
{
paramsAtLeast(n);
bufs[n] = new std::string(b);
@@ -159,6 +159,11 @@ PQ::Command::bindParamF(unsigned int n, float v)
void
PQ::Command::bindParamS(unsigned int n, const Glib::ustring & s)
{
+ paramSet(n, s.raw());
+}
+void
+PQ::Command::bindParamS(unsigned int n, const std::string_view & s)
+{
paramSet(n, s);
}
void
diff --git a/libpqpp/pq-command.h b/libpqpp/pq-command.h
index c2674eb..a26bae8 100644
--- a/libpqpp/pq-command.h
+++ b/libpqpp/pq-command.h
@@ -43,6 +43,7 @@ namespace PQ {
void bindParamF(unsigned int, float) override;
void bindParamS(unsigned int, const Glib::ustring&) override;
+ void bindParamS(unsigned int, const std::string_view&) override;
void bindParamT(unsigned int, const boost::posix_time::time_duration &) override;
void bindParamT(unsigned int, const boost::posix_time::ptime &) override;
@@ -59,7 +60,7 @@ namespace PQ {
void paramsAtLeast(unsigned int);
template<typename ... T>
void paramSet(unsigned int, const char * fmt, const T & ... t);
- void paramSet(unsigned int, const std::string &);
+ void paramSet(unsigned int, const std::string_view &);
std::vector<char *> values;
std::vector<int> lengths;
std::vector<int> formats;
diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp
index e5d86ef..0a13c1e 100644
--- a/libpqpp/unittests/testpq.cpp
+++ b/libpqpp/unittests/testpq.cpp
@@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE( bindAndSend )
mod->execute();
mod->bindParamI(0, (unsigned int)(testInt + 10));
mod->bindParamF(1, (float)(testDouble + 10));
- mod->bindParamS(2, testString + " something");
+ mod->bindParamS(2, std::string(testString) + " something");
mod->bindParamB(3, true);
mod->bindParamT(4, testDateTime);
mod->bindParamT(5, testInterval);
@@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE( bindAndSelectOther )
while (select->fetch()) {
assertColumnValueHelper(*select, 0, 4);
assertColumnValueHelper(*select, 1, 123.45);
- assertColumnValueHelper(*select, 2, std::string("some text with a ; in it and a ' too"));
+ assertColumnValueHelper(*select, 2, std::string_view("some text with a ; in it and a ' too"));
assertColumnValueHelper(*select, 3, true);
assertColumnValueHelper(*select, 4, boost::posix_time::ptime_from_tm({ 3, 6, 23, 27, 3, 115, 0, 0, 0, 0, 0}));
assertColumnValueHelper(*select, 5, boost::posix_time::time_duration(38, 13, 12));