Beispiel #1
0
PCOL TDBASE::InsertSpcBlk(PGLOBAL g, PCOLDEF cdp)
  {
//char *name = cdp->GetName();
  char   *name = cdp->GetFmt();
  PCOLUMN cp;
  PCOL    colp;

  cp= new(g) COLUMN(cdp->GetName());

  if (! To_Table) {
    strcpy(g->Message, "Cannot make special column: To_Table is NULL");
    return NULL;
  } else
    cp->SetTo_Table(To_Table);

  if (!stricmp(name, "FILEID") || !stricmp(name, "FDISK") ||
      !stricmp(name, "FPATH")  || !stricmp(name, "FNAME") ||
      !stricmp(name, "FTYPE")  || !stricmp(name, "SERVID")) {
    if (!To_Def || !(To_Def->GetPseudo() & 2)) {
      sprintf(g->Message, MSG(BAD_SPEC_COLUMN));
      return NULL;
      } // endif Pseudo

    if (!stricmp(name, "FILEID"))
      colp = new(g) FIDBLK(cp, OP_XX);
    else if (!stricmp(name, "FDISK"))
      colp = new(g) FIDBLK(cp, OP_FDISK);
    else if (!stricmp(name, "FPATH"))
      colp = new(g) FIDBLK(cp, OP_FPATH);
    else if (!stricmp(name, "FNAME"))
      colp = new(g) FIDBLK(cp, OP_FNAME);
    else if (!stricmp(name, "FTYPE"))
      colp = new(g) FIDBLK(cp, OP_FTYPE);
    else
      colp = new(g) SIDBLK(cp);

  } else if (!stricmp(name, "TABID")) {
    colp = new(g) TIDBLK(cp);
  } else if (!stricmp(name, "PARTID")) {
    colp = new(g) PRTBLK(cp);
//} else if (!stricmp(name, "CONID")) {
//  colp = new(g) CIDBLK(cp);
  } else if (!stricmp(name, "ROWID")) {
    colp = new(g) RIDBLK(cp, false);
  } else if (!stricmp(name, "ROWNUM")) {
      colp = new(g) RIDBLK(cp, true);
  } else {
    sprintf(g->Message, MSG(BAD_SPECIAL_COL), name);
    return NULL;
  } // endif's name

  if (!(colp = InsertSpecialColumn(colp))) {
    sprintf(g->Message, MSG(BAD_SPECIAL_COL), name);
    return NULL;
    } // endif Insert

  return (colp);
  } // end of InsertSpcBlk
Beispiel #2
0
bool TDBFMT::OpenDB(PGLOBAL g)
  {
  Linenum = 0;

  if (Mode == MODE_INSERT || Mode == MODE_UPDATE) {
    sprintf(g->Message, MSG(FMT_WRITE_NIY), "FMT");
    return true;                    // NIY
    } // endif Mode

  if (Use != USE_OPEN && Columns) {
    // Make the formats used to read records
    PSZ     pfm;
    int     i, n;
    PCSVCOL colp;
    PCOLDEF cdp;
    PDOSDEF tdp = (PDOSDEF)To_Def;

    for (colp = (PCSVCOL)Columns; colp; colp = (PCSVCOL)colp->Next)
      if (!colp->IsSpecial() && !colp->IsVirtual())  // a true column
        Fields = MY_MAX(Fields, (int)colp->Fldnum);

    if (Columns)
      Fields++;                // Fldnum was 0 based

    To_Fld = PlugSubAlloc(g, NULL, Lrecl + 1);
    FldFormat = (PSZ*)PlugSubAlloc(g, NULL, sizeof(PSZ) * Fields);
    memset(FldFormat, 0, sizeof(PSZ) * Fields);
    FmtTest = (int*)PlugSubAlloc(g, NULL, sizeof(int) * Fields);
    memset(FmtTest, 0, sizeof(int) * Fields);

    // Get the column formats
    for (cdp = tdp->GetCols(); cdp; cdp = cdp->GetNext())
      if (!cdp->IsVirtual() && (i = cdp->GetOffset() - 1) < Fields) {
        if (!(pfm = cdp->GetFmt())) {
          sprintf(g->Message, MSG(NO_FLD_FORMAT), i + 1, Name);
          return true;
          } // endif pfm

        // Roughly check the Fmt format
        if ((n = strlen(pfm) - 2) < 4) {
          sprintf(g->Message, MSG(BAD_FLD_FORMAT), i + 1, Name);
          return true;
          } // endif n

        FldFormat[i] = (PSZ)PlugSubAlloc(g, NULL, n + 5);
        strcpy(FldFormat[i], pfm);

        if (!strcmp(pfm + n, "%m")) {
          // This is a field that can be missing. Flag it so it can
          // be handled with special processing.
          FldFormat[i][n+1] = 'n';  // To have sscanf normal processing
          FmtTest[i] = 2;
        } else if (i+1 < Fields && strcmp(pfm + n, "%n")) {
          // There are trailing characters after the field contents
          // add a marker for the next field start position.
          strcat(FldFormat[i], "%n");
          FmtTest[i] = 1;
        } // endif's

        } // endif i

    } // endif Use

  return TDBCSV::OpenDB(g);
  } // end of OpenDB