28 #ifndef CORE_METADATASQL_H 29 #define CORE_METADATASQL_H 44 class sqlite3_context;
58 void sqlite_regexp(sqlite3_context* context,
int argc, sqlite3_value** values);
114 void copyTableFromFileDB(
const FileName blockname,
116 const std::vector<MDLabel> *desiredLabels,
117 const size_t maxRows=0
137 bool addColumn(
MDLabel column);
142 bool renameColumn(
const std::vector<MDLabel> &oldLabel,
const std::vector<MDLabel> &newlabel);
147 template <
typename T>
148 bool setObjectValues(
int id,
const std::vector<T> &columnValues,
const std::vector<MDLabel> *desiredLabels=NULL);
152 bool setObjectValue(
const int objId,
const MDObject &value);
156 bool setObjectValue(
const MDObject &value);
160 bool getObjectsValues(
const std::vector<MDLabel> &labels, std::vector<MDObject> &values);
164 bool getObjectValue(
const int objId,
MDObject &value);
172 void selectObjects(std::vector<size_t> &objectsOut,
const MDQuery *queryPtr = NULL);
181 size_t deleteObjects(
const MDQuery *queryPtr = NULL);
186 size_t copyObjects(
MDSql * sqlOut,
187 const MDQuery *queryPtr = NULL)
const;
189 const MDQuery *queryPtr = NULL)
const;
194 const std::vector<AggregateOperation> &operations,
195 const std::vector<MDLabel> &operateLabel);
201 const std::vector<MDLabel> &groupByLabels ,
223 void indexModify(
const std::vector<MDLabel> &columns,
bool create=
true);
229 size_t nextRow(
size_t currentRow);
230 size_t previousRow(
size_t currentRow);
232 int columnMaxLength(
MDLabel column);
236 void setOperate(
const MetaDataDb *mdInLeft,
const MetaDataDb *mdInRight,
const std::vector<MDLabel> &columnsLeft,
237 const std::vector<MDLabel> &columnsRight,
SetOperation operation);
239 bool operate(
const String &expression);
254 static int table_counter;
260 static bool sqlBegin();
261 static void sqlEnd();
262 static bool sqlBeginTrans();
263 static bool sqlCommitTrans();
271 bool createTable(
const std::vector<MDLabel> * labelsVector = NULL,
bool withObjID=
true);
272 bool insertValues(
double a,
double b);
273 bool initializeSelect(
bool addWhereObjId,
const std::vector<MDLabel> &labels);
274 bool initializeInsert(
const std::vector<MDLabel> *labels,
const std::vector<MDObject*> &values);
275 void finalizePreparedStmt(
void);
276 void prepareStmt(
const std::stringstream &ss, sqlite3_stmt *stmt);
277 bool execSingleStmt(
const std::stringstream &ss);
278 bool execSingleStmt(sqlite3_stmt *&stmt,
const std::stringstream *ss = NULL);
279 size_t execSingleIntStmt(
const std::stringstream &ss);
280 double execSingleDoubleStmt(
const std::stringstream &ss);
282 String tableName(
const int tableId)
const;
284 bool bindStatement(
size_t id);
285 int bindValue(sqlite3_stmt *stmt,
const int position,
const MDObject &valueIn);
286 void extractValue(sqlite3_stmt *stmt,
const int position,
MDObject &valueOut);
289 static const char *zLeftover;
291 static sqlite3_stmt *stmt;
293 static std::stringstream preparedStream;
294 static sqlite3_stmt * preparedStmt;
305 bool equals(
const MDSql &op);
std::vector< String > StringVector