-
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.
Added UpdateDBConnection to refresh DB connection for python clients
* First attempt of adding UpdateDBConnection * Fixed several bugs due to caching of sqlite3 objects --------- Co-authored-by: Lucio Anderlini <[email protected]>
- Loading branch information
1 parent
a332686
commit e801210
Showing
17 changed files
with
311 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ | |
/.idea/ | ||
*.swp | ||
/docs/ | ||
/wheelhouse/ | ||
/dist/ | ||
**.egg-info | ||
**/__pycache__/ |
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 |
---|---|---|
|
@@ -44,7 +44,7 @@ classifiers = [ | |
] | ||
|
||
|
||
version = "0.0c5" | ||
version = "0.0c7" | ||
|
||
dependencies = ["hepmc3"] | ||
|
||
|
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,43 @@ | ||
# (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. | ||
import ctypes | ||
from ctypes import POINTER | ||
from SQLamarr import clib, c_TransformerPtr | ||
|
||
from SQLamarr.db_functions import SQLite3DB | ||
|
||
clib.new_UpdateDBConnection.argtypes = (ctypes.c_void_p,) | ||
clib.new_UpdateDBConnection.restype = c_TransformerPtr | ||
|
||
class UpdateDBConnection: | ||
""" | ||
Update the reference to the DB Connection, to ensure synchronization with disk. | ||
Refer to SQLamarr::UpdateDBConnection for implementation details. | ||
""" | ||
def __init__ (self, db: SQLite3DB): | ||
""" | ||
Configure a Transformer to update the connection to the DB. | ||
@param db: An open database connection. | ||
""" | ||
self._self = clib.new_UpdateDBConnection(db.get(), db.path.encode('ascii')) | ||
|
||
def __del__(self): | ||
"""@private: Release the bound class instance""" | ||
clib.del_Transformer(self._self) | ||
|
||
@property | ||
def raw_pointer(self): | ||
"""@private: Return the raw pointer to the algorithm.""" | ||
return self._self | ||
|
||
|
||
|
||
|
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
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,47 @@ | ||
// (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> | ||
#include <random> | ||
|
||
// SQLite3 | ||
#include "sqlite3.h" | ||
|
||
// SQLamarr | ||
#include "SQLamarr/UpdateDBConnection.h" | ||
#include "SQLamarr/GlobalPRNG.h" | ||
#include "SQLamarr/db_functions.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() | ||
{ | ||
update_db_connection(m_database, m_filename, m_flags); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.