diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..e2eac569 --- /dev/null +++ b/.clang-format @@ -0,0 +1,12 @@ +BasedOnStyle: Google +Language: Cpp +TabWidth: 8 +IndentWidth: 2 +UseTab: Never +IndentCaseLabels: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: Never +AccessModifierOffset: -4 +IncludeCategories: + - Regex: '^((<|")(pch.h))' + Priority: -1 diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 7444bf79..63587420 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -7,6 +7,7 @@ RUN sudo apt install -y \ r-base \ ccache \ cmake \ + clang-format \ mariadb-server mariadb-client \ # Install dependencies for devtools package libharfbuzz-dev libfribidi-dev diff --git a/CMakeLists.txt b/CMakeLists.txt index f1aef84c..651379ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,10 @@ # quote(cynkrathis::use_cmakelists()) cmake_minimum_required(VERSION 3.14) + project(RMariaDB VERSION 0.1.0) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") +include(Misc) add_subdirectory(src) diff --git a/cmake/Misc.cmake b/cmake/Misc.cmake new file mode 100644 index 00000000..5665d4c3 --- /dev/null +++ b/cmake/Misc.cmake @@ -0,0 +1,24 @@ +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# clang-format support +function(add_clang_format_target) + set(options) + set(oneValueArgs) + set(multiValueArgs SOURCES) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" + "${multiValueArgs}" ${ARGN}) + if(NOT ${PROJECT_NAME}_CLANG_FORMAT_BINARY) + find_program(${PROJECT_NAME}_CLANG_FORMAT_BINARY clang-format) + endif() + + message(STATUS ${ARG_SOURCES}) + + if(${PROJECT_NAME}_CLANG_FORMAT_BINARY) + add_custom_target(clang-format + COMMAND ${${PROJECT_NAME}_CLANG_FORMAT_BINARY} --verbose + -i ${ARG_SOURCES} + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) + + message(STATUS "Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format).\n") + endif() +endfunction() diff --git a/src/DbConnection.cpp b/src/DbConnection.cpp index efb60641..d6a4202c 100644 --- a/src/DbConnection.cpp +++ b/src/DbConnection.cpp @@ -1,12 +1,11 @@ #include "pch.h" + #include "DbConnection.h" + #include "DbResult.h" -DbConnection::DbConnection() : - pConn_(NULL), - pCurrentResult_(NULL), - transacting_(false) -{ +DbConnection::DbConnection() + : pConn_(NULL), pCurrentResult_(NULL), transacting_(false) { LOG_VERBOSE; } @@ -19,15 +18,16 @@ DbConnection::~DbConnection() { } } -void DbConnection::connect(const Nullable& host, const Nullable& user, - const Nullable& password, const Nullable& db, - unsigned int port, const Nullable& unix_socket, - unsigned long client_flag, const Nullable& groups, - const Nullable& default_file, - const Nullable& ssl_key, const Nullable& ssl_cert, - const Nullable& ssl_ca, const Nullable& ssl_capath, - const Nullable& ssl_cipher, - int timeout, bool reconnect) { +void DbConnection::connect( + const Nullable& host, const Nullable& user, + const Nullable& password, const Nullable& db, + unsigned int port, const Nullable& unix_socket, + unsigned long client_flag, const Nullable& groups, + const Nullable& default_file, + const Nullable& ssl_key, const Nullable& ssl_cert, + const Nullable& ssl_ca, + const Nullable& ssl_capath, + const Nullable& ssl_cipher, int timeout, bool reconnect) { LOG_VERBOSE; this->pConn_ = mysql_init(NULL); @@ -46,33 +46,30 @@ void DbConnection::connect(const Nullable& host, const NullablepConn_, - ssl_key.isNull() ? NULL : as(ssl_key).c_str(), - ssl_cert.isNull() ? NULL : as(ssl_cert).c_str(), - ssl_ca.isNull() ? NULL : as(ssl_ca).c_str(), - ssl_capath.isNull() ? NULL : as(ssl_capath).c_str(), - ssl_cipher.isNull() ? NULL : as(ssl_cipher).c_str() - ); + this->pConn_, + ssl_key.isNull() ? NULL : as(ssl_key).c_str(), + ssl_cert.isNull() ? NULL : as(ssl_cert).c_str(), + ssl_ca.isNull() ? NULL : as(ssl_ca).c_str(), + ssl_capath.isNull() ? NULL : as(ssl_capath).c_str(), + ssl_cipher.isNull() ? NULL : as(ssl_cipher).c_str()); } if (timeout > 0) { - mysql_options(this->pConn_, MYSQL_OPT_CONNECT_TIMEOUT, - &timeout); + mysql_options(this->pConn_, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); } if (reconnect) { my_bool reconnect_ = 1; - mysql_options(this->pConn_, MYSQL_OPT_RECONNECT, (void *)&reconnect_); + mysql_options(this->pConn_, MYSQL_OPT_RECONNECT, (void*)&reconnect_); } LOG_VERBOSE; - if (!mysql_real_connect(this->pConn_, - host.isNull() ? NULL : as(host).c_str(), - user.isNull() ? NULL : as(user).c_str(), - password.isNull() ? NULL : as(password).c_str(), - db.isNull() ? NULL : as(db).c_str(), - port, - unix_socket.isNull() ? NULL : as(unix_socket).c_str(), - client_flag)) { + if (!mysql_real_connect( + this->pConn_, host.isNull() ? NULL : as(host).c_str(), + user.isNull() ? NULL : as(user).c_str(), + password.isNull() ? NULL : as(password).c_str(), + db.isNull() ? NULL : as(db).c_str(), port, + unix_socket.isNull() ? NULL : as(unix_socket).c_str(), + client_flag)) { std::string error = mysql_error(this->pConn_); mysql_close(this->pConn_); this->pConn_ = NULL; @@ -82,19 +79,18 @@ void DbConnection::connect(const Nullable& host, const Nullablehost), _["username"] = std::string(pConn_->user), _["dbname"] = std::string(pConn_->db ? pConn_->db : ""), _["con.type"] = std::string(mysql_get_host_info(pConn_)), _["db.version"] = std::string(mysql_get_server_info(pConn_)), _["port"] = NA_INTEGER, - _["protocol.version"] = (int) mysql_get_proto_info(pConn_), - _["thread.id"] = (int) mysql_thread_id(pConn_) - ); + _["protocol.version"] = (int)mysql_get_proto_info(pConn_), + _["thread.id"] = (int)mysql_thread_id(pConn_)); } MYSQL* DbConnection::get_conn() { @@ -138,7 +132,8 @@ SEXP DbConnection::quote_string(const String& input) { std::string output = "'"; output.resize(input_len * 2 + 3); - size_t end = mysql_real_escape_string(pConn_, &output[1], input_cstr, input_len); + size_t end = + mysql_real_escape_string(pConn_, &output[1], input_cstr, input_len); output.resize(end + 1); output.append("'"); @@ -196,14 +191,16 @@ bool DbConnection::exec(const std::string& sql) { } void DbConnection::begin_transaction() { - if (is_transacting()) stop("Nested transactions not supported."); + if (is_transacting()) + stop("Nested transactions not supported."); check_connection(); transacting_ = true; } void DbConnection::commit() { - if (!is_transacting()) stop("Call dbBegin() to start a transaction."); + if (!is_transacting()) + stop("Call dbBegin() to start a transaction."); check_connection(); mysql_commit(get_conn()); @@ -211,7 +208,8 @@ void DbConnection::commit() { } void DbConnection::rollback() { - if (!is_transacting()) stop("Call dbBegin() to start a transaction."); + if (!is_transacting()) + stop("Call dbBegin() to start a transaction."); check_connection(); mysql_rollback(get_conn()); diff --git a/src/DbConnection.h b/src/DbConnection.h index 67558aef..c166a857 100644 --- a/src/DbConnection.h +++ b/src/DbConnection.h @@ -15,20 +15,24 @@ class DbConnection : boost::noncopyable { DbResult* pCurrentResult_; bool transacting_; -public: - + public: DbConnection(); ~DbConnection(); -public: - void - connect(const Nullable& host, const Nullable& user, const Nullable& password, - const Nullable& db, unsigned int port, const Nullable& unix_socket, - unsigned long client_flag, const Nullable& groups, const Nullable& default_file, - const Nullable& ssl_key, const Nullable& ssl_cert, - const Nullable& ssl_ca, const Nullable& ssl_capath, - const Nullable& ssl_cipher, - int timeout, bool reconnect); + public: + void connect(const Nullable& host, + const Nullable& user, + const Nullable& password, + const Nullable& db, unsigned int port, + const Nullable& unix_socket, + unsigned long client_flag, const Nullable& groups, + const Nullable& default_file, + const Nullable& ssl_key, + const Nullable& ssl_cert, + const Nullable& ssl_ca, + const Nullable& ssl_capath, + const Nullable& ssl_cipher, int timeout, + bool reconnect); void disconnect(); bool is_valid(); void check_connection(); diff --git a/src/DbResult.cpp b/src/DbResult.cpp index b6a376fe..b425a314 100644 --- a/src/DbResult.cpp +++ b/src/DbResult.cpp @@ -1,15 +1,13 @@ #include "pch.h" + #include "DbResult.h" + #include "DbConnection.h" #include "DbResultImpl.h" - - // Construction //////////////////////////////////////////////////////////////// -DbResult::DbResult(const DbConnectionPtr& pConn) : - pConn_(pConn) -{ +DbResult::DbResult(const DbConnectionPtr& pConn) : pConn_(pConn) { pConn_->check_connection(); // subclass constructor can throw, the destructor will remove the @@ -22,10 +20,10 @@ DbResult::~DbResult() { if (is_active()) { pConn_->reset_current_result(this); } - } catch (...) {} + } catch (...) { + } } - // Publics ///////////////////////////////////////////////////////////////////// bool DbResult::complete() const { @@ -67,7 +65,8 @@ List DbResult::get_column_info() { void DbResult::close() { // Called from destructor - if (impl) impl->close(); + if (impl) + impl->close(); } // Privates /////////////////////////////////////////////////////////////////// diff --git a/src/DbResult.h b/src/DbResult.h index f6d63717..625e54e7 100644 --- a/src/DbResult.h +++ b/src/DbResult.h @@ -2,12 +2,11 @@ #define __RDBI_DB_RESULT__ #include -#include #include +#include #include "DbResultImplDecl.h" - class DbConnection; typedef boost::shared_ptr DbConnectionPtr; @@ -16,16 +15,16 @@ typedef boost::shared_ptr DbConnectionPtr; class DbResult : boost::noncopyable { DbConnectionPtr pConn_; -protected: + protected: boost::scoped_ptr impl; -protected: + protected: DbResult(const DbConnectionPtr& pConn); -public: + public: ~DbResult(); -public: + public: void close(); bool complete() const; @@ -38,8 +37,8 @@ class DbResult : boost::noncopyable { List get_column_info(); -private: + private: void validate_params(const List& params) const; }; -#endif // __RDBI_DB_RESULT__ +#endif // __RDBI_DB_RESULT__ diff --git a/src/MariaBinding.cpp b/src/MariaBinding.cpp index 63ffc93d..31a805cb 100644 --- a/src/MariaBinding.cpp +++ b/src/MariaBinding.cpp @@ -1,13 +1,12 @@ #include "pch.h" -#include + #include "MariaBinding.h" + +#include + #include "integer64.h" -MariaBinding::MariaBinding() : - statement(NULL), - p(0), - i(0), - n_rows(0) { +MariaBinding::MariaBinding() : statement(NULL), p(0), i(0), n_rows(0) { } MariaBinding::~MariaBinding() { @@ -86,7 +85,8 @@ void MariaBinding::init_binding(const List& params_) { bool MariaBinding::bind_next_row() { LOG_VERBOSE; - if (i >= n_rows) return false; + if (i >= n_rows) + return false; for (int j = 0; j < p; ++j) { LOG_VERBOSE << j << " -> " << type_name(types[j]); @@ -126,17 +126,16 @@ bool MariaBinding::bind_next_row() { bindings[j].buffer_length = Rf_length(string); } break; - case MY_RAW: - { - SEXP raw = VECTOR_ELT(col, i); - if (Rf_isNull(raw)) { - missing = true; - } else { - bindings[j].buffer_length = Rf_length(raw); - bindings[j].buffer = RAW(raw); - } - break; + case MY_RAW: { + SEXP raw = VECTOR_ELT(col, i); + if (Rf_isNull(raw)) { + missing = true; + } else { + bindings[j].buffer_length = Rf_length(raw); + bindings[j].buffer = RAW(raw); } + break; + } case MY_DATE: case MY_DATE_TIME: if (ISNAN(REAL(col)[i])) { @@ -209,15 +208,17 @@ void MariaBinding::set_date_buffer(int j, const int date) { // https://howardhinnant.github.io/date_algorithms.html#civil_from_days const int date_0 = date + 719468; const int era = (date_0 >= 0 ? date_0 : date_0 - 146096) / 146097; - const unsigned doe = static_cast(date_0 - era * 146097); // [0, 146096] + const unsigned doe = + static_cast(date_0 - era * 146097); // [0, 146096] LOG_VERBOSE << doe; - const unsigned yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365; // [0, 399] + const unsigned yoe = + (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; // [0, 399] LOG_VERBOSE << yoe; const int y = static_cast(yoe) + era * 400; - const unsigned doy = doe - (365*yoe + yoe/4 - yoe/100); // [0, 365] - const unsigned mp = (5*doy + 2)/153; // [0, 11] - const unsigned d = doy - (153*mp+2)/5 + 1; // [1, 31] - const unsigned m = mp < 10 ? mp+3 : mp-9; // [1, 12] + const unsigned doy = doe - (365 * yoe + yoe / 4 - yoe / 100); // [0, 365] + const unsigned mp = (5 * doy + 2) / 153; // [0, 11] + const unsigned d = doy - (153 * mp + 2) / 5 + 1; // [1, 31] + const unsigned m = mp < 10 ? mp + 3 : mp - 9; // [1, 12] const unsigned yr = y + (m <= 2); // gmtime() fails for dates < 1970 on Windows @@ -258,6 +259,7 @@ void MariaBinding::set_time_buffer(int j, double time) { time_buffers[j].hour = static_cast(hours); time_buffers[j].minute = static_cast(minutes); time_buffers[j].second = static_cast(seconds); - time_buffers[j].second_part = static_cast(frac_seconds * 1000000.0); + time_buffers[j].second_part = + static_cast(frac_seconds * 1000000.0); time_buffers[j].neg = neg; } diff --git a/src/MariaBinding.h b/src/MariaBinding.h index fb9bc8c7..b1322bc1 100644 --- a/src/MariaBinding.h +++ b/src/MariaBinding.h @@ -3,6 +3,7 @@ #include #include + #include "MariaTypes.h" class MariaBinding : public boost::noncopyable { @@ -16,17 +17,17 @@ class MariaBinding : public boost::noncopyable { std::vector types; std::vector time_buffers; -public: + public: MariaBinding(); ~MariaBinding(); -public: + public: void setup(MYSQL_STMT* statement_); void init_binding(const List& params); bool bind_next_row(); -private: + private: void binding_update(int j, enum_field_types type, int size); void clear_date_buffer(int j); diff --git a/src/MariaResult.cpp b/src/MariaResult.cpp index 64e8d0fa..017036b5 100644 --- a/src/MariaResult.cpp +++ b/src/MariaResult.cpp @@ -1,21 +1,23 @@ #include "pch.h" + #include "MariaResult.h" + #include "MariaResultPrep.h" #include "MariaResultSimple.h" - // Construction //////////////////////////////////////////////////////////////// -MariaResult::MariaResult(const DbConnectionPtr& pConn, const std::string& sql, bool is_statement) : - DbResult(pConn) -{ - boost::scoped_ptr res(new MariaResultPrep(pConn, is_statement)); +MariaResult::MariaResult(const DbConnectionPtr& pConn, const std::string& sql, + bool is_statement) + : DbResult(pConn) { + boost::scoped_ptr res( + new MariaResultPrep(pConn, is_statement)); try { res->send_query(sql); - } - catch (const MariaResultPrep::UnsupportedPS& e) { + } catch (const MariaResultPrep::UnsupportedPS& e) { res.reset(NULL); - // is_statement info might be worthwhile to pass to simple queries as well + // is_statement info might be worthwhile to pass to simple queries as + // well res.reset(new MariaResultSimple(pConn, is_statement)); res->send_query(sql); } @@ -23,7 +25,9 @@ MariaResult::MariaResult(const DbConnectionPtr& pConn, const std::string& sql, b res.swap(impl); } -DbResult* MariaResult::create_and_send_query(const DbConnectionPtr& con, const std::string& sql, bool is_statement) { +DbResult* MariaResult::create_and_send_query(const DbConnectionPtr& con, + const std::string& sql, + bool is_statement) { return new MariaResult(con, sql, is_statement); } diff --git a/src/MariaResult.h b/src/MariaResult.h index ad24d73e..1586aa66 100644 --- a/src/MariaResult.h +++ b/src/MariaResult.h @@ -3,18 +3,20 @@ #include "DbResult.h" - // MariaResult ----------------------------------------------------------------- class MariaResult : public DbResult { -protected: - MariaResult(const DbConnectionPtr& pConn, const std::string& sql, bool is_statement); + protected: + MariaResult(const DbConnectionPtr& pConn, const std::string& sql, + bool is_statement); -public: - static DbResult* create_and_send_query(const DbConnectionPtr& con, const std::string& sql, bool is_statement); + public: + static DbResult* create_and_send_query(const DbConnectionPtr& con, + const std::string& sql, + bool is_statement); -public: + public: void close(); }; -#endif // __RMARIADB_MARIA_RESULT__ +#endif // __RMARIADB_MARIA_RESULT__ diff --git a/src/MariaResultImpl.cpp b/src/MariaResultImpl.cpp index e260880f..92fea7c1 100644 --- a/src/MariaResultImpl.cpp +++ b/src/MariaResultImpl.cpp @@ -1,4 +1,5 @@ #include "pch.h" + #include "MariaResultImpl.h" MariaResultImpl::MariaResultImpl() { diff --git a/src/MariaResultImpl.h b/src/MariaResultImpl.h index 58120d26..7e592174 100644 --- a/src/MariaResultImpl.h +++ b/src/MariaResultImpl.h @@ -2,11 +2,11 @@ #define RMARIADB_MARIARESULTIMPL_H class MariaResultImpl { -public: + public: MariaResultImpl(); virtual ~MariaResultImpl(); -public: + public: virtual void send_query(const std::string& sql) = 0; virtual void close() = 0; @@ -21,4 +21,4 @@ class MariaResultImpl { virtual bool complete() const = 0; }; -#endif //RMARIADB_MARIARESULTIMPL_H +#endif // RMARIADB_MARIARESULTIMPL_H diff --git a/src/MariaResultPrep.cpp b/src/MariaResultPrep.cpp index 3bc63cdd..27d23310 100644 --- a/src/MariaResultPrep.cpp +++ b/src/MariaResultPrep.cpp @@ -1,22 +1,24 @@ #include "pch.h" #include "MariaResultPrep.h" -#include "DbConnection.h" + #include + +#include "DbConnection.h" #include "MariaResult.h" -MariaResultPrep::MariaResultPrep(const DbConnectionPtr& pConn, bool is_statement) : - pConn_(pConn), - pStatement_(NULL), - pSpec_(NULL), - rowsAffected_(0), - rowsFetched_(0), - nCols_(0), - nParams_(0), - bound_(false), - complete_(false), - is_statement_(is_statement) -{ +MariaResultPrep::MariaResultPrep(const DbConnectionPtr& pConn, + bool is_statement) + : pConn_(pConn), + pStatement_(NULL), + pSpec_(NULL), + rowsAffected_(0), + rowsFetched_(0), + nCols_(0), + nParams_(0), + bound_(false), + complete_(false), + is_statement_(is_statement) { pStatement_ = mysql_stmt_init(pConn_->get_conn()); if (pStatement_ == NULL) stop("Out of memory"); @@ -101,8 +103,7 @@ void MariaResultPrep::bind(const List& params) { if (has_result()) { complete_ = true; - } - else { + } else { while (bindingInput_.bind_next_row()) { execute(); } @@ -131,7 +132,8 @@ bool MariaResultPrep::step() { while (!fetch_row()) { LOG_VERBOSE; - if (!bindingInput_.bind_next_row()) return false; + if (!bindingInput_.bind_next_row()) + return false; execute(); } @@ -144,7 +146,8 @@ bool MariaResultPrep::step() { bool MariaResultPrep::fetch_row() { LOG_VERBOSE; - if (complete_) return false; + if (complete_) + return false; LOG_VERBOSE << "mysql_stmt_fetch()"; int result = mysql_stmt_fetch(pStatement_); @@ -170,7 +173,10 @@ List MariaResultPrep::fetch(int n_max) { stop("Query needs to be bound before fetching"); if (!has_result()) { if (names_.size() == 0) { - warning("Use dbExecute() instead of dbGetQuery() for statements, and also avoid dbFetch()"); + warning( + "Use dbExecute() instead of dbGetQuery() for statements, and " + "also " + "avoid dbFetch()"); } return df_create(types_, names_, 0); } @@ -183,7 +189,8 @@ List MariaResultPrep::fetch(int n_max) { int i = 0; for (;;) { - if (i >= n && n_max > 0) break; + if (i >= n && n_max > 0) + break; if (!step()) break; @@ -214,30 +221,28 @@ List MariaResultPrep::fetch(int n_max) { } int MariaResultPrep::n_rows_affected() { - if (!bound_) return NA_INTEGER; + if (!bound_) + return NA_INTEGER; // FIXME: > 2^32 rows? return static_cast(rowsAffected_); } int MariaResultPrep::n_rows_fetched() { - if (!bound_) return 0; + if (!bound_) + return 0; // FIXME: > 2^32 rows? return static_cast(rowsFetched_); } bool MariaResultPrep::complete() const { - if (!bound_) return FALSE; - return - !has_result() || // query doesn't have results - complete_; // we've fetched all available results + if (!bound_) + return FALSE; + return !has_result() || // query doesn't have results + complete_; // we've fetched all available results } void MariaResultPrep::throw_error() { - stop( - "%s [%i]", - mysql_stmt_error(pStatement_), - mysql_stmt_errno(pStatement_) - ); + stop("%s [%i]", mysql_stmt_error(pStatement_), mysql_stmt_errno(pStatement_)); } void MariaResultPrep::cache_metadata() { @@ -251,9 +256,11 @@ void MariaResultPrep::cache_metadata() { bool binary = fields[i].charsetnr == 63; bool length1 = fields[i].length == 1; - MariaFieldType type = variable_type_from_field_type(fields[i].type, binary, length1); + MariaFieldType type = + variable_type_from_field_type(fields[i].type, binary, length1); types_.push_back(type); - LOG_VERBOSE << i << " -> " << fields[i].name << "(" << fields[i].type << ", " << binary << ") => " << type_name(type); + LOG_VERBOSE << i << " -> " << fields[i].name << "(" << fields[i].type + << ", " << binary << ") => " << type_name(type); } } diff --git a/src/MariaResultPrep.h b/src/MariaResultPrep.h index d696c239..c1fe8cb3 100644 --- a/src/MariaResultPrep.h +++ b/src/MariaResultPrep.h @@ -29,11 +29,11 @@ class MariaResultPrep : boost::noncopyable, public MariaResultImpl { MariaBinding bindingInput_; MariaRow bindingOutput_; -public: + public: MariaResultPrep(const DbConnectionPtr& pConn, bool is_statement = false); ~MariaResultPrep(); -public: + public: virtual void send_query(const std::string& sql); virtual void close(); @@ -47,10 +47,10 @@ class MariaResultPrep : boost::noncopyable, public MariaResultImpl { virtual int n_rows_fetched(); virtual bool complete() const; -public: + public: class UnsupportedPS : public std::exception {}; -private: + private: void execute(); bool has_result() const; @@ -58,7 +58,7 @@ class MariaResultPrep : boost::noncopyable, public MariaResultImpl { bool fetch_row(); void NORET throw_error(); -private: + private: void cache_metadata(); }; diff --git a/src/MariaResultSimple.cpp b/src/MariaResultSimple.cpp index 748a4339..dd13333e 100644 --- a/src/MariaResultSimple.cpp +++ b/src/MariaResultSimple.cpp @@ -1,11 +1,12 @@ #include "pch.h" #include "MariaResultSimple.h" + #include "DbConnection.h" -MariaResultSimple::MariaResultSimple(const DbConnectionPtr& pConn, bool is_statement) : - pConn_(pConn) -{ +MariaResultSimple::MariaResultSimple(const DbConnectionPtr& pConn, + bool is_statement) + : pConn_(pConn) { (void)is_statement; } @@ -26,7 +27,9 @@ void MariaResultSimple::close() { void MariaResultSimple::bind(const List& /*params*/) { LOG_VERBOSE; - stop("This query is not supported by the prepared statement protocol, no parameters can be bound."); + stop( + "This query is not supported by the prepared statement protocol, no " + "parameters can be bound."); } List MariaResultSimple::get_column_info() { @@ -38,8 +41,12 @@ List MariaResultSimple::get_column_info() { List MariaResultSimple::fetch(int /*n_max*/) { LOG_VERBOSE; - warning("Use dbExecute() instead of dbGetQuery() for statements, and also avoid dbFetch()"); - return df_create(std::vector(), std::vector(), 0); + warning( + "Use dbExecute() instead of dbGetQuery() for statements, and also " + "avoid " + "dbFetch()"); + return df_create(std::vector(), std::vector(), + 0); } int MariaResultSimple::n_rows_affected() { diff --git a/src/MariaResultSimple.h b/src/MariaResultSimple.h index e586e069..242cfe69 100644 --- a/src/MariaResultSimple.h +++ b/src/MariaResultSimple.h @@ -2,8 +2,9 @@ #define __RMARIADB_MARIA_RESULT_SIMPLE__ #include -#include "MariaBinding.h" + #include "DbResult.h" +#include "MariaBinding.h" #include "MariaResultImpl.h" #include "MariaRow.h" #include "MariaTypes.h" @@ -15,11 +16,11 @@ typedef boost::shared_ptr DbConnectionPtr; class MariaResultSimple : boost::noncopyable, public MariaResultImpl { DbConnectionPtr pConn_; -public: + public: MariaResultSimple(const DbConnectionPtr& pConn, bool is_statement); ~MariaResultSimple(); -public: + public: virtual void send_query(const std::string& sql); virtual void close(); @@ -33,7 +34,7 @@ class MariaResultSimple : boost::noncopyable, public MariaResultImpl { virtual int n_rows_fetched(); virtual bool complete() const; -private: + private: void exec(const std::string& sql); }; diff --git a/src/MariaRow.cpp b/src/MariaRow.cpp index fa9301a3..e5944b90 100644 --- a/src/MariaRow.cpp +++ b/src/MariaRow.cpp @@ -1,21 +1,19 @@ #include "pch.h" #include "MariaRow.h" + #include "MariaTypes.h" #include "MariaUtils.h" #include "integer64.h" - -MariaRow::MariaRow() : - pStatement_(NULL), - n_(0) -{ +MariaRow::MariaRow() : pStatement_(NULL), n_(0) { } MariaRow::~MariaRow() { } -void MariaRow::setup(MYSQL_STMT* pStatement, const std::vector& types) { +void MariaRow::setup(MYSQL_STMT* pStatement, + const std::vector& types) { LOG_VERBOSE; pStatement_ = pStatement; @@ -123,15 +121,15 @@ int MariaRow::value_bool(int j) { } int MariaRow::value_int(int j) { - return is_null(j) ? NA_INTEGER : *((int*) &buffers_[j][0]); + return is_null(j) ? NA_INTEGER : *((int*)&buffers_[j][0]); } int64_t MariaRow::value_int64(int j) { - return is_null(j) ? NA_INTEGER64 : *((int64_t*) &buffers_[j][0]); + return is_null(j) ? NA_INTEGER64 : *((int64_t*)&buffers_[j][0]); } double MariaRow::value_double(int j) { - return is_null(j) ? NA_REAL : *((double*) &buffers_[j][0]); + return is_null(j) ? NA_REAL : *((double*)&buffers_[j][0]); } SEXP MariaRow::value_string(int j) { @@ -162,15 +160,14 @@ double MariaRow::value_date_time(int j) { if (is_null(j)) return NA_REAL; - MYSQL_TIME* mytime = (MYSQL_TIME*) &buffers_[j][0]; + MYSQL_TIME* mytime = (MYSQL_TIME*)&buffers_[j][0]; const int days = days_from_civil(mytime->year, mytime->month, mytime->day); - double date_time = - static_cast(days) * 86400.0 + - static_cast(mytime->hour) * (60.0 * 60) + - static_cast(mytime->minute) * 60.0 + - static_cast(mytime->second) + - static_cast(mytime->second_part) / 1000000.0; + double date_time = static_cast(days) * 86400.0 + + static_cast(mytime->hour) * (60.0 * 60) + + static_cast(mytime->minute) * 60.0 + + static_cast(mytime->second) + + static_cast(mytime->second_part) / 1000000.0; LOG_VERBOSE << date_time; return date_time; } @@ -179,7 +176,7 @@ double MariaRow::value_date(int j) { if (is_null(j)) return NA_REAL; - MYSQL_TIME* mytime = (MYSQL_TIME*) &buffers_[j][0]; + MYSQL_TIME* mytime = (MYSQL_TIME*)&buffers_[j][0]; const int days = days_from_civil(mytime->year, mytime->month, mytime->day); double date_time = static_cast(days); @@ -191,7 +188,7 @@ double MariaRow::value_time(int j) { if (is_null(j)) return NA_REAL; - MYSQL_TIME* mytime = (MYSQL_TIME*) &buffers_[j][0]; + MYSQL_TIME* mytime = (MYSQL_TIME*)&buffers_[j][0]; return static_cast(mytime->hour) * 3600.0 + static_cast(mytime->minute) * 60.0 + static_cast(mytime->second) + @@ -238,7 +235,7 @@ void MariaRow::fetch_buffer(int j) { if (length == 0) return; - bindings_[j].buffer = &buffers_[j][0]; // might have moved + bindings_[j].buffer = &buffers_[j][0]; // might have moved bindings_[j].buffer_length = length; LOG_VERBOSE << bindings_[j].buffer_length; diff --git a/src/MariaRow.h b/src/MariaRow.h index 476ed4d5..45efd3b5 100644 --- a/src/MariaRow.h +++ b/src/MariaRow.h @@ -1,8 +1,8 @@ #ifndef __RMARIADB_MARIA_ROW__ #define __RMARIADB_MARIA_ROW__ -#include #include +#include #include #include "MariaTypes.h" @@ -18,16 +18,17 @@ class MariaRow : public boost::noncopyable { std::vector lengths_; boost::container::vector nulls_, errors_; -public: + public: MariaRow(); ~MariaRow(); -public: + public: void setup(MYSQL_STMT* pStatement, const std::vector& types); void set_list_value(SEXP x, int i, int j); -private: - // Value accessors ----------------------------------------------------------- + private: + // Value accessors + // ----------------------------------------------------------- bool is_null(int j); int value_int(int j); diff --git a/src/MariaTypes.cpp b/src/MariaTypes.cpp index dd0df652..37c37162 100644 --- a/src/MariaTypes.cpp +++ b/src/MariaTypes.cpp @@ -1,10 +1,13 @@ #include "pch.h" + #include "MariaTypes.h" + #include "integer64.h" bool all_raw(SEXP x); -MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, bool length1) { +MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, + bool length1) { switch (type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: @@ -122,16 +125,22 @@ MariaFieldType variable_type_from_object(const RObject& type) { case INTSXP: return MY_INT32; case REALSXP: - if (klass == "Date") return MY_DATE; - if (klass == "POSIXt") return MY_DATE_TIME; - if (klass == "difftime") return MY_TIME; - if (klass == "integer64") return MY_INT64; + if (klass == "Date") + return MY_DATE; + if (klass == "POSIXt") + return MY_DATE_TIME; + if (klass == "difftime") + return MY_TIME; + if (klass == "integer64") + return MY_INT64; return MY_DBL; case STRSXP: return MY_STR; case VECSXP: - if (klass == "blob") return MY_RAW; - if (all_raw(type)) return MY_RAW; + if (klass == "blob") + return MY_RAW; + if (all_raw(type)) + return MY_RAW; break; } diff --git a/src/MariaTypes.h b/src/MariaTypes.h index c1b8d5a1..df681f7f 100644 --- a/src/MariaTypes.h +++ b/src/MariaTypes.h @@ -3,22 +3,22 @@ enum MariaFieldType { MY_INT32, - MY_INT64, // output only + MY_INT64, // output only MY_DBL, MY_STR, MY_DATE, MY_DATE_TIME, MY_TIME, MY_RAW, - MY_LGL // for BIT(1) + MY_LGL // for BIT(1) }; -MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, bool length1); +MariaFieldType variable_type_from_field_type(enum_field_types type, bool binary, + bool length1); std::string type_name(MariaFieldType type); SEXPTYPE type_sexp(MariaFieldType type); std::string r_class(RObject x); MariaFieldType variable_type_from_object(const RObject& type); - #endif diff --git a/src/RMariaDB_types.h b/src/RMariaDB_types.h index 5ab1665a..449f80be 100644 --- a/src/RMariaDB_types.h +++ b/src/RMariaDB_types.h @@ -9,12 +9,12 @@ namespace Rcpp { -template<> +template <> DbConnection* as(SEXP x); -template<> +template <> DbResult* as(SEXP x); -} +} // namespace Rcpp #endif diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index c12a410d..d772fcae 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -1,294 +1,333 @@ // Generated by using Rcpp::compileAttributes() -> do not edit by hand // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 -#include "RMariaDB_types.h" #include +#include "RMariaDB_types.h" + using namespace Rcpp; #ifdef RCPP_USE_GLOBAL_ROSTREAM -Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif // connection_create -XPtr connection_create(const Nullable& host, const Nullable& user, const Nullable& password, const Nullable& db, unsigned int port, const Nullable& unix_socket, unsigned long client_flag, const Nullable& groups, const Nullable& default_file, const Nullable& ssl_key, const Nullable& ssl_cert, const Nullable& ssl_ca, const Nullable& ssl_capath, const Nullable& ssl_cipher, int timeout, bool reconnect); -RcppExport SEXP _RMariaDB_connection_create(SEXP hostSEXP, SEXP userSEXP, SEXP passwordSEXP, SEXP dbSEXP, SEXP portSEXP, SEXP unix_socketSEXP, SEXP client_flagSEXP, SEXP groupsSEXP, SEXP default_fileSEXP, SEXP ssl_keySEXP, SEXP ssl_certSEXP, SEXP ssl_caSEXP, SEXP ssl_capathSEXP, SEXP ssl_cipherSEXP, SEXP timeoutSEXP, SEXP reconnectSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Nullable& >::type host(hostSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type user(userSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type password(passwordSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type db(dbSEXP); - Rcpp::traits::input_parameter< unsigned int >::type port(portSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type unix_socket(unix_socketSEXP); - Rcpp::traits::input_parameter< unsigned long >::type client_flag(client_flagSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type groups(groupsSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type default_file(default_fileSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type ssl_key(ssl_keySEXP); - Rcpp::traits::input_parameter< const Nullable& >::type ssl_cert(ssl_certSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type ssl_ca(ssl_caSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type ssl_capath(ssl_capathSEXP); - Rcpp::traits::input_parameter< const Nullable& >::type ssl_cipher(ssl_cipherSEXP); - Rcpp::traits::input_parameter< int >::type timeout(timeoutSEXP); - Rcpp::traits::input_parameter< bool >::type reconnect(reconnectSEXP); - rcpp_result_gen = Rcpp::wrap(connection_create(host, user, password, db, port, unix_socket, client_flag, groups, default_file, ssl_key, ssl_cert, ssl_ca, ssl_capath, ssl_cipher, timeout, reconnect)); - return rcpp_result_gen; -END_RCPP +XPtr connection_create( + const Nullable& host, const Nullable& user, + const Nullable& password, const Nullable& db, + unsigned int port, const Nullable& unix_socket, + unsigned long client_flag, const Nullable& groups, + const Nullable& default_file, + const Nullable& ssl_key, const Nullable& ssl_cert, + const Nullable& ssl_ca, + const Nullable& ssl_capath, + const Nullable& ssl_cipher, int timeout, bool reconnect); +RcppExport SEXP _RMariaDB_connection_create( + SEXP hostSEXP, SEXP userSEXP, SEXP passwordSEXP, SEXP dbSEXP, SEXP portSEXP, + SEXP unix_socketSEXP, SEXP client_flagSEXP, SEXP groupsSEXP, + SEXP default_fileSEXP, SEXP ssl_keySEXP, SEXP ssl_certSEXP, SEXP ssl_caSEXP, + SEXP ssl_capathSEXP, SEXP ssl_cipherSEXP, SEXP timeoutSEXP, + SEXP reconnectSEXP) { + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter&>::type host( + hostSEXP); + Rcpp::traits::input_parameter&>::type user( + userSEXP); + Rcpp::traits::input_parameter&>::type password( + passwordSEXP); + Rcpp::traits::input_parameter&>::type db(dbSEXP); + Rcpp::traits::input_parameter::type port(portSEXP); + Rcpp::traits::input_parameter&>::type unix_socket( + unix_socketSEXP); + Rcpp::traits::input_parameter::type client_flag( + client_flagSEXP); + Rcpp::traits::input_parameter&>::type groups( + groupsSEXP); + Rcpp::traits::input_parameter&>::type + default_file(default_fileSEXP); + Rcpp::traits::input_parameter&>::type ssl_key( + ssl_keySEXP); + Rcpp::traits::input_parameter&>::type ssl_cert( + ssl_certSEXP); + Rcpp::traits::input_parameter&>::type ssl_ca( + ssl_caSEXP); + Rcpp::traits::input_parameter&>::type ssl_capath( + ssl_capathSEXP); + Rcpp::traits::input_parameter&>::type ssl_cipher( + ssl_cipherSEXP); + Rcpp::traits::input_parameter::type timeout(timeoutSEXP); + Rcpp::traits::input_parameter::type reconnect(reconnectSEXP); + rcpp_result_gen = Rcpp::wrap( + connection_create(host, user, password, db, port, unix_socket, + client_flag, groups, default_file, ssl_key, ssl_cert, + ssl_ca, ssl_capath, ssl_cipher, timeout, reconnect)); + return rcpp_result_gen; + END_RCPP } // connection_valid bool connection_valid(XPtr con_); RcppExport SEXP _RMariaDB_connection_valid(SEXP con_SEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< XPtr >::type con_(con_SEXP); - rcpp_result_gen = Rcpp::wrap(connection_valid(con_)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter >::type con_(con_SEXP); + rcpp_result_gen = Rcpp::wrap(connection_valid(con_)); + return rcpp_result_gen; + END_RCPP } // connection_release void connection_release(XPtr con_); RcppExport SEXP _RMariaDB_connection_release(SEXP con_SEXP) { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< XPtr >::type con_(con_SEXP); - connection_release(con_); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter >::type con_(con_SEXP); + connection_release(con_); + return R_NilValue; + END_RCPP } // connection_info List connection_info(DbConnection* con); RcppExport SEXP _RMariaDB_connection_info(SEXP conSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbConnection* >::type con(conSEXP); - rcpp_result_gen = Rcpp::wrap(connection_info(con)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type con(conSEXP); + rcpp_result_gen = Rcpp::wrap(connection_info(con)); + return rcpp_result_gen; + END_RCPP } // connection_quote_string CharacterVector connection_quote_string(DbConnection* con, CharacterVector xs); RcppExport SEXP _RMariaDB_connection_quote_string(SEXP conSEXP, SEXP xsSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbConnection* >::type con(conSEXP); - Rcpp::traits::input_parameter< CharacterVector >::type xs(xsSEXP); - rcpp_result_gen = Rcpp::wrap(connection_quote_string(con, xs)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type con(conSEXP); + Rcpp::traits::input_parameter::type xs(xsSEXP); + rcpp_result_gen = Rcpp::wrap(connection_quote_string(con, xs)); + return rcpp_result_gen; + END_RCPP } // connection_begin_transaction void connection_begin_transaction(XPtr con); RcppExport SEXP _RMariaDB_connection_begin_transaction(SEXP conSEXP) { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< XPtr >::type con(conSEXP); - connection_begin_transaction(con); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter >::type con(conSEXP); + connection_begin_transaction(con); + return R_NilValue; + END_RCPP } // connection_commit void connection_commit(XPtr con); RcppExport SEXP _RMariaDB_connection_commit(SEXP conSEXP) { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< XPtr >::type con(conSEXP); - connection_commit(con); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter >::type con(conSEXP); + connection_commit(con); + return R_NilValue; + END_RCPP } // connection_rollback void connection_rollback(XPtr con); RcppExport SEXP _RMariaDB_connection_rollback(SEXP conSEXP) { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< XPtr >::type con(conSEXP); - connection_rollback(con); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter >::type con(conSEXP); + connection_rollback(con); + return R_NilValue; + END_RCPP } // connection_is_transacting bool connection_is_transacting(DbConnection* con); RcppExport SEXP _RMariaDB_connection_is_transacting(SEXP conSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbConnection* >::type con(conSEXP); - rcpp_result_gen = Rcpp::wrap(connection_is_transacting(con)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type con(conSEXP); + rcpp_result_gen = Rcpp::wrap(connection_is_transacting(con)); + return rcpp_result_gen; + END_RCPP } // driver_init void driver_init(); RcppExport SEXP _RMariaDB_driver_init() { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - driver_init(); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + driver_init(); + return R_NilValue; + END_RCPP } // driver_done void driver_done(); RcppExport SEXP _RMariaDB_driver_done() { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - driver_done(); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + driver_done(); + return R_NilValue; + END_RCPP } // version IntegerVector version(); RcppExport SEXP _RMariaDB_version() { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = Rcpp::wrap(version()); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(version()); + return rcpp_result_gen; + END_RCPP } // init_logging void init_logging(const std::string& log_level); RcppExport SEXP _RMariaDB_init_logging(SEXP log_levelSEXP) { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const std::string& >::type log_level(log_levelSEXP); - init_logging(log_level); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type log_level( + log_levelSEXP); + init_logging(log_level); + return R_NilValue; + END_RCPP } // result_create -XPtr result_create(XPtr con, std::string sql, bool is_statement); -RcppExport SEXP _RMariaDB_result_create(SEXP conSEXP, SEXP sqlSEXP, SEXP is_statementSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< XPtr >::type con(conSEXP); - Rcpp::traits::input_parameter< std::string >::type sql(sqlSEXP); - Rcpp::traits::input_parameter< bool >::type is_statement(is_statementSEXP); - rcpp_result_gen = Rcpp::wrap(result_create(con, sql, is_statement)); - return rcpp_result_gen; -END_RCPP +XPtr result_create(XPtr con, std::string sql, + bool is_statement); +RcppExport SEXP _RMariaDB_result_create(SEXP conSEXP, SEXP sqlSEXP, + SEXP is_statementSEXP) { + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter >::type con(conSEXP); + Rcpp::traits::input_parameter::type sql(sqlSEXP); + Rcpp::traits::input_parameter::type is_statement(is_statementSEXP); + rcpp_result_gen = Rcpp::wrap(result_create(con, sql, is_statement)); + return rcpp_result_gen; + END_RCPP } // result_release void result_release(XPtr res); RcppExport SEXP _RMariaDB_result_release(SEXP resSEXP) { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< XPtr >::type res(resSEXP); - result_release(res); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter >::type res(resSEXP); + result_release(res); + return R_NilValue; + END_RCPP } // result_valid bool result_valid(XPtr res_); RcppExport SEXP _RMariaDB_result_valid(SEXP res_SEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< XPtr >::type res_(res_SEXP); - rcpp_result_gen = Rcpp::wrap(result_valid(res_)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter >::type res_(res_SEXP); + rcpp_result_gen = Rcpp::wrap(result_valid(res_)); + return rcpp_result_gen; + END_RCPP } // result_fetch List result_fetch(DbResult* res, const int n); RcppExport SEXP _RMariaDB_result_fetch(SEXP resSEXP, SEXP nSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbResult* >::type res(resSEXP); - Rcpp::traits::input_parameter< const int >::type n(nSEXP); - rcpp_result_gen = Rcpp::wrap(result_fetch(res, n)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type res(resSEXP); + Rcpp::traits::input_parameter::type n(nSEXP); + rcpp_result_gen = Rcpp::wrap(result_fetch(res, n)); + return rcpp_result_gen; + END_RCPP } // result_bind void result_bind(DbResult* res, List params); RcppExport SEXP _RMariaDB_result_bind(SEXP resSEXP, SEXP paramsSEXP) { -BEGIN_RCPP - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbResult* >::type res(resSEXP); - Rcpp::traits::input_parameter< List >::type params(paramsSEXP); - result_bind(res, params); - return R_NilValue; -END_RCPP + BEGIN_RCPP + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type res(resSEXP); + Rcpp::traits::input_parameter::type params(paramsSEXP); + result_bind(res, params); + return R_NilValue; + END_RCPP } // result_has_completed bool result_has_completed(DbResult* res); RcppExport SEXP _RMariaDB_result_has_completed(SEXP resSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbResult* >::type res(resSEXP); - rcpp_result_gen = Rcpp::wrap(result_has_completed(res)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type res(resSEXP); + rcpp_result_gen = Rcpp::wrap(result_has_completed(res)); + return rcpp_result_gen; + END_RCPP } // result_rows_fetched int result_rows_fetched(DbResult* res); RcppExport SEXP _RMariaDB_result_rows_fetched(SEXP resSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbResult* >::type res(resSEXP); - rcpp_result_gen = Rcpp::wrap(result_rows_fetched(res)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type res(resSEXP); + rcpp_result_gen = Rcpp::wrap(result_rows_fetched(res)); + return rcpp_result_gen; + END_RCPP } // result_rows_affected int result_rows_affected(DbResult* res); RcppExport SEXP _RMariaDB_result_rows_affected(SEXP resSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbResult* >::type res(resSEXP); - rcpp_result_gen = Rcpp::wrap(result_rows_affected(res)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type res(resSEXP); + rcpp_result_gen = Rcpp::wrap(result_rows_affected(res)); + return rcpp_result_gen; + END_RCPP } // result_column_info List result_column_info(DbResult* res); RcppExport SEXP _RMariaDB_result_column_info(SEXP resSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< DbResult* >::type res(resSEXP); - rcpp_result_gen = Rcpp::wrap(result_column_info(res)); - return rcpp_result_gen; -END_RCPP + BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter::type res(resSEXP); + rcpp_result_gen = Rcpp::wrap(result_column_info(res)); + return rcpp_result_gen; + END_RCPP } static const R_CallMethodDef CallEntries[] = { - {"_RMariaDB_connection_create", (DL_FUNC) &_RMariaDB_connection_create, 16}, - {"_RMariaDB_connection_valid", (DL_FUNC) &_RMariaDB_connection_valid, 1}, - {"_RMariaDB_connection_release", (DL_FUNC) &_RMariaDB_connection_release, 1}, - {"_RMariaDB_connection_info", (DL_FUNC) &_RMariaDB_connection_info, 1}, - {"_RMariaDB_connection_quote_string", (DL_FUNC) &_RMariaDB_connection_quote_string, 2}, - {"_RMariaDB_connection_begin_transaction", (DL_FUNC) &_RMariaDB_connection_begin_transaction, 1}, - {"_RMariaDB_connection_commit", (DL_FUNC) &_RMariaDB_connection_commit, 1}, - {"_RMariaDB_connection_rollback", (DL_FUNC) &_RMariaDB_connection_rollback, 1}, - {"_RMariaDB_connection_is_transacting", (DL_FUNC) &_RMariaDB_connection_is_transacting, 1}, - {"_RMariaDB_driver_init", (DL_FUNC) &_RMariaDB_driver_init, 0}, - {"_RMariaDB_driver_done", (DL_FUNC) &_RMariaDB_driver_done, 0}, - {"_RMariaDB_version", (DL_FUNC) &_RMariaDB_version, 0}, - {"_RMariaDB_init_logging", (DL_FUNC) &_RMariaDB_init_logging, 1}, - {"_RMariaDB_result_create", (DL_FUNC) &_RMariaDB_result_create, 3}, - {"_RMariaDB_result_release", (DL_FUNC) &_RMariaDB_result_release, 1}, - {"_RMariaDB_result_valid", (DL_FUNC) &_RMariaDB_result_valid, 1}, - {"_RMariaDB_result_fetch", (DL_FUNC) &_RMariaDB_result_fetch, 2}, - {"_RMariaDB_result_bind", (DL_FUNC) &_RMariaDB_result_bind, 2}, - {"_RMariaDB_result_has_completed", (DL_FUNC) &_RMariaDB_result_has_completed, 1}, - {"_RMariaDB_result_rows_fetched", (DL_FUNC) &_RMariaDB_result_rows_fetched, 1}, - {"_RMariaDB_result_rows_affected", (DL_FUNC) &_RMariaDB_result_rows_affected, 1}, - {"_RMariaDB_result_column_info", (DL_FUNC) &_RMariaDB_result_column_info, 1}, - {NULL, NULL, 0} -}; + {"_RMariaDB_connection_create", (DL_FUNC)&_RMariaDB_connection_create, 16}, + {"_RMariaDB_connection_valid", (DL_FUNC)&_RMariaDB_connection_valid, 1}, + {"_RMariaDB_connection_release", (DL_FUNC)&_RMariaDB_connection_release, 1}, + {"_RMariaDB_connection_info", (DL_FUNC)&_RMariaDB_connection_info, 1}, + {"_RMariaDB_connection_quote_string", + (DL_FUNC)&_RMariaDB_connection_quote_string, 2}, + {"_RMariaDB_connection_begin_transaction", + (DL_FUNC)&_RMariaDB_connection_begin_transaction, 1}, + {"_RMariaDB_connection_commit", (DL_FUNC)&_RMariaDB_connection_commit, 1}, + {"_RMariaDB_connection_rollback", (DL_FUNC)&_RMariaDB_connection_rollback, + 1}, + {"_RMariaDB_connection_is_transacting", + (DL_FUNC)&_RMariaDB_connection_is_transacting, 1}, + {"_RMariaDB_driver_init", (DL_FUNC)&_RMariaDB_driver_init, 0}, + {"_RMariaDB_driver_done", (DL_FUNC)&_RMariaDB_driver_done, 0}, + {"_RMariaDB_version", (DL_FUNC)&_RMariaDB_version, 0}, + {"_RMariaDB_init_logging", (DL_FUNC)&_RMariaDB_init_logging, 1}, + {"_RMariaDB_result_create", (DL_FUNC)&_RMariaDB_result_create, 3}, + {"_RMariaDB_result_release", (DL_FUNC)&_RMariaDB_result_release, 1}, + {"_RMariaDB_result_valid", (DL_FUNC)&_RMariaDB_result_valid, 1}, + {"_RMariaDB_result_fetch", (DL_FUNC)&_RMariaDB_result_fetch, 2}, + {"_RMariaDB_result_bind", (DL_FUNC)&_RMariaDB_result_bind, 2}, + {"_RMariaDB_result_has_completed", (DL_FUNC)&_RMariaDB_result_has_completed, + 1}, + {"_RMariaDB_result_rows_fetched", (DL_FUNC)&_RMariaDB_result_rows_fetched, + 1}, + {"_RMariaDB_result_rows_affected", (DL_FUNC)&_RMariaDB_result_rows_affected, + 1}, + {"_RMariaDB_result_column_info", (DL_FUNC)&_RMariaDB_result_column_info, 1}, + {NULL, NULL, 0}}; -RcppExport void R_init_RMariaDB(DllInfo *dll) { - R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); - R_useDynamicSymbols(dll, FALSE); +RcppExport void R_init_RMariaDB(DllInfo* dll) { + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); } diff --git a/src/connection.cpp b/src/connection.cpp index 3ecf4aa9..e350ecee 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -1,33 +1,25 @@ #include "pch.h" + #include "RMariaDB_types.h" // [[Rcpp::export]] XPtr connection_create( - const Nullable& host, - const Nullable& user, - const Nullable& password, - const Nullable& db, - unsigned int port, - const Nullable& unix_socket, - unsigned long client_flag, - const Nullable& groups, - const Nullable& default_file, - const Nullable& ssl_key, - const Nullable& ssl_cert, - const Nullable& ssl_ca, - const Nullable& ssl_capath, - const Nullable& ssl_cipher, - int timeout, - bool reconnect -) { + const Nullable& host, const Nullable& user, + const Nullable& password, const Nullable& db, + unsigned int port, const Nullable& unix_socket, + unsigned long client_flag, const Nullable& groups, + const Nullable& default_file, + const Nullable& ssl_key, const Nullable& ssl_cert, + const Nullable& ssl_ca, + const Nullable& ssl_capath, + const Nullable& ssl_cipher, int timeout, bool reconnect) { LOG_VERBOSE; DbConnection* pConnPtr = new DbConnection; try { - pConnPtr->connect( - host, user, password, db, port, unix_socket, client_flag, groups, default_file, - ssl_key, ssl_cert, ssl_ca, ssl_capath, ssl_cipher, timeout, reconnect - ); + pConnPtr->connect(host, user, password, db, port, unix_socket, client_flag, + groups, default_file, ssl_key, ssl_cert, ssl_ca, + ssl_capath, ssl_cipher, timeout, reconnect); } catch (...) { delete pConnPtr; throw; @@ -98,15 +90,13 @@ bool connection_is_transacting(DbConnection* con) { return con->is_transacting(); } - // Specific functions - // as() override namespace Rcpp { -template<> +template <> DbConnection* as(SEXP x) { DbConnectionPtr* connection = (DbConnectionPtr*)(R_ExternalPtrAddr(x)); if (!connection) @@ -114,4 +104,4 @@ DbConnection* as(SEXP x) { return connection->get(); } -} +} // namespace Rcpp diff --git a/src/driver.cpp b/src/driver.cpp index 37db4c8f..aa940f86 100644 --- a/src/driver.cpp +++ b/src/driver.cpp @@ -8,7 +8,6 @@ #define SERVER_VERSION "" #endif - // [[Rcpp::export]] void driver_init() { mysql_library_init(0, NULL, NULL); @@ -21,11 +20,9 @@ void driver_done() { // [[Rcpp::export]] IntegerVector version() { - return - IntegerVector::create( + return IntegerVector::create( _[SERVER_VERSION] = MYSQL_VERSION_ID, - _[mysql_get_client_info()] = mysql_get_client_version() - ); + _[mysql_get_client_info()] = mysql_get_client_version()); } // [[Rcpp::export]] diff --git a/src/integer64.h b/src/integer64.h index dfa12ea5..2f3b934c 100644 --- a/src/integer64.h +++ b/src/integer64.h @@ -9,4 +9,4 @@ inline int64_t* INTEGER64(SEXP x) { return reinterpret_cast(REAL(x)); } -#endif // RMARIADB_INTEGER64_H +#endif // RMARIADB_INTEGER64_H diff --git a/src/pch.h b/src/pch.h index f11d93e9..81e2cf21 100644 --- a/src/pch.h +++ b/src/pch.h @@ -1,6 +1,5 @@ #include #include - #include using namespace Rcpp; diff --git a/src/result.cpp b/src/result.cpp index 03e3da7b..0ae16f0d 100644 --- a/src/result.cpp +++ b/src/result.cpp @@ -1,10 +1,11 @@ #include "pch.h" -#include "RMariaDB_types.h" -#include "MariaResult.h" +#include "MariaResult.h" +#include "RMariaDB_types.h" // [[Rcpp::export]] -XPtr result_create(XPtr con, std::string sql, bool is_statement = false) { +XPtr result_create(XPtr con, std::string sql, + bool is_statement = false) { (*con)->check_connection(); DbResult* res = MariaResult::create_and_send_query(*con, sql, is_statement); return XPtr(res, true); @@ -53,7 +54,7 @@ List result_column_info(DbResult* res) { namespace Rcpp { -template<> +template <> DbResult* as(SEXP x) { DbResult* result = (DbResult*)(R_ExternalPtrAddr(x)); if (!result) @@ -61,4 +62,4 @@ DbResult* as(SEXP x) { return result; } -} +} // namespace Rcpp