#include <dataholding.h>
Public Member Functions | |
Dataholding (Dedupe::FilePath Path) | |
bool | AlreadyInDatabase (Dedupe::FileInfo const &File) |
void | AddFile (Dedupe::FileInfo const &IncomingFile) |
void | AddFiles (Dedupe::FileStream const &IncomingFiles) |
void | UpdateFile (Dedupe::FileInfo const &Updated) |
void | DelFile (Dedupe::FileInfo const &FileToDel) |
void | DelFiles (Dedupe::FileStream const &FilesToDel) |
Dedupe::FileStream | GetFiles () |
Dedupe::FileStream | SqlExec (const std::string &SqlCommand) |
Dataholding represents the dataholding module. To create it, give the path where the database should be created to the constructor.
Definition at line 26 of file dataholding.h.
Dataholding::Dataholding | ( | Dedupe::FilePath | Path | ) |
Give the databasepath to the constructor. Make sure you have read/write rights there! The rights are not checked!
Definition at line 14 of file dataholding.cpp.
References SqlExec().
{
sqlite3_stmt *stmt( NULL );
std::string SqlString(
"INSERT INTO StoredFiles( Path, Size, ChangeDate, Type, Keep, Hash) VALUES (?,?,?,?,?,?)");
SqliteWrapper::Check(sqlite3_prepare_v2(
db_handle,
SqlString.c_str(),
SqlString.size(),
&stmt,
NULL ));
void Dataholding::AddFile | ( | Dedupe::FileInfo const & | IncomingFile | ) |
Add a single file to the database. The function don't check if the file is already in database!
Definition at line 60 of file dataholding.cpp.
References Dedupe::FileInfo::GetDateChanged(), Dedupe::FileInfo::GetHash(), Dedupe::FileInfo::GetKeep(), Dedupe::FileInfo::GetPath(), Dedupe::FileInfo::GetSize(), and Dedupe::FileInfo::GetType().
Referenced by AddFiles().
{
sqlite3_stmt *stmt( NULL );
std::string SqlString(
"DELETE FROM StoredFiles WHERE Path=?;");
SqliteWrapper::Check(sqlite3_prepare_v2(
db_handle,
SqlString.c_str(),
void Dataholding::AddFiles | ( | Dedupe::FileStream const & | IncomingFiles | ) |
Adds a FileStream holding more files to the database. No check, if one of the files is already in the database
Definition at line 85 of file dataholding.cpp.
References AddFile().
bool Dataholding::AlreadyInDatabase | ( | Dedupe::FileInfo const & | File | ) |
Checks, if a file is already stored in the database. It checks for Path, Size, ChangeDate and Type but NOT hash value.
Definition at line 37 of file dataholding.cpp.
References Dedupe::FileInfo::GetDateChanged(), Dedupe::FileInfo::GetPath(), and Dedupe::FileInfo::GetSize().
{ std::for_each( IncomingFiles.begin(), IncomingFiles.end(), boost::bind( &Dataholding::AddFile, this, _1 ));} void Dataholding::UpdateFile( Dedupe::FileInfo const &Updated ) { sqlite3_stmt *stmt( NULL ); std::string SqlString( "UPDATE StoredFiles SET Size=?, ChangeDate=?, Type=?, Keep=?, Hash=? WHERE Path=?"); SqliteWrapper::Check(sqlite3_prepare_v2( db_handle, SqlString.c_str(),
void Dataholding::DelFile | ( | Dedupe::FileInfo const & | FileToDel | ) |
Deletes a specified file from the database. There is no message if done or not, cause sqlite don't give a message back. Use AlreadyInDatabase instead.
Definition at line 118 of file dataholding.cpp.
References Dedupe::FileInfo::GetPath().
Referenced by Dedupe::Core::Kernel::AutoUpdateDatabase(), DelFiles(), and Dedupe::Core::Kernel::UntrackFiles().
{ for( int i = 0; i < cols; i++ ) { if( !sqlite3_column_name( stmt, i ) ) continue; name = sqlite3_column_name( stmt, i ); if( name.empty() ) continue; if( name == "Path" ) { Path = reinterpret_cast<const char*>( sqlite3_column_text( stmt, i )); } if( name == "Size" ) { Size = sqlite3_column_int64( stmt, i ); }
void Dataholding::DelFiles | ( | Dedupe::FileStream const & | FilesToDel | ) |
Deletes spezified files from the database. Equal to DelFile, read it's description
Definition at line 137 of file dataholding.cpp.
References DelFile().
{ ChangeDate = sqlite3_column_int64( stmt, i ); } if( name == "Hash" ) {
Dedupe::FileStream Dataholding::GetFiles | ( | ) |
Call this function to get all Files, that are stored in the database
Definition at line 145 of file dataholding.cpp.
References SqlExec().
Referenced by Dedupe::Core::Kernel::AutoUpdateDatabase(), Dedupe::Core::Kernel::FindFiledateDuplicates(), Dedupe::Core::Kernel::FindFilenameDuplicates(), Dedupe::Core::Kernel::FindFilesizeDuplicates(), Dedupe::Core::Kernel::FindHashDuplicates(), Dedupe::Core::Kernel::GetDatabase(), and Dedupe::Core::Kernel::ListDatabase().
{ Type = static_cast<Dedupe::FileInfo::FileType>(sqlite3_column_int( stmt, i )); }
Dedupe::FileStream Dataholding::SqlExec | ( | const std::string & | sql_com | ) |
This function can execute every SQL command, but the result can only handle tables. It's also possible to execute more as one SQL-Command. The commands must be seperated by ";". If you call two commands, which give a result back, both results are stored. Please note, that the result will be overwritten if you call the functions a second time.
Reimplemented from Dedupe::Dataholding::SqliteWrapper.
Definition at line 214 of file dataholding.cpp.
Referenced by Dataholding(), and GetFiles().
void Dataholding::UpdateFile | ( | Dedupe::FileInfo const & | Updated | ) |
UpdateFile wants a updated FileInfo. Which Dataset is updated is decided by the path, which is stored in the FileInfo object
Definition at line 93 of file dataholding.cpp.
References Dedupe::FileInfo::GetDateChanged(), Dedupe::FileInfo::GetHash(), Dedupe::FileInfo::GetKeep(), Dedupe::FileInfo::GetPath(), Dedupe::FileInfo::GetSize(), and Dedupe::FileInfo::GetType().
Referenced by Dedupe::Core::Kernel::AutoUpdateDatabase().
{ std::for_each( FilesToDel.begin(), FilesToDel.end(), boost::bind( &Dataholding::DelFile, this, _1 )); } Dedupe::FileStream Dataholding::GetFiles(){ //Get all stored data from the database return SqlExec( "SELECT * FROM StoredFiles;" );} Dedupe::FileStream Dataholding::ExecStatement( sqlite3_stmt *stmt ) { Dedupe::FileStream ReturningInfos; Dedupe::FilePath Path( "" ); unsigned long long Size( 0 ), Hash( 0 ); time_t ChangeDate( 0 ); Dedupe::FileInfo::FileType Type( Dedupe::FileInfo::TNotDefined ); bool Keep( false ); //get how many columns are in the table int cols = sqlite3_column_count( stmt ); //step until all results are readed out