/************* TabZip C++ Program Source Code File (.CPP) **************/ /* PROGRAM NAME: TABZIP Version 1.0 */ /* (C) Copyright to the author Olivier BERTRAND 2016 */ /* This program are the TABZIP 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. */ /* (x)table.h is header containing the TDBASE declarations. */ /* tabzip.h is header containing the TABZIP classes declarations. */ /***********************************************************************/ #include"global.h" #include"plgdbsem.h" #include"xtable.h" #include"filamtxt.h" #include"filamzip.h" #include"resource.h"// for IDS_COLUMNS #include"tabdos.h" #include"tabmul.h" #include"tabzip.h"
/* -------------------------- Class ZIPDEF --------------------------- */
/************************************************************************/ /* DefineAM: define specific AM block values. */ /************************************************************************/ bool ZIPDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{ //target = GetStringCatInfo(g, "Target", NULL); return DOSDEF::DefineAM(g, "ZIP", poff);
} // end of DefineAM
/***********************************************************************/ /* GetTable: makes a new Table Description Block. */ /***********************************************************************/
PTDB ZIPDEF::GetTable(PGLOBAL g, MODE m)
{
PTDB tdbp = NULL;
/***********************************************************************/ /* Implementation of the TDBZIP class. */ /***********************************************************************/
TDBZIP::TDBZIP(PZIPDEF tdp) : TDBASE(tdp)
{
zipfile = NULL;
zfn = tdp->Fn; //target = tdp->target;
nexterr = UNZ_OK;
} // end of TDBZIP standard constructor
/***********************************************************************/ /* Allocate ZIP column description block. */ /***********************************************************************/
PCOL TDBZIP::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
{ returnnew(g) ZIPCOL(cdp, this, cprec, n);
} // end of MakeCol
/***********************************************************************/ /* open a zip file. */ /* param: filename path and the filename of the zip file to open. */ /* return: true if open, false otherwise. */ /***********************************************************************/ bool TDBZIP::open(PGLOBAL g, constchar *fn)
{ char filename[_MAX_PATH];
PlugSetPath(filename, fn, GetPath());
if (!zipfile && !(zipfile = unzOpen64(filename)))
snprintf(g->Message, sizeof(g->Message), "Zipfile open error");
return (zipfile == NULL);
} // end of open
/***********************************************************************/ /* Close the zip file. */ /***********************************************************************/ void TDBZIP::close()
{ if (zipfile) {
unzClose(zipfile);
zipfile = NULL;
} // endif zipfile
} // end of close
/***********************************************************************/ /* ZIP Cardinality: returns table size in number of rows. */ /***********************************************************************/ int TDBZIP::Cardinality(PGLOBAL g)
{ if (!g) return1; elseif (Cardinal < 0) { if (!open(g, zfn)) {
unz_global_info64 ginfo; int err = unzGetGlobalInfo64(zipfile, &ginfo);
/***********************************************************************/ /* ZIP GetMaxSize: returns file size estimate in number of lines. */ /***********************************************************************/ int TDBZIP::GetMaxSize(PGLOBAL g)
{ if (MaxSize < 0)
MaxSize = Cardinality(g);
return MaxSize;
} // end of GetMaxSize
/***********************************************************************/ /* ZIP Access Method opening routine. */ /***********************************************************************/ bool TDBZIP::OpenDB(PGLOBAL g)
{ if (Use == USE_OPEN) // Table already open returnfalse;
Use = USE_OPEN; // To be clean return open(g, zfn);
} // end of OpenDB
/***********************************************************************/ /* ReadDB: Data Base read routine for ZIP access method. */ /***********************************************************************/ int TDBZIP::ReadDB(PGLOBAL g)
{ if (nexterr == UNZ_END_OF_LIST_OF_FILE) return RC_EF; elseif (nexterr != UNZ_OK) {
snprintf(g->Message, sizeof(g->Message), "unzGoToNextFile error %d", nexterr); return RC_FX;
} // endif nexterr
nexterr = unzGoToNextFile(zipfile); return RC_OK;
} // end of ReadDB
/***********************************************************************/ /* WriteDB: Data Base write routine for ZIP access method. */ /***********************************************************************/ int TDBZIP::WriteDB(PGLOBAL g)
{
strcpy(g->Message, "ZIP tables are read only"); return RC_FX;
} // end of WriteDB
/***********************************************************************/ /* Data Base delete line routine for ZIP access method. */ /***********************************************************************/ int TDBZIP::DeleteDB(PGLOBAL g, int irc)
{
strcpy(g->Message, "Delete not enabled for ZIP tables"); return RC_FX;
} // end of DeleteDB
/***********************************************************************/ /* Data Base close routine for ZIP access method. */ /***********************************************************************/ void TDBZIP::CloseDB(PGLOBAL g)
{
close();
nexterr = UNZ_OK; // For multiple tables
Use = USE_READY; // Just to be clean
} // end of CloseDB
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.