Commit 3a889b1f authored by Olivier Bertrand's avatar Olivier Bertrand

Fix a bug in init_table_share that caused syntax error with Boolean options:

  oom|= sql->append(vull ? "ON" : "OFF");
  replaced by:
  oom|= sql->append(vull ? "YES" : "NO");
modified:
  ha_connect.cc

Make DBF tables to be usable in big-endian machines (test version)
modified:
  filamdbf.cpp
parent 12bebceb
...@@ -115,6 +115,7 @@ typedef struct _descriptor { ...@@ -115,6 +115,7 @@ typedef struct _descriptor {
/* Side effects: */ /* Side effects: */
/* Moves file pointer to byte 32; fills buffer at buf with */ /* Moves file pointer to byte 32; fills buffer at buf with */
/* first 32 bytes of file. */ /* first 32 bytes of file. */
/* Converts numeric values to platform byte ordering (LE in file) */
/****************************************************************************/ /****************************************************************************/
static int dbfhead(PGLOBAL g, FILE *file, PSZ fn, DBFHEADER *buf) static int dbfhead(PGLOBAL g, FILE *file, PSZ fn, DBFHEADER *buf)
{ {
...@@ -142,6 +143,11 @@ static int dbfhead(PGLOBAL g, FILE *file, PSZ fn, DBFHEADER *buf) ...@@ -142,6 +143,11 @@ static int dbfhead(PGLOBAL g, FILE *file, PSZ fn, DBFHEADER *buf)
} else } else
strcpy(g->Message, MSG(DBASE_FILE)); strcpy(g->Message, MSG(DBASE_FILE));
// Convert numeric fields to have them in platform byte ordering
buf->Records = uint4korr(&buf->Records);
buf->Headlen = uint2korr(&buf->Headlen);
buf->Reclen = uint2korr(&buf->Reclen);
// Check last byte(s) of header // Check last byte(s) of header
if (fseek(file, buf->Headlen - dbc, SEEK_SET) != 0) { if (fseek(file, buf->Headlen - dbc, SEEK_SET) != 0) {
sprintf(g->Message, MSG(BAD_HEADER), fn); sprintf(g->Message, MSG(BAD_HEADER), fn);
...@@ -565,8 +571,8 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g) ...@@ -565,8 +571,8 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g)
header->Filedate[0] = datm->tm_year - 100; header->Filedate[0] = datm->tm_year - 100;
header->Filedate[1] = datm->tm_mon + 1; header->Filedate[1] = datm->tm_mon + 1;
header->Filedate[2] = datm->tm_mday; header->Filedate[2] = datm->tm_mday;
header->Headlen = (ushort)hlen; int2store(&header->Headlen, hlen);
header->Reclen = (ushort)reclen; int2store(&header->Reclen, reclen);
descp = (DESCRIPTOR*)header; descp = (DESCRIPTOR*)header;
// Currently only standard Xbase types are supported // Currently only standard Xbase types are supported
...@@ -729,7 +735,7 @@ bool DBFFAM::CopyHeader(PGLOBAL g) ...@@ -729,7 +735,7 @@ bool DBFFAM::CopyHeader(PGLOBAL g)
if (Headlen) { if (Headlen) {
void *hdr = PlugSubAlloc(g, NULL, Headlen); void *hdr = PlugSubAlloc(g, NULL, Headlen);
size_t n, hlen = (size_t)Headlen; size_t n, hlen = (size_t)Headlen;
int pos = ftell(Stream); int pos = ftell(Stream);
if (fseek(Stream, 0, SEEK_SET)) if (fseek(Stream, 0, SEEK_SET))
strcpy(g->Message, "Seek error in CopyHeader"); strcpy(g->Message, "Seek error in CopyHeader");
...@@ -863,13 +869,14 @@ void DBFFAM::CloseTableFile(PGLOBAL g, bool abort) ...@@ -863,13 +869,14 @@ void DBFFAM::CloseTableFile(PGLOBAL g, bool abort)
if (n > Records) { if (n > Records) {
// Update the number of rows in the file header // Update the number of rows in the file header
char filename[_MAX_PATH]; char filename[_MAX_PATH], nRecords[4];
int4store(&nRecords, n);
PlugSetPath(filename, To_File, Tdbp->GetPath()); PlugSetPath(filename, To_File, Tdbp->GetPath());
if ((Stream= global_fopen(g, MSGID_OPEN_MODE_STRERROR, filename, "r+b"))) if ((Stream= global_fopen(g, MSGID_OPEN_MODE_STRERROR, filename, "r+b")))
{ {
fseek(Stream, 4, SEEK_SET); // Get header.Records position fseek(Stream, 4, SEEK_SET); // Get header.Records position
fwrite(&n, sizeof(int), 1, Stream); fwrite(nRecords, sizeof(nRecords), 1, Stream);
fclose(Stream); fclose(Stream);
Stream= NULL; Stream= NULL;
Records= n; // Update Records value Records= n; // Update Records value
...@@ -944,13 +951,13 @@ bool DBMFAM::AllocateBuffer(PGLOBAL g) ...@@ -944,13 +951,13 @@ bool DBMFAM::AllocateBuffer(PGLOBAL g)
/************************************************************************/ /************************************************************************/
DBFHEADER *hp = (DBFHEADER*)Memory; DBFHEADER *hp = (DBFHEADER*)Memory;
if (Lrecl != (int)hp->Reclen) { if (Lrecl != (int)uint2korr(&hp->Reclen)) {
sprintf(g->Message, MSG(BAD_LRECL), Lrecl, hp->Reclen); sprintf(g->Message, MSG(BAD_LRECL), Lrecl, uint2korr(&hp->Reclen));
return true; return true;
} // endif Lrecl } // endif Lrecl
Records = (int)hp->Records; Records = (int)uint4korr(&hp->Records);
Headlen = (int)hp->Headlen; Headlen = (int)uint2korr(&hp->Headlen);
} // endif Headlen } // endif Headlen
/**************************************************************************/ /**************************************************************************/
......
...@@ -4901,7 +4901,7 @@ static int init_table_share(THD* thd, ...@@ -4901,7 +4901,7 @@ static int init_table_share(THD* thd,
oom|= sql->append(' '); oom|= sql->append(' ');
oom|= sql->append(opt->name); oom|= sql->append(opt->name);
oom|= sql->append('='); oom|= sql->append('=');
oom|= sql->append(vull ? "ON" : "OFF"); oom|= sql->append(vull ? "YES" : "NO");
} // endif vull } // endif vull
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment