-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt of adding UpdateDBConnection
- Loading branch information
Lucio Anderlini
authored and
Lucio Anderlini
committed
Apr 25, 2024
1 parent
a332686
commit 4d12601
Showing
7 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// Licence version 3 (GPL Version 3), copied verbatim in the file "LICENCE". | ||
// | ||
// In applying this licence, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
#pragma once | ||
|
||
// STL | ||
#include <string> | ||
|
||
// SQLamarr | ||
#include "SQLamarr/db_functions.h" | ||
#include "SQLamarr/Transformer.h" | ||
|
||
namespace SQLamarr | ||
{ | ||
/** Reset the database connection forcing flushing the db status. | ||
* | ||
* In the interaction with Python or other frameworks it is sometimes | ||
* necessary to ensure db synchronization with disk or shared memory. | ||
* This can be achieved refreshing the connection to the database, | ||
* by closing it and reopening. | ||
* | ||
* WARNING! Executing UpdateDBConnection drops TEMPORARY tables and views. | ||
*/ | ||
class UpdateDBConnection: public Transformer | ||
{ | ||
public: | ||
/// Constructor | ||
UpdateDBConnection ( | ||
SQLite3DB& db, | ||
///< Reference to the database | ||
std::string filename, | ||
///< Filename or URI of the (possibly new) connection to the database | ||
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI | ||
///< Flags | ||
); | ||
|
||
|
||
/// Execute the algorithm, cleaning the database | ||
void execute () override; | ||
|
||
private: // members | ||
SQLite3DB& m_database; ///< Reference to the SQLite database (not owned). | ||
const std::string m_filename; ///< Filename or URI of the database | ||
const int m_flags; ///< SQLite flags to open to database (see sqlite_open_v3) | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration. | ||
// | ||
// This software is distributed under the terms of the GNU General Public | ||
// Licence version 3 (GPL Version 3), copied verbatim in the file "LICENCE". | ||
// | ||
// In applying this licence, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
|
||
// STL | ||
#include <memory> | ||
|
||
// SQLite3 | ||
#include "sqlite3.h" | ||
|
||
// SQLamarr | ||
#include "SQLamarr/UpdateDBConnection.h" | ||
|
||
namespace SQLamarr | ||
{ | ||
//============================================================================ | ||
// Constructor | ||
//============================================================================ | ||
UpdateDBConnection::UpdateDBConnection( | ||
SQLite3DB& db, | ||
std::string filename, | ||
int flags | ||
) | ||
: m_database(db) | ||
, m_filename(filename) | ||
, m_flags(flags) | ||
{} | ||
|
||
//============================================================================ | ||
// execute | ||
//============================================================================ | ||
void UpdateDBConnection::execute() | ||
{ | ||
SQLite3DB new_database = make_database(m_filename, m_flags); | ||
m_database.swap(new_database); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters