<commit_before>/************* tabjson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson     Version 1.4                               */
/*  (C) Copyright to the author <NAME>          2014 - 2017  */
/*  This program are the JSON class DB execution routines.             */
/***********************************************************************/

/***********************************************************************/
/*  Include relevant sections of the MariaDB header file.              */
/***********************************************************************/
#include <my_global.h>

/***********************************************************************/
/*  Include application header files:                                  */
/*  global.h    is header containing all global declarations.          */
/*  plgdbsem.h  is header containing the DB application declarations.  */
/*  tdbdos.h    is header containing the TDBDOS declarations.          */
/*  json.h      is header containing the JSON classes declarations.    */
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
//#include "xtable.h"
#include "maputil.h"
#include "filamtxt.h"
#include "tabdos.h"
//#include "resource.h"                        // for IDS_COLUMNS
#include "tabjson.h"
#include "filamap.h"
#if defined(GZ_SUPPORT)
#include "filamgz.h"
#endif   // GZ_SUPPORT
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif   // ZIP_SUPPORT
#if defined(MONGO_SUPPORT)
#include "mongofam.h"
#endif   // MONGO_SUPPORT
#include "tabmul.h"
#include "checklvl.h"
#include "resource.h"
#include "mycat.h"                             // for FNC_COL

/***********************************************************************/
/*  This should be an option.                                          */
/***********************************************************************/
#define MAXCOL          200        /* Default max column nb in result  */
#define TYPE_UNKNOWN     12        /* Must be greater than other types */
#define USE_G             1        /* Use recoverable memory if 1      */

/***********************************************************************/
/*  External functions.                                                */
/***********************************************************************/
USETEMP UseTemp(void);
bool    IsNum(PSZ s);
char   *NextChr(PSZ s, char sep);

typedef struct _jncol {
  struct _jncol *Next;
  char *Name;
  char *Fmt;
  int   Type;
  int   Len;
  int   Scale;
  bool  Cbn;
  bool  Found;
} JCOL, *PJCL;

/***********************************************************************/
/* JSONColumns: construct the result blocks containing the description */
/* of all the columns of a table contained inside a JSON file.         */
/***********************************************************************/
PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info)
{
  static int  buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, 
                          TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING};
  static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, 
                          FLD_LENGTH, FLD_SCALE, FLD_NULL, FLD_FORMAT};
  static unsigned int length[] = {0, 6, 8, 10, 10, 6, 6, 0};
  char   *p, colname[65], fmt[129];
  int     i, j, lvl, n = 0;
  int     ncol = sizeof(buftyp) / sizeof(int);
	PCSZ    sep;
  PVAL    valp;
  JCOL    jcol;
  PJCL    jcp, fjcp = NULL, pjcp = NULL;
  PJPR   *jrp, jpp;
  PJSON   jsp;
  PJVAL   jvp;
  PJOB    row;
  PJDEF   tdp;
  TDBJSN *tjnp = NULL;
  PJTDB   tjsp = NULL;
  PQRYRES qrp;
  PCOLRES crp;

  jcol.Name = jcol.Fmt = NULL;

  if (info) {
    length[0] = 128;
    length[7] = 256;
    goto skipit;
    } // endif info

	if (GetIntegerTableOption(g, topt, "Multiple", 0)) {
		strcpy(g->Message, "Cannot find column definition for multiple table");
		return NULL;
	}	// endif Multiple

	/*********************************************************************/
  /*  Open the input file.                                             */
  /*********************************************************************/
  lvl = GetIntegerTableOption(g, topt, "Level", 0);
  lvl = (lvl < 0) ? 0 : (lvl > 16) ? 16 : lvl;
	sep = GetStringTableOption(g, topt, "Separator", ".");

  tdp = new(g) JSONDEF;
#if defined(ZIP_SUPPORT)
	tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL);
	tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false);
#endif   // ZIP_SUPPORT
	tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);

	if (!tdp->Fn && !dsn) {
		strcpy(g->Message, MSG(MISSING_FNAME));
		return NULL;
	} // endif Fn

	if (!(tdp->Database = SetPath(g, db)))
		return NULL;

  tdp->Objname = GetStringTableOption(g, topt, "Object", NULL);
  tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
  tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2);
	tdp->Xcol = GetStringTableOption(g, topt, "Expand", NULL);

  if (trace)
    htrc("File %s objname=%s pretty=%d lvl=%d\n", 
          tdp->Fn, tdp->Objname, tdp->Pretty, lvl);

	if (dsn && *dsn)
		tdp->Uri = dsn;

	if (tdp->Uri) {
#if defined(MONGO_SUPPORT)
		tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);<commit_msg>Fix bug: Discovery of JSON table fails in DEBUG mode when NO MONGO support. (tdb->Uri is uninitialized)   modified:   storage/connect/tabjson.cpp<commit_after>/************* tabjson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson     Version 1.4                               */
/*  (C) Copyright to the author <NAME>          2014 - 2017  */
/*  This program are the JSON class DB execution routines.             */
/***********************************************************************/

/***********************************************************************/
/*  Include relevant sections of the MariaDB header file.              */
/***********************************************************************/
#include <my_global.h>

/***********************************************************************/
/*  Include application header files:                                  */
/*  global.h    is header containing all global declarations.          */
/*  plgdbsem.h  is header containing the DB application declarations.  */
/*  tdbdos.h    is header containing the TDBDOS declarations.          */
/*  json.h      is header containing the JSON classes declarations.    */
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
//#include "xtable.h"
#include "maputil.h"
#include "filamtxt.h"
#include "tabdos.h"
//#include "resource.h"                        // for IDS_COLUMNS
#include "tabjson.h"
#include "filamap.h"
#if defined(GZ_SUPPORT)
#include "filamgz.h"
#endif   // GZ_SUPPORT
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
#endif   // ZIP_SUPPORT
#if defined(MONGO_SUPPORT)
#include "mongofam.h"
#endif   // MONGO_SUPPORT
#include "tabmul.h"
#include "checklvl.h"
#include "resource.h"
#include "mycat.h"                             // for FNC_COL

/***********************************************************************/
/*  This should be an option.                                          */
/***********************************************************************/
#define MAXCOL          200        /* Default max column nb in result  */
#define TYPE_UNKNOWN     12        /* Must be greater than other types */
#define USE_G             1        /* Use recoverable memory if 1      */

/***********************************************************************/
/*  External functions.                                                */
/***********************************************************************/
USETEMP UseTemp(void);
bool    IsNum(PSZ s);
char   *NextChr(PSZ s, char sep);

typedef struct _jncol {
  struct _jncol *Next;
  char *Name;
  char *Fmt;
  int   Type;
  int   Len;
  int   Scale;
  bool  Cbn;
  bool  Found;
} JCOL, *PJCL;

/***********************************************************************/
/* JSONColumns: construct the result blocks containing the description */
/* of all the columns of a table contained inside a JSON file.         */
/***********************************************************************/
PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info)
{
  static int  buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, 
                          TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING};
  static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, 
                          FLD_LENGTH, FLD_SCALE, FLD_NULL, FLD_FORMAT};
  static unsigned int length[] = {0, 6, 8, 10, 10, 6, 6, 0};
  char   *p, colname[65], fmt[129];
  int     i, j, lvl, n = 0;
  int     ncol = sizeof(buftyp) / sizeof(int);
	PCSZ    sep;
  PVAL    valp;
  JCOL    jcol;
  PJCL    jcp, fjcp = NULL, pjcp = NULL;
  PJPR   *jrp, jpp;
  PJSON   jsp;
  PJVAL   jvp;
  PJOB    row;
  PJDEF   tdp;
  TDBJSN *tjnp = NULL;
  PJTDB   tjsp = NULL;
  PQRYRES qrp;
  PCOLRES crp;

  jcol.Name = jcol.Fmt = NULL;

  if (info) {
    length[0] = 128;
    length[7] = 256;
    goto skipit;
    } // endif info

	if (GetIntegerTableOption(g, topt, "Multiple", 0)) {
		strcpy(g->Message, "Cannot find column definition for multiple table");
		return NULL;
	}	// endif Multiple

	/*********************************************************************/
  /*  Open the input file.                                             */
  /*********************************************************************/
  lvl = GetIntegerTableOption(g, topt, "Level", 0);
  lvl = (lvl < 0) ? 0 : (lvl > 16) ? 16 : lvl;
	sep = GetStringTableOption(g, topt, "Separator", ".");

  tdp = new(g) JSONDEF;
#if defined(ZIP_SUPPORT)
	tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL);
	tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false);
#endif   // ZIP_SUPPORT
	tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);

	if (!tdp->Fn && !dsn) {
		strcpy(g->Message, MSG(MISSING_FNAME));
		return NULL;
	} // endif Fn

	if (!(tdp->Database = SetPath(g, db)))
		return NULL;

  tdp->Objname = GetStringTableOption(g, topt, "Object", NULL);
  tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
  tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2);
	tdp->Xcol = GetStringTableOption(g, topt, "Expand", NULL);
	tdp->Uri = (dsn && *dsn ? dsn : NULL);

  if (trace)
    htrc("File %s objname=%s pretty=%d lvl=%d\n", 
          tdp->Fn, tdp->Objname, tdp->Pretty, lvl);

	if (tdp->Uri) {
#if defined(MONGO_SUPPORT)
		tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
{'fraction_non_alphanumeric': 0.28696380385223785, 'fraction_numerical': 0.009863217642132688, 'mean_word_length': 2.997024916325772, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1753703', 'n_tokens_mistral': 3477, 'n_tokens_neox': 3187, 'n_words': 887}