⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datadevelopermanual.page

📁 很好用的网络封装库,不熟悉网络编程的人也可以使用。使用风格良好的标准c++编写。
💻 PAGE
📖 第 1 页 / 共 2 页
字号:
    
    virtual ~AbstractPreparation();
        /// Destroys the AbstractPreparation.
    
    virtual void prepare(std::size_t pos, Poco::Int8) = 0;
        /// Prepares an Int8.
    
    virtual void prepare(std::size_t pos, Poco::UInt8) = 0;
        /// Prepares an UInt8.
    
    virtual void prepare(std::size_t pos, Poco::Int16) = 0;
        /// Prepares an Int16.
    
    virtual void prepare(std::size_t pos, Poco::UInt16) = 0;
        /// Prepares an UInt16.
    
    virtual void prepare(std::size_t pos, Poco::Int32) = 0;
        /// Prepares an Int32.
    
    virtual void prepare(std::size_t pos, Poco::UInt32) = 0;
        /// Prepares an UInt32.
    
    virtual void prepare(std::size_t pos, Poco::Int64) = 0;
        /// Prepares an Int64.
    
    virtual void prepare(std::size_t pos, Poco::UInt64) = 0;
        /// Prepares an UInt64.
    
    virtual void prepare(std::size_t pos, bool) = 0;
        /// Prepares a boolean.
    
    virtual void prepare(std::size_t pos, float) = 0;
        /// Prepares a float.
    
    virtual void prepare(std::size_t pos, double) = 0;
        /// Prepares a double.
    
    virtual void prepare(std::size_t pos, char) = 0;
        /// Prepares a single character.
    
    virtual void prepare(std::size_t pos, const std::string& ) = 0;
        /// Prepares a string.
    
    virtual void prepare(std::size_t pos, const BLOB&) = 0;
----

Note that it is recommended to prepare a statement only once in the compileImpl of <[StatementImpl]>. The AbstractPrepare objects (which make use of <[AbstractPreparation]>
can be created by iterating over the Extractor objects of the StatementImpl:

    Poco::Data::AbstractExtractingVec::iterator it = extractings().begin();
    Poco::Data::AbstractExtractingVec::iterator itEnd = extractings().end();
    std::size_t pos = 0; // sqlite starts with pos 0 for results! your DB maybe with 1
    for (; it != itEnd; ++it)
    {
         AbstractPrepare* pPrep = (*it)->createPrepareObject(pPreparation, pos);
        _prepareVec.push_back(pPrep);
        (*it)->extract(pos);
        pos += (*it)->numOfColumnsHandled();
    }
----
!!!StatementImpl
A <[StatementImpl]> stores as member a Binder and an Extractor (optional a Preparation object) and is responsible for compiling, binding, fetching single rows from the database and invoking the <*Extracting*> objects.
The interface it has to implement is given as:

    public:
        StatementImpl();
            /// Creates the StatementImpl.
        
        virtual ~StatementImpl();
            /// Destroys the StatementImpl.
    
    protected:
        virtual bool hasNext() = 0;
            /// Returns true if a call to next() will return data. Note that the 
            /// implementation must support several consecutive calls to hasNext 
            /// without data getting lost, ie. hasNext(); hasNext(); next() must 
            /// be equal to hasNext(); next();
    
        virtual void next() = 0;
            /// Retrieves the next row from the resultset.
            /// Will throw, if the resultset is empty.
            /// Expects the statement to be compiled and bound
    
        virtual bool canBind() const = 0;
            /// Returns if another bind is possible.
    
        virtual void compileImpl() = 0;
            /// Compiles the statement, doesn't bind yet.
            /// From now on AbstractBinder and AbstractExtractor 
            /// will be used
    
        virtual void bindImpl() = 0;
            /// Binds parameters.
    
        virtual AbstractExtractor& extractor() = 0;
            /// Returns the concrete extractor used by the statement.
    
        virtual AbstractBinder& binder() = 0;
            /// Returns the concrete binder used by the statement.  
----

The Extracting and Binding objects can be accessed via the calls to the super-class methods <*extractings()*> and <*bindings()*>.
A high-level <*bind*> implementation will look like this:

    [...]
    Poco::Data::AbstractBindingVec& binds = bindings();
    std::size_t pos = 1; // or 0 depending on your database
    Poco::Data::AbstractBindingVec::iterator it = binds.begin();
    Poco::Data::AbstractBindingVec::iterator itEnd = binds.end();
    for (; it != itEnd && (*it)->canBind(); ++it)
    {
        (*it)->bind(pos);
        pos += (*it)->numOfColumnsHandled();
    }
----

A high-level <*next*> implementation:

    if (!hasNext())
        throw Poco::Data::DataException("No data received");
    int nCol = countColumnsInResult...;
    poco_assert (columnsHandled() == nCol); 
    Poco::Data::AbstractExtractingVec::iterator it = extractings().begin();
    Poco::Data::AbstractExtractingVec::iterator itEnd = extractings().end();
    std::size_t pos = 0; // sqlite starts with pos 0 for results! your DB maybe with 1
    for (; it != itEnd; ++it)
    {
        (*it)->extract(pos);
        pos += (*it)->numOfColumnsHandled();
    }
    enableHasNext();
----

A high-level <*hasNext*> implementation:

    if (enabledhasNext())
    {
        checkIfItHasMoreData
        cacheResult
        disablehasNext()
    }
    
    return cachedResult;
----

A high-level <*compileImpl*>:

    if (compiled)
        return;
    
    std::string sqlStmt(toString());

   if database expects placeholders in different format than ":name", parse and replace them

    compile statement;
    
    create Binder;
    create Extractor;
----

A high-level <*canBind*>:

    bool ret = false;
    if (!bindings().empty() && validCompiledStatement)
        ret = (*bindings().begin())->canBind();
    
    return ret;
----

!!!SessionImpl
The purpose of the <[SessionImpl]> is simply to open/close a connection to the database, to act as factory for <[StatementImpl]> objects, and to handle transactions.
The connection is opened in the constructor, and closed in the destructor.

    Poco::Data::StatementImpl* createStatementImpl();
        /// Returns an SQLite StatementImpl
    
    void begin();
        /// Starts a transaction
    
    void commit();
        /// Commits and ends a transaction
    
    void rollback();
        /// Aborts a transaction
----

!!!Connector
Finally, one needs to implement the <[Connector]>.
Each <[Connector]> should have a public static const string member named <*KEY*> and must have a factory method to <*create*> <[ Poco::AutoPtr ]> objects of type <[SessionImpl]>.
It should also have a static <*addToFactory()*> and a static <*removeFromFactory()*> method:

    class My_API Connector: public Poco::Data::Connector
        /// Connector instantiates SessionImpl objects.
    {
    public:
        static const std::string KEY;
            /// Keyword for creating sessions
    
        Connector();
            /// Creates the Connector.
    
        ~Connector();
        /// Destroys the Connector.
    
        Poco::AutoPtr < Poco::Data::SessionImpl > createSession(const std::string& connectionString);
            /// Creates a SessionImpl object and initializes it with the given connectionString.
    
        static void registerConnector();
            /// Registers the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory
    
        static void unregisterConnector();
            /// Unregisters the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory
    };
----

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -