Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
MDQuery Class Reference

#include <metadata_query.h>

Inheritance diagram for MDQuery:
Inheritance graph
[legend]

Public Member Functions

 MDQuery (int limit=-1, int offset=0, MDLabel orderLabel=MDL_OBJID, bool asc=true)
 
virtual ~MDQuery ()
 
String orderByString () const
 
String limitString () const
 
String whereString () const
 
virtual String queryStringFunc () const
 

Public Attributes

int limit
 If distint of -1 the results will be limited to this value. More...
 
int offset
 If distint of 0, offset elements will be discarded. More...
 
MDLabel orderLabel
 Label to which apply sort of the results. More...
 
bool asc
 

Detailed Description

This is the base class for queries on MetaData. It is abstract, so it can not be instanciated. Queries will be very helpful for performing several tasks on MetaData like importing, searching or removing objects.

Definition at line 41 of file metadata_query.h.

Constructor & Destructor Documentation

◆ MDQuery()

MDQuery::MDQuery ( int  limit = -1,
int  offset = 0,
MDLabel  orderLabel = MDL_OBJID,
bool  asc = true 
)
inline

Constructor.

Definition at line 50 of file metadata_query.h.

51  {
52  this->limit = limit;
53  this->offset = offset;
54  this->orderLabel = orderLabel;
55  this->asc=asc;
56  }
int limit
If distint of -1 the results will be limited to this value.
MDLabel orderLabel
Label to which apply sort of the results.
int offset
If distint of 0, offset elements will be discarded.

◆ ~MDQuery()

virtual MDQuery::~MDQuery ( )
inlinevirtual

Destructor

Definition at line 59 of file metadata_query.h.

59 {}

Member Function Documentation

◆ limitString()

String MDQuery::limitString ( ) const

Return the LIMIT string to be used in SQL

Definition at line 3 of file metadata_query.cpp.

4 {
5  if (limit == -1 && offset > 0)
6  REPORT_ERROR(ERR_MD_SQL, "Sqlite does not support OFFSET without LIMIT");
7  std::stringstream ss;
8  if (limit != -1)
9  ss << " LIMIT " << limit << " ";
10  if (offset > 0)
11  ss << " OFFSET " << offset << " ";
12  return ss.str();
13 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
int limit
If distint of -1 the results will be limited to this value.
int offset
If distint of 0, offset elements will be discarded.
Error in SQL of MetaData operations.
Definition: xmipp_error.h:159

◆ orderByString()

String MDQuery::orderByString ( ) const
inline

Return the ORDER BY string to be used in SQL query

Definition at line 62 of file metadata_query.h.

63  {
64  return (String)" ORDER BY " + MDL::label2Str(orderLabel) + (asc ? " ASC" : " DESC");
65  }
MDLabel orderLabel
Label to which apply sort of the results.
std::string String
Definition: xmipp_strings.h:34
static String label2Str(const MDLabel &label)

◆ queryStringFunc()

virtual String MDQuery::queryStringFunc ( ) const
inlinevirtual

Return the query string, should be overrided in subclasses

Reimplemented in MDMultiQuery, MDExpression, MDValueRange, and MDValueRelational.

Definition at line 78 of file metadata_query.h.

79  {
80  return " ";
81  }

◆ whereString()

String MDQuery::whereString ( ) const
inline

Return the WHERE string to be used in SQL query

Definition at line 71 of file metadata_query.h.

72  {
73  String queryString = this->queryStringFunc();
74  return (queryString == " ") ? " " : " WHERE " + queryString + " ";
75  }
virtual String queryStringFunc() const
std::string String
Definition: xmipp_strings.h:34

Member Data Documentation

◆ asc

bool MDQuery::asc

Definition at line 47 of file metadata_query.h.

◆ limit

int MDQuery::limit

If distint of -1 the results will be limited to this value.

Definition at line 44 of file metadata_query.h.

◆ offset

int MDQuery::offset

If distint of 0, offset elements will be discarded.

Definition at line 45 of file metadata_query.h.

◆ orderLabel

MDLabel MDQuery::orderLabel

Label to which apply sort of the results.

Definition at line 46 of file metadata_query.h.


The documentation for this class was generated from the following files: