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 
36 namespace mongo {
37 
42 class SqliteStatement final {
43 public:
47  SqliteStatement(const MobileSession& session, const std::string& sqlQuery);
48 
53 
59  void bindInt(int paramIndex, int64_t intValue);
60 
61  void bindBlob(int paramIndex, const void* data, int len);
62 
63  void bindText(int paramIndex, const char* data, int len);
64 
65  void clearBindings();
66 
74  int step(int desiredStatus = -1);
75 
82  int64_t getColInt(int colIndex);
83 
84  const void* getColBlob(int colIndex);
85 
89  int64_t getColBytes(int colIndex);
90 
96  const void* getColText(int colIndex);
97 
101  void reset();
102 
108  }
109 
116  static void execQuery(MobileSession* session, const std::string& query);
117 
118 private:
119  sqlite3_stmt* _stmt;
120 
121  // If the most recent call to sqlite3_step on this statement returned an error, the error is
122  // returned again when the statement is finalized. This is used to verify that the last error
123  // code returned matches the finalize error code, if there is any.
124  int _exceptionStatus = SQLITE_OK;
125 };
126 } // 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:116
sqlite3_stmt * _stmt
Definition: mobile_sqlite_statement.h:119
void bindText(int paramIndex, const char *data, int len)
Definition: mobile_sqlite_statement.cpp:76
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:64
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:45
void setExceptionStatus(int status)
Sets the last status on the prepared statement.
Definition: mobile_sqlite_statement.h:106
int step(int desiredStatus=-1)
Wraps sqlite3_step and returns the resulting status.
Definition: mobile_sqlite_statement.cpp:87
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:112
Status status
Definition: database_impl.cpp:975
~SqliteStatement()
Finalizes the prepared statement.
Definition: mobile_sqlite_statement.cpp:59
This class manages a SQLite database connection object.
Definition: mobile_session.h:43
int _exceptionStatus
Definition: mobile_sqlite_statement.h:124
void bindBlob(int paramIndex, const void *data, int len)
Definition: mobile_sqlite_statement.cpp:70
SqliteStatement is a wrapper around the sqlite3_stmt object.
Definition: mobile_sqlite_statement.h:42
void clearBindings()
Definition: mobile_sqlite_statement.cpp:82
const void * getColBlob(int colIndex)
Definition: mobile_sqlite_statement.cpp:104
void reset()
Resets the statement to the first of the query result rows.
Definition: mobile_sqlite_statement.cpp:133
int64_t getColBytes(int colIndex)
Returns the number of bytes in a corresponding blob or string.
Definition: mobile_sqlite_statement.cpp:108
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:100