Commit f772ed74 authored by Olivier Bertrand's avatar Olivier Bertrand

- FIX MDEV-4853 + another bug causing the whole section to be deleted

  when deleting one key of a INI table with layout=Row. The same happens
  for layout=column but this is normal as one line is one section.

modified:
  storage/connect/tabsys.cpp

- Should fix a valgrind warning in CHRBLK::GetValPtrEx

modified:
  storage/connect/valblk.cpp
parent bce59293
...@@ -36,7 +36,9 @@ ...@@ -36,7 +36,9 @@
#include "global.h" #include "global.h"
#include "plgdbsem.h" #include "plgdbsem.h"
#include "reldef.h" #include "reldef.h"
//#include "xobject.h" #if !defined(WIN32)
#include "osutil.h"
#endif // !WIN32
#include "filamtxt.h" #include "filamtxt.h"
#include "tabdos.h" #include "tabdos.h"
#include "tabsys.h" #include "tabsys.h"
...@@ -320,7 +322,11 @@ int TDBINI::DeleteDB(PGLOBAL g, int irc) ...@@ -320,7 +322,11 @@ int TDBINI::DeleteDB(PGLOBAL g, int irc)
break; break;
case RC_FX: case RC_FX:
while (ReadDB(g) == RC_OK) while (ReadDB(g) == RC_OK)
WritePrivateProfileString(Section, NULL, NULL, Ifile); if (!WritePrivateProfileString(Section, NULL, NULL, Ifile)) {
sprintf(g->Message, "Error %d accessing %s",
GetLastError(), Ifile);
return RC_FX;
} // endif
break; break;
default: default:
...@@ -328,7 +334,11 @@ int TDBINI::DeleteDB(PGLOBAL g, int irc) ...@@ -328,7 +334,11 @@ int TDBINI::DeleteDB(PGLOBAL g, int irc)
strcpy(g->Message, MSG(NO_SECTION_NAME)); strcpy(g->Message, MSG(NO_SECTION_NAME));
return RC_FX; return RC_FX;
} else } else
WritePrivateProfileString(Section, NULL, NULL, Ifile); if (!WritePrivateProfileString(Section, NULL, NULL, Ifile)) {
sprintf(g->Message, "Error %d accessing %s",
GetLastError(), Ifile);
return RC_FX;
} // endif rc
} // endswitch irc } // endswitch irc
...@@ -461,13 +471,13 @@ void INICOL::ReadColumn(PGLOBAL g) ...@@ -461,13 +471,13 @@ void INICOL::ReadColumn(PGLOBAL g)
Valbuf[Long] = '\0'; Valbuf[Long] = '\0';
break; break;
default: default:
GetPrivateProfileString(tdbp->Section, Name, "", GetPrivateProfileString(tdbp->Section, Name, "\b",
Valbuf, Long + 1, tdbp->Ifile); Valbuf, Long + 1, tdbp->Ifile);
break; break;
} // endswitch Flag } // endswitch Flag
// Missing keys are interpreted as null values // Missing keys are interpreted as null values
if (!strcmp(Valbuf, "")) { if (!strcmp(Valbuf, "\b")) {
if (Nullable) if (Nullable)
Value->SetNull(true); Value->SetNull(true);
...@@ -485,6 +495,7 @@ void INICOL::ReadColumn(PGLOBAL g) ...@@ -485,6 +495,7 @@ void INICOL::ReadColumn(PGLOBAL g)
void INICOL::WriteColumn(PGLOBAL g) void INICOL::WriteColumn(PGLOBAL g)
{ {
char *p; char *p;
bool rc;
PTDBINI tdbp = (PTDBINI)To_Tdb; PTDBINI tdbp = (PTDBINI)To_Tdb;
if (trace > 1) if (trace > 1)
...@@ -510,11 +521,12 @@ void INICOL::WriteColumn(PGLOBAL g) ...@@ -510,11 +521,12 @@ void INICOL::WriteColumn(PGLOBAL g)
if (tdbp->Mode == MODE_UPDATE) { if (tdbp->Mode == MODE_UPDATE) {
strcpy(g->Message, MSG(NO_SEC_UPDATE)); strcpy(g->Message, MSG(NO_SEC_UPDATE));
longjmp(g->jumper[g->jump_level], 31); longjmp(g->jumper[g->jump_level], 31);
} else { } else if (*p) {
tdbp->Section = p; tdbp->Section = p;
return; } else
} // endif Mode tdbp->Section = NULL;
return;
} else if (!tdbp->Section) { } else if (!tdbp->Section) {
strcpy(g->Message, MSG(SEC_NAME_FIRST)); strcpy(g->Message, MSG(SEC_NAME_FIRST));
longjmp(g->jumper[g->jump_level], 31); longjmp(g->jumper[g->jump_level], 31);
...@@ -523,8 +535,16 @@ void INICOL::WriteColumn(PGLOBAL g) ...@@ -523,8 +535,16 @@ void INICOL::WriteColumn(PGLOBAL g)
/*********************************************************************/ /*********************************************************************/
/* Updating must be done only when not in checking pass. */ /* Updating must be done only when not in checking pass. */
/*********************************************************************/ /*********************************************************************/
if (Status) if (Status) {
WritePrivateProfileString(tdbp->Section, Name, p, tdbp->Ifile); rc = WritePrivateProfileString(tdbp->Section, Name, p, tdbp->Ifile);
if (!rc) {
sprintf(g->Message, "Error %d writing to %s",
GetLastError(), tdbp->Ifile);
longjmp(g->jumper[g->jump_level], 31);
} // endif rc
} // endif Status
} // end of WriteColumn } // end of WriteColumn
...@@ -724,14 +744,21 @@ int TDBXIN::DeleteDB(PGLOBAL g, int irc) ...@@ -724,14 +744,21 @@ int TDBXIN::DeleteDB(PGLOBAL g, int irc)
if (irc == RC_EF) { if (irc == RC_EF) {
} else if (irc == RC_FX) { } else if (irc == RC_FX) {
for (Section = Seclist; *Section; Section += (strlen(Section) + 1)) for (Section = Seclist; *Section; Section += (strlen(Section) + 1))
WritePrivateProfileString(Section, NULL, NULL, Ifile); if (!WritePrivateProfileString(Section, NULL, NULL, Ifile)) {
sprintf(g->Message, "Error %d accessing %s",
GetLastError(), Ifile);
return RC_FX;
} // endif
} else if (Section) { } else if (!Section) {
WritePrivateProfileString(Section, Keycur, NULL, Ifile);
} else {
strcpy(g->Message, MSG(NO_SECTION_NAME)); strcpy(g->Message, MSG(NO_SECTION_NAME));
return RC_FX; return RC_FX;
} // endif's } else
if (!WritePrivateProfileString(Section, Keycur, NULL, Ifile)) {
sprintf(g->Message, "Error %d accessing %s",
GetLastError(), Ifile);
return RC_FX;
} // endif
return RC_OK; return RC_OK;
} // end of DeleteDB } // end of DeleteDB
...@@ -792,6 +819,7 @@ void XINCOL::ReadColumn(PGLOBAL g) ...@@ -792,6 +819,7 @@ void XINCOL::ReadColumn(PGLOBAL g)
void XINCOL::WriteColumn(PGLOBAL g) void XINCOL::WriteColumn(PGLOBAL g)
{ {
char *p; char *p;
bool rc;
PTDBXIN tdbp = (PTDBXIN)To_Tdb; PTDBXIN tdbp = (PTDBXIN)To_Tdb;
if (trace > 1) if (trace > 1)
...@@ -813,20 +841,22 @@ void XINCOL::WriteColumn(PGLOBAL g) ...@@ -813,20 +841,22 @@ void XINCOL::WriteColumn(PGLOBAL g)
if (tdbp->Mode == MODE_UPDATE) { if (tdbp->Mode == MODE_UPDATE) {
strcpy(g->Message, MSG(NO_SEC_UPDATE)); strcpy(g->Message, MSG(NO_SEC_UPDATE));
longjmp(g->jumper[g->jump_level], 31); longjmp(g->jumper[g->jump_level], 31);
} else { } else if (*p) {
tdbp->Section = p; tdbp->Section = p;
return; } else
} // endif Mode tdbp->Section = NULL;
return;
} else if (Flag == 2) { } else if (Flag == 2) {
if (tdbp->Mode == MODE_UPDATE) { if (tdbp->Mode == MODE_UPDATE) {
strcpy(g->Message, MSG(NO_KEY_UPDATE)); strcpy(g->Message, MSG(NO_KEY_UPDATE));
longjmp(g->jumper[g->jump_level], 31); longjmp(g->jumper[g->jump_level], 31);
} else { } else if (*p) {
tdbp->Keycur = p; tdbp->Keycur = p;
return; } else
} // endif Mode tdbp->Keycur = NULL;
return;
} else if (!tdbp->Section || !tdbp->Keycur) { } else if (!tdbp->Section || !tdbp->Keycur) {
strcpy(g->Message, MSG(SEC_KEY_FIRST)); strcpy(g->Message, MSG(SEC_KEY_FIRST));
longjmp(g->jumper[g->jump_level], 31); longjmp(g->jumper[g->jump_level], 31);
...@@ -835,8 +865,16 @@ void XINCOL::WriteColumn(PGLOBAL g) ...@@ -835,8 +865,16 @@ void XINCOL::WriteColumn(PGLOBAL g)
/*********************************************************************/ /*********************************************************************/
/* Updating must be done only when not in checking pass. */ /* Updating must be done only when not in checking pass. */
/*********************************************************************/ /*********************************************************************/
if (Status) if (Status) {
WritePrivateProfileString(tdbp->Section, tdbp->Keycur, p, tdbp->Ifile); rc = WritePrivateProfileString(tdbp->Section, tdbp->Keycur, p, tdbp->Ifile);
if (!rc) {
sprintf(g->Message, "Error %d writing to %s",
GetLastError(), tdbp->Ifile);
longjmp(g->jumper[g->jump_level], 31);
} // endif rc
} // endif Status
} // end of WriteColumn } // end of WriteColumn
......
...@@ -712,7 +712,7 @@ void *CHRBLK::GetValPtrEx(int n) ...@@ -712,7 +712,7 @@ void *CHRBLK::GetValPtrEx(int n)
// For VCT blocks we must remove rightmost blanks. // For VCT blocks we must remove rightmost blanks.
char *p = Valp + Long; char *p = Valp + Long;
for (p--; *p == ' ' && p >= Valp; p--) ; for (p--; p >= Valp && *p == ' '; p--) ;
*(++p) = '\0'; *(++p) = '\0';
} // endif Blanks } // endif Blanks
......
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