/** * * @file Sqlite3Connection.h * @author An Tao * * Copyright 2018, An Tao. All rights reserved. * https://github.com/an-tao/drogon * Use of this source code is governed by a MIT license * that can be found in the License file. * * Drogon * */ #pragma once #include "../DbConnection.h" #include "Sqlite3ResultImpl.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace drogon { namespace orm { class Sqlite3Connection; using Sqlite3ConnectionPtr = std::shared_ptr; class Sqlite3Connection : public DbConnection, public std::enable_shared_from_this { public: Sqlite3Connection(trantor::EventLoop *loop, const std::string &connInfo, const std::shared_ptr &sharedMutex); void init() override; void execSql(std::string_view &&sql, size_t paraNum, std::vector &¶meters, std::vector &&length, std::vector &&format, ResultCallback &&rcb, std::function &&exceptCallback) override; void batchSql(std::deque> &&) override { LOG_FATAL << "The mysql library does not support batch mode"; exit(1); } void disconnect() override; private: static std::once_flag once_; void execSqlInQueue( const std::string_view &sql, size_t paraNum, const std::vector ¶meters, const std::vector &length, const std::vector &format, const ResultCallback &rcb, const std::function &exceptCallback); void onError( const std::string_view &sql, const std::function &exceptCallback); int stmtStep(sqlite3_stmt *stmt, const std::shared_ptr &resultPtr, int columnNum); trantor::EventLoopThread loopThread_; std::shared_ptr connectionPtr_; std::shared_ptr sharedMutexPtr_; std::unordered_map> stmtsMap_; std::set stmts_; std::string connInfo_; }; } // namespace orm } // namespace drogon