Storage Engine API
mobile_sqlite_statement.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <sqlite3.h>
32 #include <string>
33 
35 #include "mongo/platform/atomic_word.h"
36 
37 namespace mongo {
38 
43 class SqliteStatement final {
44 public:
48  SqliteStatement(const MobileSession& session, const std::string& sqlQuery);
49 
54 
60  void bindInt(int paramIndex, int64_t intValue);
61 
62  void bindBlob(int paramIndex, const void* data, int len);
63 
64  void bindText(int paramIndex, const char* data, int len);
65 
66  void clearBindings();
67 
75  int step(int desiredStatus = -1);
76 
83  int64_t getColInt(int colIndex);
84 
85  const void* getColBlob(int colIndex);
86 
90  int64_t getColBytes(int colIndex);
91 
97  const void* getColText(int colIndex);
98 
102  void reset();
103 
109  }
110 
117  static void execQuery(MobileSession* session, const std::string& query);
118 
119  uint64_t _id;
120 
121 private:
122  static AtomicInt64 _nextID;
123  sqlite3_stmt* _stmt;
124 
125  // If the most recent call to sqlite3_step on this statement returned an error, the error is
126  // returned again when the statement is finalized. This is used to verify that the last error
127  // code returned matches the finalize error code, if there is any.
128  int _exceptionStatus = SQLITE_OK;
129 };
130 } // namespace mongo
static void execQuery(MobileSession *session, const std::string &query)
A one step query execution that wraps sqlite3_prepare_v2(), sqlite3_step(), and sqlite3_finalize().
Definition: mobile_sqlite_statement.cpp:127
sqlite3_stmt * _stmt
Definition: mobile_sqlite_statement.h:123
Status status
Definition: database_impl.cpp:1020
void bindText(int paramIndex, const char *data, int len)
Definition: mobile_sqlite_statement.cpp:84
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
IndexKeyEntry query
Definition: ephemeral_for_test_btree_impl.cpp:457
void bindInt(int paramIndex, int64_t intValue)
The various bind methods bind a value to the query parameter specified by paramIndex.
Definition: mobile_sqlite_statement.cpp:72
std::shared_ptr< void > data
Definition: ephemeral_for_test_record_store_test.cpp:74
SqliteStatement(const MobileSession &session, const std::string &sqlQuery)
Creates and prepares a SQLite statement.
Definition: mobile_sqlite_statement.cpp:49
void setExceptionStatus(int status)
Sets the last status on the prepared statement.
Definition: mobile_sqlite_statement.h:107
int step(int desiredStatus=-1)
Wraps sqlite3_step and returns the resulting status.
Definition: mobile_sqlite_statement.cpp:95
const void * getColText(int colIndex)
Wraps sqlite3_column_text method and returns the text from the retrieved query row[colIndex].
Definition: mobile_sqlite_statement.cpp:123
~SqliteStatement()
Finalizes the prepared statement.
Definition: mobile_sqlite_statement.cpp:67
static AtomicInt64 _nextID
Definition: mobile_sqlite_statement.h:122
This class manages a SQLite database connection object.
Definition: mobile_session.h:43
int _exceptionStatus
Definition: mobile_sqlite_statement.h:128
void bindBlob(int paramIndex, const void *data, int len)
Definition: mobile_sqlite_statement.cpp:78
SqliteStatement is a wrapper around the sqlite3_stmt object.
Definition: mobile_sqlite_statement.h:43
void clearBindings()
Definition: mobile_sqlite_statement.cpp:90
const void * getColBlob(int colIndex)
Definition: mobile_sqlite_statement.cpp:115
void reset()
Resets the statement to the first of the query result rows.
Definition: mobile_sqlite_statement.cpp:147
int64_t getColBytes(int colIndex)
Returns the number of bytes in a corresponding blob or string.
Definition: mobile_sqlite_statement.cpp:119
uint64_t _id
Definition: mobile_sqlite_statement.h:119
int64_t getColInt(int colIndex)
The getCol methods wrap sqlite3_column methods and return the correctly typed values stored in a retr...
Definition: mobile_sqlite_statement.cpp:111