Skip to content

Commit

Permalink
Swithc to sqlite3_prepare_v2 as we didn't really need v3 and it is no…
Browse files Browse the repository at this point in the history
…t on RS3 (microsoft#134)

v3 is not available on Windows 10 (16299), and we don't really need or use the persistent statements in a meaningful way.  Fall back to v2 and remove the persistent statement support.
  • Loading branch information
JohnMcPMS authored May 13, 2020
1 parent aa7f136 commit 695de19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/AppInstallerRepositoryCore/SQLiteStatementBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,9 @@ namespace AppInstaller::Repository::SQLite::Builder
return *this;
}

Statement StatementBuilder::Prepare(Connection& connection, bool persistent)
Statement StatementBuilder::Prepare(Connection& connection)
{
Statement result = Statement::Create(connection, m_stream.str(), persistent);
Statement result = Statement::Create(connection, m_stream.str());
for (const auto& f : m_binders)
{
f(result);
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerRepositoryCore/SQLiteStatementBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ namespace AppInstaller::Repository::SQLite::Builder
int GetLastBindIndex() const { return m_bindIndex - 1; }

// Prepares and returns the statement, applying any bindings that were requested.
Statement Prepare(Connection& connection, bool persistent = false);
Statement Prepare(Connection& connection);

// A convenience function that prepares, binds, and then executes a statement that does not return rows.
void Execute(Connection& connection);
Expand Down
20 changes: 10 additions & 10 deletions src/AppInstallerRepositoryCore/SQLiteWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,29 @@ namespace AppInstaller::Repository::SQLite
return sqlite3_changes(m_dbconn.get());
}

Statement::Statement(Connection& connection, std::string_view sql, bool persistent)
Statement::Statement(Connection& connection, std::string_view sql)
{
m_id = GetNextStatementId();
AICLI_LOG(SQL, Verbose, << "Preparing statement #" << m_id << ": " << sql);
// SQL string size should include the null terminator (https://www.sqlite.org/c3ref/prepare.html)
assert(sql.data()[sql.size()] == '\0');
THROW_IF_SQLITE_FAILED(sqlite3_prepare_v3(connection, sql.data(), static_cast<int>(sql.size() + 1), (persistent ? SQLITE_PREPARE_PERSISTENT : 0), &m_stmt, nullptr));
THROW_IF_SQLITE_FAILED(sqlite3_prepare_v2(connection, sql.data(), static_cast<int>(sql.size() + 1), &m_stmt, nullptr));
}

Statement Statement::Create(Connection& connection, const std::string& sql, bool persistent)
Statement Statement::Create(Connection& connection, const std::string& sql)
{
return { connection, { sql.c_str(), sql.size() }, persistent };
return { connection, { sql.c_str(), sql.size() } };
}

Statement Statement::Create(Connection& connection, std::string_view sql, bool persistent)
Statement Statement::Create(Connection& connection, std::string_view sql)
{
// We need the statement to be null terminated, and the only way to guarantee that with a string_view is to construct a string copy.
return Create(connection, std::string(sql), persistent);
return Create(connection, std::string(sql));
}

Statement Statement::Create(Connection& connection, char const* const sql, bool persistent)
Statement Statement::Create(Connection& connection, char const* const sql)
{
return { connection, sql, persistent };
return { connection, sql };
}

bool Statement::Step(bool failFastOnError)
Expand Down Expand Up @@ -203,8 +203,8 @@ namespace AppInstaller::Repository::SQLite
using namespace std::string_literals;

Statement begin = Statement::Create(connection, "SAVEPOINT ["s + m_name + "]");
m_rollbackTo = Statement::Create(connection, "ROLLBACK TO ["s + m_name + "]", true);
m_release = Statement::Create(connection, "RELEASE ["s + m_name + "]", true);
m_rollbackTo = Statement::Create(connection, "ROLLBACK TO ["s + m_name + "]");
m_release = Statement::Create(connection, "RELEASE ["s + m_name + "]");

AICLI_LOG(SQL, Info, << "Begin savepoint: " << m_name);
begin.Step();
Expand Down
8 changes: 4 additions & 4 deletions src/AppInstallerRepositoryCore/SQLiteWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ namespace AppInstaller::Repository::SQLite
// A SQL statement.
struct Statement
{
static Statement Create(Connection& connection, const std::string& sql, bool persistent = false);
static Statement Create(Connection& connection, std::string_view sql, bool persistent = false);
static Statement Create(Connection& connection, char const* const sql, bool persistent = false);
static Statement Create(Connection& connection, const std::string& sql);
static Statement Create(Connection& connection, std::string_view sql);
static Statement Create(Connection& connection, char const* const sql);

Statement() = default;

Expand Down Expand Up @@ -231,7 +231,7 @@ namespace AppInstaller::Repository::SQLite
operator bool() const { return static_cast<bool>(m_stmt); }

private:
Statement(Connection& connection, std::string_view sql, bool persistent);
Statement(Connection& connection, std::string_view sql);

// Helper to receive the integer sequence from the public function.
// This is equivalent to calling:
Expand Down

0 comments on commit 695de19

Please sign in to comment.