Skip to content

Commit

Permalink
First attempt of adding UpdateDBConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucio Anderlini authored and Lucio Anderlini committed Apr 25, 2024
1 parent a332686 commit 4d12601
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 3 deletions.
18 changes: 17 additions & 1 deletion docs.md/Creating_the_wheel.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ older Linux distributions.
Indeed, PyPI forbids uploading wheel that do not specify a compatibility tag
used to choose the right wheel when running `pip install SQLamarr`.

## Using docker
To compile the wheel in compatibility mode, we are using the following recipe,
which assumes the working directory is the root of the git repository
```bash
Expand All @@ -15,7 +16,22 @@ docker run -it -v $PWD:/mylib quay.io/pypa/manylinux2014_x86_64:latest \
python3 -m twine upload wheelhouse/*.whl
```

Additional information:
## Using Apptainer
In some environments, docker is not available and apptainer should be used instead.

First convert the docker image to an SIF image (this is only required once).
```bash
apptainer build /tmp/pypa.sif docker://quay.io/pypa/manylinux2014_x86_64:latest
```

Then execute the following script (as for the docker case, it is assumed
the working directory is the root of the git repository).

```build
apptainer exec --bind $PWD:/mylib --writable-tmpfs /tmp/pypa.sif /bin/bash make_wheel.sh
```

## Additional information:
* Distributing binaries in compatibility mode: https://github.com/pypa/manylinux
* Example using travis for CI/CD: https://github.com/pypa/python-manylinux-demo

Expand Down
1 change: 0 additions & 1 deletion include/SQLamarr/BaseSqlInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <string>
#include <unordered_map>

#include "SQLamarr/BaseSqlInterface.h"
#include "SQLamarr/db_functions.h"

namespace SQLamarr
Expand Down
54 changes: 54 additions & 0 deletions include/SQLamarr/UpdateDBConnection.h
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)
};
}


2 changes: 1 addition & 1 deletion make_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cd /mylib;
rm -f wheelhouse/*.whl | echo "Ok";
rm -f dist/*.whl | echo "Ok";

for PYVERSION in cp311-cp311 cp310-cp310 cp37-cp37m cp38-cp38 cp39-cp39;
for PYVERSION in cp312-cp312 cp311-cp311 cp310-cp310 cp37-cp37m cp38-cp38 cp39-cp39;
do
export PYBIN=/opt/python/$PYVERSION/bin/python3
echo "Preparing binary distribution with $PYBIN";
Expand Down
4 changes: 4 additions & 0 deletions python/SQLamarr/db_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def __del__(self):
"""@private: Return the raw pointer to the algorithm."""
clib.del_database(self._pointer)

@property
def path(self):
return self._path

def get(self):
"""@private: Return the raw pointer to the database."""
return self._pointer
Expand Down
45 changes: 45 additions & 0 deletions src/UpdateDBConnection.cpp
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);
}
}


18 changes: 18 additions & 0 deletions src/python_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "SQLamarr/TemporaryTable.h"
#include "SQLamarr/CleanEventStore.h"
#include "SQLamarr/EditEventStore.h"
#include "SQLamarr/UpdateDBConnection.h"
#include "SQLamarr/SQLiteError.h"

constexpr int SQL_ERRORSHIFT = 10000;
Expand All @@ -39,6 +40,7 @@ typedef enum {
, TemporaryTable
, CleanEventStore
, EditEventStore
, UpdateDBConnection
} TransformerType;

struct TransformerPtr {
Expand Down Expand Up @@ -254,6 +256,19 @@ TransformerPtr new_EditEventStore (
)};
}

//==============================================================================
// UpdateDBConnection
//==============================================================================
extern "C"
TransformerPtr new_UpdateDBConnection (
void *db,
const char* path
)
{
SQLite3DB *udb = reinterpret_cast<SQLite3DB *>(db);
return {UpdateDBConnection, new SQLamarr::UpdateDBConnection(*udb, path)};
}

//==============================================================================
// Delete Transformer
//==============================================================================
Expand Down Expand Up @@ -286,6 +301,9 @@ void del_Transformer (TransformerPtr self)
case EditEventStore:
delete reinterpret_cast<SQLamarr::EditEventStore*> (self.p);
break;
case UpdateDBConnection:
delete reinterpret_cast<SQLamarr::UpdateDBConnection*> (self.p);
break;
default:
throw std::bad_cast();
}
Expand Down

0 comments on commit 4d12601

Please sign in to comment.