Skip to content

Commit cdc7a69

Browse files
committed
CONNECT DIR tables: fix retrieving file date values under Windows.
modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h
1 parent 95667ae commit cdc7a69

File tree

2 files changed

+54
-88
lines changed

2 files changed

+54
-88
lines changed

storage/connect/tabmul.cpp

Lines changed: 51 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ void TDBDIR::Init(void)
634634
{
635635
iFile = 0;
636636
#if defined(__WIN__)
637+
Dvalp = NULL;
637638
memset(&FileData, 0, sizeof(_finddata_t));
638639
hSearch = INVALID_HANDLE_VALUE;
639640
*Drive = '\0';
@@ -662,37 +663,6 @@ TDBDIR::TDBDIR(PSZ fpat) : TDBASE((PTABDEF)NULL)
662663
Init();
663664
} // end of TDBDIR constructor
664665

665-
TDBDIR::TDBDIR(PTDBDIR tdbp) : TDBASE(tdbp)
666-
{
667-
To_File = tdbp->To_File;
668-
iFile = tdbp->iFile;
669-
#if defined(__WIN__)
670-
FileData = tdbp->FileData;
671-
hSearch = tdbp->hSearch;
672-
strcpy(Drive, tdbp->Drive);
673-
#else // !__WIN__
674-
Fileinfo = tdbp->Fileinfo;
675-
Entry = tdbp->Entry;
676-
Dir = tdbp->Dir;
677-
Done = tdbp->Done;
678-
strcpy(Pattern, tdbp->Pattern);
679-
#endif // !__WIN__
680-
strcpy(Direc, tdbp->Direc);
681-
strcpy(Fname, tdbp->Fname);
682-
strcpy(Ftype, tdbp->Ftype);
683-
} // end of TDBDIR copy constructor
684-
685-
// Method
686-
PTDB TDBDIR::Clone(PTABS t)
687-
{
688-
PTDB tp;
689-
PGLOBAL g = t->G; // Is this really useful ???
690-
691-
tp = new(g) TDBDIR(this);
692-
tp->SetColumns(Columns);
693-
return tp;
694-
} // end of Clone
695-
696666
/***********************************************************************/
697667
/* Initialize/get the components of the search file pattern. */
698668
/***********************************************************************/
@@ -958,6 +928,7 @@ DIRCOL::DIRCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ)
958928
} // endif cprec
959929

960930
// Set additional DIR access method information for column.
931+
Tdbp = (PTDBDIR)tdbp;
961932
N = cdp->GetOffset();
962933
} // end of DIRCOL constructor
963934

@@ -967,48 +938,73 @@ DIRCOL::DIRCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ)
967938
/***********************************************************************/
968939
DIRCOL::DIRCOL(DIRCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp)
969940
{
970-
N = col1->N;
941+
Tdbp = (PTDBDIR)tdbp;
942+
N = col1->N;
971943
} // end of DIRCOL copy constructor
972944

