From 331328221408de06270279bfd7f9d99576009b16 Mon Sep 17 00:00:00 2001 From: gaspardle Date: Mon, 5 Jan 2015 01:01:09 -0500 Subject: [PATCH] more cleanup --- mssql/COPYING.txt => COPYING.txt | 0 mssql/Makefile => Makefile | 0 mssql/README.md => README.md | 0 mssql/connection.hpp | 48 ++++++++---------- mssql/connection_manager.hpp | 15 ++++-- mssql/mssql.vcxproj | 1 - mssql/mssql.vcxproj.filters | 3 -- mssql/mssql_datasource.cpp | 54 ++------------------ mssql/resultset.hpp | 87 ++++++++++---------------------- mssql/targetver.h | 8 --- 10 files changed, 63 insertions(+), 153 deletions(-) rename mssql/COPYING.txt => COPYING.txt (100%) rename mssql/Makefile => Makefile (100%) rename mssql/README.md => README.md (100%) delete mode 100644 mssql/targetver.h diff --git a/mssql/COPYING.txt b/COPYING.txt similarity index 100% rename from mssql/COPYING.txt rename to COPYING.txt diff --git a/mssql/Makefile b/Makefile similarity index 100% rename from mssql/Makefile rename to Makefile diff --git a/mssql/README.md b/README.md similarity index 100% rename from mssql/README.md rename to README.md diff --git a/mssql/connection.hpp b/mssql/connection.hpp index ff70c8b..cc63bb0 100644 --- a/mssql/connection.hpp +++ b/mssql/connection.hpp @@ -51,19 +51,22 @@ class Connection //XXX string to wstring conversion std::wstring connect_with_pass; connect_with_pass.assign(connection_str.begin(), connection_str.end()); - /*if (password && !password->empty()) - { - connect_with_pass += " password=" + *password; - }*/ - if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlenvhandle)) - throw mapnik::datasource_exception("Mssql Plugin: SQLAllocHandle");// goto FINISHED; - if (SQL_SUCCESS != SQLSetEnvAttr(sqlenvhandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0)) - throw mapnik::datasource_exception("Mssql Plugin: SQLSetEnvAttr");// goto FINISHED; + if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlenvhandle)){ + close(); + throw mapnik::datasource_exception("Mssql Plugin: SQLAllocHandle"); + } + + if (SQL_SUCCESS != SQLSetEnvAttr(sqlenvhandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0)){ + close(); + throw mapnik::datasource_exception("Mssql Plugin: SQLSetEnvAttr"); + } - if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_DBC, sqlenvhandle, &sqlconnectionhandle)) - throw mapnik::datasource_exception("Mssql Plugin: SQLAllocHandle");// goto FINISHED; + if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_DBC, sqlenvhandle, &sqlconnectionhandle)){ + close(); + throw mapnik::datasource_exception("Mssql Plugin: SQLAllocHandle"); + } SQLWCHAR retconstring[1024]; SQLSMALLINT OutConnStrLen; @@ -79,7 +82,7 @@ class Connection { std::string err_msg = "Mssql Plugin: "; err_msg += status(SQL_HANDLE_DBC, sqlconnectionhandle); - err_msg += "\nConnection string: '"; + err_msg += "\nSQLDriverConnect Error, Connection string: '"; err_msg += connection_str; err_msg += "'\n"; close(); @@ -107,11 +110,8 @@ class Connection #ifdef MAPNIK_STATS mapnik::progress_timer __stats__(std::clog, std::string("mssql_connection::execute ") + sql); #endif - throw mapnik::datasource_exception("execute!"); - //PGresult *result = PQexec(conn_, sql.c_str()); - //bool ok = (result && (PQresultStatus(result) == PGRES_COMMAND_OK)); - //PQclear(result); - //return ok; + throw mapnik::datasource_exception("not implemented"); + } std::shared_ptr executeQuery(std::string const& sql) @@ -122,14 +122,13 @@ class Connection debug_current_sql = sql; SQLHANDLE hstmt = NULL; SQLRETURN retcode; - if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_STMT, sqlconnectionhandle, &hstmt)) - throw mapnik::datasource_exception("cant SQLAllocHandle"); + if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_STMT, sqlconnectionhandle, &hstmt)){ + throw mapnik::datasource_exception("SQLAllocHandle error"); + } retcode = SQLExecDirectA(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS); - - - if (!(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)) - // if (! result || (PQresultStatus(result) != PGRES_TUPLES_OK)) + + if (!(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)) { std::string err_msg = status(SQL_HANDLE_STMT, hstmt); err_msg += "\nFull sql was: '"; @@ -137,9 +136,6 @@ class Connection err_msg += "'\n"; SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - // PQclear(result); - - throw mapnik::datasource_exception(err_msg); } @@ -219,7 +215,7 @@ class Connection if (retcode != SQL_STILL_EXECUTING) break; - sleep(1); + //sleep(1); } return retcode; diff --git a/mssql/connection_manager.hpp b/mssql/connection_manager.hpp index aa5817a..f4eef99 100644 --- a/mssql/connection_manager.hpp +++ b/mssql/connection_manager.hpp @@ -76,7 +76,7 @@ class ConnectionCreator inline std::string connection_string() const { std::string connect_str = connection_string_safe(); - if (pass_ && !pass_->empty()) connect_str += " PWD=" + *pass_; + if (pass_ && !pass_->empty()) connect_str += "PWD=" + *pass_; return connect_str; } @@ -97,11 +97,16 @@ class ConnectionCreator connect_str += "DRIVER={SQL Server Native Client 11.0};"; } if (host_ && !host_->empty()) connect_str += "SERVER=" + *host_ + ";"; - if (port_ && !port_->empty()) connect_str += " port=" + *port_ + ";"; - if (dbname_ && !dbname_->empty()) connect_str += " DATABASE=" + *dbname_ + ";"; - if (user_ && !user_->empty()) connect_str += " UID=" + *user_ + ";"; + if (port_ && !port_->empty()) connect_str += "port=" + *port_ + ";"; + if (dbname_ && !dbname_->empty()) connect_str += "DATABASE=" + *dbname_ + ";"; + if (user_ && !user_->empty()) connect_str += "UID=" + *user_ + ";"; if (connect_timeout_ && !connect_timeout_->empty()) - connect_str += " connect_timeout=" + *connect_timeout_ + ";"; + connect_str += "connect_timeout=" + *connect_timeout_ + ";"; + /*if (encrypt_ && !encrypt_->empty()) + connect_str += "Encrypt=true;"; + if (trust_server_certificate_ && !trust_server_certificate_->empty()) + connect_str += "TrustServerCertificate=no;"; + */ } return connect_str; diff --git a/mssql/mssql.vcxproj b/mssql/mssql.vcxproj index acdc83a..83d5bc1 100644 --- a/mssql/mssql.vcxproj +++ b/mssql/mssql.vcxproj @@ -102,7 +102,6 @@ - diff --git a/mssql/mssql.vcxproj.filters b/mssql/mssql.vcxproj.filters index f9f39d4..9fb7a80 100644 --- a/mssql/mssql.vcxproj.filters +++ b/mssql/mssql.vcxproj.filters @@ -18,9 +18,6 @@ - - Header Files - Header Files diff --git a/mssql/mssql_datasource.cpp b/mssql/mssql_datasource.cpp index d3e7674..541a900 100644 --- a/mssql/mssql_datasource.cpp +++ b/mssql/mssql_datasource.cpp @@ -892,6 +892,8 @@ box2d mssql_datasource::envelope() const boost::optional mssql_datasource::get_geometry_type() const { + //return boost::optional(); + boost::optional result; CnxPool_ptr pool = ConnectionManager::instance().getPool(creator_.id()); @@ -903,56 +905,7 @@ boost::optional mssql_datasource::get_geometry_t { std::ostringstream s; std::string g_type; - /*try - { - s << "SELECT lower(type) as type FROM " - << GEOMETRY_COLUMNS <<" WHERE f_table_name='" - << mapnik::sql_utils::unquote_double(geometry_table_) - << "'"; - if (! schema_.empty()) - { - s << " AND f_table_schema='" - << mapnik::sql_utils::unquote_double(schema_) - << "'"; - } - if (! geometry_field_.empty()) - { - s << " AND f_geometry_column='" - << mapnik::sql_utils::unquote_double(geometry_field_) - << "'"; - } - shared_ptr rs = conn->executeQuery(s.str()); - if (rs->next()) - { - g_type = rs->getValue("type"); - if (boost::algorithm::contains(g_type, "line")) - { - result.reset(mapnik::datasource::LineString); - return result; - } - else if (boost::algorithm::contains(g_type, "point")) - { - result.reset(mapnik::datasource::Point); - return result; - } - else if (boost::algorithm::contains(g_type, "polygon")) - { - result.reset(mapnik::datasource::Polygon); - return result; - } - else // geometry - { - result.reset(mapnik::datasource::Collection); - return result; - } - } - } - catch (mapnik::datasource_exception const& ex) { - // let this pass on query error and use the fallback below - MAPNIK_LOG_WARN(mssql) << "mssql_datasource: metadata query failed: " << ex.what(); - }*/ - // fallback to querying first several features if (g_type.empty() && !geometryColumn_.empty()) { s.str(""); @@ -975,8 +928,7 @@ boost::optional mssql_datasource::get_geometry_t shared_ptr rs = conn->executeQuery(s.str()); while (rs->next() && !rs->isNull(0)) - { - //const char* data = rs->getValue(0); + { std::string data = rs->getString(0); if (boost::algorithm::contains(data, "line")) diff --git a/mssql/resultset.hpp b/mssql/resultset.hpp index 485910c..9a04d7a 100644 --- a/mssql/resultset.hpp +++ b/mssql/resultset.hpp @@ -67,8 +67,7 @@ class ResultSet : public IResultSet, private mapnik::noncopyable } virtual void close() - { - //PQclear(res_); + { // SQLDisconnect(res_); SQLFreeHandle(SQL_HANDLE_STMT, res_); res_ = 0; @@ -142,6 +141,7 @@ class ResultSet : public IResultSet, private mapnik::noncopyable sizeof(fname), &name_length, 0); + //XXX validation? return std::string(fname); } @@ -157,40 +157,32 @@ class ResultSet : public IResultSet, private mapnik::noncopyable NULL, NULL, &length); + //XXX validation? return length; - //return PQgetlength(res_, pos_, index); + } virtual int getFieldLength(const char* name) const { - throw mapnik::datasource_exception("ResultSet getFieldLength not implemented"); - /*int col = PQfnumber(res_, name); - if (col >= 0) - { - return PQgetlength(res_, pos_, col); - }*/ + throw mapnik::datasource_exception("ResultSet getFieldLength not implemented"); return 0; } virtual int getTypeOID(int index) const { SQLLEN dataType; - SQLColAttribute(res_, index + 1, SQL_DESC_TYPE, NULL, 0, NULL, &dataType); + SQLRETURN retcode; + retcode = SQLColAttribute(res_, index + 1, SQL_DESC_TYPE, NULL, 0, NULL, &dataType); + + //XXX validation? return dataType; - //return PQftype(res_, index); } virtual int getTypeOID(const char* name) const { throw mapnik::datasource_exception("ResultSet getTypeOID(const char* name) not implemented"); - return 0; - /* int col = PQfnumber(res_, name); - if (col >= 0) - { - return PQftype(res_, col); - } - return 0;*/ + return 0; } virtual bool isNull(int index) const @@ -201,6 +193,7 @@ class ResultSet : public IResultSet, private mapnik::noncopyable unsigned char value[1]; retcode = SQLGetData(res_, index + 1, SQL_C_BINARY, value, 0, &length); + //XXX retcode validation? return static_cast(length == SQL_NULL_DATA); } @@ -209,21 +202,28 @@ class ResultSet : public IResultSet, private mapnik::noncopyable virtual const int getInt(int index) const { SQLINTEGER intvalue; - SQLGetData(res_, index + 1, SQL_C_SLONG, &intvalue, 0, NULL); - return intvalue; - // return PQgetvalue(res_, pos_, index); + SQLRETURN retcode; + + retcode = SQLGetData(res_, index + 1, SQL_C_SLONG, &intvalue, 0, NULL); + + //XXX retcode validation? + return intvalue; } virtual const double getDouble(int index) const { double value; - SQLGetData(res_, index + 1, SQL_C_DOUBLE, &value, 0, NULL); + SQLRETURN retcode; + + retcode = SQLGetData(res_, index + 1, SQL_C_DOUBLE, &value, 0, NULL); return value; // return PQgetvalue(res_, pos_, index); } virtual const float getFloat(int index) const { float value; - SQLGetData(res_, index + 1, SQL_C_FLOAT, &value, 0, NULL); + SQLRETURN retcode; + + retcode = SQLGetData(res_, index + 1, SQL_C_FLOAT, &value, 0, NULL); return value; // return PQgetvalue(res_, pos_, index); } @@ -263,10 +263,9 @@ class ResultSet : public IResultSet, private mapnik::noncopyable return mapnik::utf16_to_utf8(str); #else return str; -#endif - - // return PQgetvalue(res_, pos_, index); +#endif } + virtual const std::vector getBinary(int index) const { SQLLEN length = 0; @@ -277,44 +276,14 @@ class ResultSet : public IResultSet, private mapnik::noncopyable retcode = SQLGetData(res_, index + 1, SQL_C_BINARY, bit, 0, &length); if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){ if (length != SQL_NULL_DATA){ - // char* binvalue = new char[length*2]; - + std::vector binvalue(length, 0); retcode = SQLGetData(res_, index + 1, SQL_C_BINARY, (SQLPOINTER)&binvalue[0], length, &length); - - //char* binvalue = new char[80000]; - //retcode = SQLGetData(res_, index + 1, SQL_C_BINARY, binvalue, length, &length); - - - return binvalue; - // return std::vector(binvalue, binvalue + sizeof binvalue / sizeof binvalue[0]); + + return binvalue; } } return std::vector(); - - // return PQgetvalue(res_, pos_, index); - } - virtual const char* getValue4(int index) const - { - throw mapnik::datasource_exception("ResultSet getValue(intindex) not implemented"); - return "novalue"; - // return PQgetvalue(res_, pos_, index); - } - - virtual const char* getValue5(const char* name) const - { - std::string a = "ResultSet getValue([const char* name]"; - a += ((char*)name); - a += ") not implemented"; - throw mapnik::datasource_exception(a.c_str()); - return "novalue"; - /* - int col = PQfnumber(res_, name); - if (col >= 0) - { - return getValue(col); - } - return 0;*/ } private: diff --git a/mssql/targetver.h b/mssql/targetver.h deleted file mode 100644 index 87c0086..0000000 --- a/mssql/targetver.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -// Including SDKDDKVer.h defines the highest available Windows platform. - -// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and -// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. - -#include