1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/**************** tabcmg H Declares Source Code File (.H) **************/
/* Name: tabcmg.h Version 1.3 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2017 - 2021 */
/* */
/* This file contains the MongoDB classes declares. */
/***********************************************************************/
#include "mongo.h"
#include "cmgoconn.h"
/***********************************************************************/
/* Class used to get the columns of a mongo collection. */
/***********************************************************************/
class CMGDISC : public MGODISC {
public:
// Constructor
CMGDISC(PGLOBAL g, int *lg) : MGODISC(g, lg) { drv = "C"; }
// Methods
void GetDoc(void) override;
//bool Find(PGLOBAL g, int i, int k, bool b) override;
bool Find(PGLOBAL g) override;
// BSON Function
//bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
// char *pcn, char *pfmt, int i, int k, bool b);
bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
char *pcn, char *pfmt, int k, bool b);
// Members
bson_iter_t iter;
const bson_t *doc;
}; // end of CMGDISC
/* -------------------------- TDBCMG class --------------------------- */
/***********************************************************************/
/* This is the MongoDB Table Type class declaration. */
/* The table is a collection, each record being a document. */
/***********************************************************************/
class DllExport TDBCMG : public TDBEXT {
friend class MGOCOL;
friend class MGODEF;
friend class CMGDISC;
friend PQRYRES MGOColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool);
public:
// Constructor
TDBCMG(MGODEF *tdp);
TDBCMG(TDBCMG *tdbp);
// Implementation
AMT GetAmType(void) override {return TYPE_AM_MGO;}
PTDB Duplicate(PGLOBAL g) {return (PTDB)new(g) TDBCMG(this);}
// Methods
PTDB Clone(PTABS t) override;
PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) override;
PCOL InsertSpecialColumn(PCOL colp) override;
int RowNumber(PGLOBAL g, bool b = FALSE) override {return N;}
// Database routines
int Cardinality(PGLOBAL g) override;
int GetMaxSize(PGLOBAL g) override;
bool OpenDB(PGLOBAL g) override;
int ReadDB(PGLOBAL g) override;
int WriteDB(PGLOBAL g) override;
int DeleteDB(PGLOBAL g, int irc) override;
void CloseDB(PGLOBAL g) override;
bool ReadKey(PGLOBAL g, OPVAL op, const key_range *kr) override;
protected:
bool Init(PGLOBAL g);
// Members
CMgoConn *Cmgp; // Points to a C Mongo connection class
CMGOPARM Pcg; // Parms passed to Cmgp
const Item *Cnd; // The first condition
PCSZ Strfy; // The stringified columns
int Fpos; // The current row index
int N; // The current Rownum
int B; // Array index base
bool Done; // Init done
}; // end of class TDBCMG
/* --------------------------- MGOCOL class -------------------------- */
/***********************************************************************/
/* Class MGOCOL: MongoDB access method column descriptor. */
/***********************************************************************/
class DllExport MGOCOL : public EXTCOL {
friend class TDBCMG;
friend class FILTER;
public:
// Constructors
MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i);
MGOCOL(MGOCOL *colp, PTDB tdbp); // Constructor used in copy process
// Implementation
int GetAmType(void) override { return Tmgp->GetAmType(); }
bool Stringify(void) override { return Sgfy; }
// Methods
PSZ GetJpath(PGLOBAL g, bool proj) override;
void ReadColumn(PGLOBAL g) override;
void WriteColumn(PGLOBAL g) override;
protected:
// Default constructor not to be used
MGOCOL(void) {}
// Members
TDBCMG *Tmgp; // To the MGO table block
char *Jpath; // The json path
bool Sgfy; // True if stringified
}; // end of class MGOCOL
/***********************************************************************/
/* This is the class declaration for the MONGO catalog table. */
/***********************************************************************/
class DllExport TDBGOL : public TDBCAT {
public:
// Constructor
TDBGOL(PMGODEF tdp);
protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g) override;
// Members
PTOS Topt;
PCSZ Uri;
PCSZ Db;
}; // end of class TDBGOL
|