945+
#if defined(__WIN__)
946+
/***********************************************************************/
947+
/* Retrieve time information from FileData. */
948+
/***********************************************************************/
949+
void DIRCOL::SetTimeValue(PGLOBAL g, FILETIME& ftime)
950+
{
951+
char tsp[24];
952+
SYSTEMTIME stp;
953+
954+
if (FileTimeToSystemTime(&ftime, &stp)) {
955+
sprintf(tsp, "%04d-%02d-%02d %02d:%02d:%02d",
956+
stp.wYear, stp.wMonth, stp.wDay, stp.wHour, stp.wMinute, stp.wSecond);
957+
958+
if (Value->GetType() != TYPE_STRING) {
959+
if (!Tdbp->Dvalp)
960+
Tdbp->Dvalp = AllocateValue(g, TYPE_DATE, 20, 0, false,
961+
"YYYY-MM-DD hh:mm:ss");
962+
963+
Tdbp->Dvalp->SetValue_psz(tsp);
964+
Value->SetValue_pval(Tdbp->Dvalp);
965+
} else
966+
Value->SetValue_psz(tsp);
967+
968+
} else
969+
Value->Reset();
970+
971+
} // end of SetTimeValue
972+
#endif // __WIN__
973+
973974
/***********************************************************************/
974975
/* ReadColumn: what this routine does is to access the information */
975976
/* corresponding to this column and convert it to buffer type. */
976977
/***********************************************************************/
977978
void DIRCOL::ReadColumn(PGLOBAL g)
978-
{
979-
PTDBDIR tdbp = (PTDBDIR)To_Tdb;
980-
#if defined(__WIN__)
981-
//PSYSTEMTIME stp = NULL;
982-
#endif // !__WIN__
983-
979+
{
984980
if (trace)
985981
htrc("DIR ReadColumn: col %s R%d use=%.4X status=%.4X type=%d N=%d\n",
986-
Name, tdbp->GetTdb_No(), ColUse, Status, Buf_Type, N);
982+
Name, Tdbp->GetTdb_No(), ColUse, Status, Buf_Type, N);
987983

988984
/*********************************************************************/
989985
/* Retrieve the information corresponding to the column number. */
990986
/*********************************************************************/
991987
switch (N) {
992988
#if defined(__WIN__)
993-
case 0: Value->SetValue_psz(tdbp->Drive); break;
989+
case 0: Value->SetValue_psz(Tdbp->Drive); break;
994990
#endif // __WIN__
995-
case 1: Value->SetValue_psz(tdbp->Direc); break;
996-
case 2: Value->SetValue_psz(tdbp->Fname); break;
997-
case 3: Value->SetValue_psz(tdbp->Ftype); break;
991+
case 1: Value->SetValue_psz(Tdbp->Direc); break;
992+
case 2: Value->SetValue_psz(Tdbp->Fname); break;
993+
case 3: Value->SetValue_psz(Tdbp->Ftype); break;
998994
#if defined(__WIN__)
999-
case 4: Value->SetValue((int)tdbp->FileData.dwFileAttributes); break;
1000-
case 5: Value->SetValue((int)tdbp->FileData.nFileSizeLow); break;
1001-
case 6: SetTimeValue(g, tdbp->FileData.ftLastWriteTime); break;
1002-
case 7: SetTimeValue(g, tdbp->FileData.ftCreationTime); break;
1003-
case 8: SetTimeValue(g, tdbp->FileData.ftLastAccessTime); break;
995+
case 4: Value->SetValue((int)Tdbp->FileData.dwFileAttributes); break;
996+
case 5: Value->SetValue((int)Tdbp->FileData.nFileSizeLow); break;
997+
case 6: SetTimeValue(g, Tdbp->FileData.ftLastWriteTime); break;
998+
case 7: SetTimeValue(g, Tdbp->FileData.ftCreationTime); break;
999+
case 8: SetTimeValue(g, Tdbp->FileData.ftLastAccessTime); break;
10041000
#else // !__WIN__
1005-
case 4: Value->SetValue((int)tdbp->Fileinfo.st_mode); break;
1006-
case 5: Value->SetValue((int)tdbp->Fileinfo.st_size); break;
1007-
case 6: Value->SetValue((int)tdbp->Fileinfo.st_mtime); break;
1008-
case 7: Value->SetValue((int)tdbp->Fileinfo.st_ctime); break;
1009-
case 8: Value->SetValue((int)tdbp->Fileinfo.st_atime); break;
1010-
case 9: Value->SetValue((int)tdbp->Fileinfo.st_uid); break;
1011-
case 10: Value->SetValue((int)tdbp->Fileinfo.st_gid); break;
1001+
case 4: Value->SetValue((int)Tdbp->Fileinfo.st_mode); break;
1002+
case 5: Value->SetValue((int)Tdbp->Fileinfo.st_size); break;
1003+
case 6: Value->SetValue((int)Tdbp->Fileinfo.st_mtime); break;
1004+
case 7: Value->SetValue((int)Tdbp->Fileinfo.st_ctime); break;
1005+
case 8: Value->SetValue((int)Tdbp->Fileinfo.st_atime); break;
1006+
case 9: Value->SetValue((int)Tdbp->Fileinfo.st_uid); break;
1007+
case 10: Value->SetValue((int)Tdbp->Fileinfo.st_gid); break;
10121008
#endif // !__WIN__
10131009
default:
10141010
sprintf(g->Message, MSG(INV_DIRCOL_OFST), N);
@@ -1023,25 +1019,6 @@ void DIRCOL::ReadColumn(PGLOBAL g)
10231019

10241020
/* ------------------------- Class TDBSDR ---------------------------- */
10251021

1026-
/***********************************************************************/
1027-
/* TABSDR copy constructors. */
1028-
/***********************************************************************/
1029-
TDBSDR::TDBSDR(PTDBSDR tdbp) : TDBDIR(tdbp)
1030-
{
1031-
Sub = tdbp->Sub;
1032-
} // end of TDBSDR copy constructor
1033-
1034-
// Method
1035-
PTDB TDBSDR::Clone(PTABS t)
1036-
{
1037-
PTDB tp;
1038-
PGLOBAL g = t->G; // Is this really useful ???
1039-
1040-
tp = new(g) TDBSDR(this);
1041-
tp->SetColumns(Columns);
1042-
return tp;
1043-
} // end of Clone
1044-
10451022
/***********************************************************************/
10461023
/* SDR GetMaxSize: returns the number of retrieved files. */
10471024
/***********************************************************************/

storage/connect/tabmul.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,11 @@ class TDBDIR : public TDBASE {
134134
// Constructor
135135
TDBDIR(PDIRDEF tdp);
136136
TDBDIR(PSZ fpat);
137-
TDBDIR(PTDBDIR tdbp);
138137

139138
// Implementation
140139
virtual AMT GetAmType(void) {return TYPE_AM_DIR;}
141-
virtual PTDB Duplicate(PGLOBAL g)
142-
{return (PTDB)new(g) TDBDIR(this);}
143140

144141
// Methods
145-
virtual PTDB Clone(PTABS t);
146142
virtual int GetRecpos(void) {return iFile;}
147143

148144
// Database routines
@@ -164,7 +160,7 @@ class TDBDIR : public TDBASE {
164160
PSZ To_File; // Points to file search pathname
165161
int iFile; // Index of currently retrieved file
166162
#if defined(__WIN__)
167-
//_finddata_t FileData; // Find data structure
163+
PVAL Dvalp; // Used to retrieve file date values
168164
WIN32_FIND_DATA FileData; // Find data structure
169165
HANDLE hSearch; // Search handle
170166
char Drive[_MAX_DRIVE]; // Drive name
@@ -195,14 +191,6 @@ class TDBSDR : public TDBDIR {
195191
// Constructors
196192
TDBSDR(PDIRDEF tdp) : TDBDIR(tdp) {Sub = NULL;}
197193
TDBSDR(PSZ fpat) : TDBDIR(fpat) {Sub = NULL;}
198-
TDBSDR(PTDBSDR tdbp);
199-
200-
// Implementation
201-
virtual PTDB Duplicate(PGLOBAL g)
202-
{return (PTDB)new(g) TDBSDR(this);}
203-
204-
// Methods
205-
virtual PTDB Clone(PTABS t);
206194

207195
// Database routines
208196
virtual int GetMaxSize(PGLOBAL g);
@@ -249,9 +237,10 @@ class DIRCOL : public COLBLK {
249237
// Default constructor not to be used
250238
DIRCOL(void) {}
251239
#if defined(__WIN__)
252-
void SetTimeValue(PGLOBAL g, FILETIME& ftime) { Value->Reset(); }
240+
void SetTimeValue(PGLOBAL g, FILETIME& ftime);
253241
#endif // __WIN__
254242

255243
// Members
244+
PTDBDIR Tdbp; // To DIR table
256245
int N; // Column number
257246
}; // end of class DIRCOL

0 commit comments

Comments
 (0)