summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libdbpp/connection.cpp4
-rw-r--r--libdbpp/unittests/testConnection.cpp11
2 files changed, 13 insertions, 2 deletions
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp
index 24d19f9..333becb 100644
--- a/libdbpp/connection.cpp
+++ b/libdbpp/connection.cpp
@@ -1,5 +1,6 @@
#include "connection.h"
#include "modifycommand.h"
+#include "error.h"
#include <factory.impl.h>
#include <buffer.h>
#include <sqlParse.h>
@@ -19,6 +20,9 @@ DB::Connection::execute(const std::string & sql) const
void
DB::Connection::executeScript(std::istream & f, const boost::filesystem::path & s) const
{
+ if (!f.good()) {
+ throw SqlParseException("Script stream not in good state.", 0);
+ }
DB::SqlParse p(f, s, this);
while (p.yylex()) ;
}
diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp
index 86ca2a8..a40c5cc 100644
--- a/libdbpp/unittests/testConnection.cpp
+++ b/libdbpp/unittests/testConnection.cpp
@@ -66,11 +66,18 @@ BOOST_AUTO_TEST_CASE( resolve )
BOOST_REQUIRE_THROW(DB::ConnectionFactory::createNew("otherdb", "doesn't matter"), AdHoc::LoadLibraryException);
}
+BOOST_AUTO_TEST_CASE( parseBad )
+{
+ auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter");
+ std::fstream s("/bad");
+ BOOST_REQUIRE_THROW(mock->executeScript(s, rootDir), DB::SqlParseException);
+ delete mock;
+}
+
BOOST_AUTO_TEST_CASE( parse )
{
auto mock = DB::ConnectionFactory::createNew("MockDb", "doesn't matter");
std::fstream s((rootDir / "parseTest.sql").string());
- BOOST_REQUIRE(s.good());
mock->executeScript(s, rootDir);
MockDb * mockdb = dynamic_cast<MockDb *>(mock);
BOOST_REQUIRE(mockdb);
@@ -84,7 +91,7 @@ BOOST_AUTO_TEST_CASE( parse2 )
auto mock = DB::ConnectionPtr(DB::ConnectionFactory::createNew("MockDb", "doesn't matter"));
auto mockdb = boost::dynamic_pointer_cast<MockDb>(mock);
BOOST_REQUIRE(mockdb);
- std::fstream s;
+ std::ifstream s;
s.open((rootDir / "dollarQuote.sql").string());
mock->executeScript(s, rootDir);