diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2013-03-02 17:58:18 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2013-03-02 17:58:18 +0100 |
commit | 5972b56a6d43aceb89e5242b6c323743eba9c71e (patch) | |
tree | 9cb05cd22e464d31e8d3d0d42f890b9d18f68c08 | |
parent | 8c8fe2f3a62191d0d3e835242c08c23906478099 (diff) | |
download | mariadb-git-5972b56a6d43aceb89e5242b6c323743eba9c71e.tar.gz |
- Fix conversion bug for MS-DOM XML tables. The node content was written
and read as if the table DATA_CHARSET was ANSI instead of UTF-8. Warning
are now provided when the read content of a node is truncated.
modified:
storage/connect/domdoc.cpp
storage/connect/domdoc.h
storage/connect/libdoc.cpp
storage/connect/libdoc.h
storage/connect/plgxml.h
storage/connect/tabxml.cpp
- Conditional compilation of pre_create depending on the MARIADB setting.
modified:
storage/connect/ha_connect.cc
storage/connect/ha_connect.h
-rw-r--r-- | storage/connect/domdoc.cpp | 41 | ||||
-rw-r--r-- | storage/connect/domdoc.h | 2 | ||||
-rw-r--r-- | storage/connect/ha_connect.cc | 4 | ||||
-rw-r--r-- | storage/connect/ha_connect.h | 4 | ||||
-rw-r--r-- | storage/connect/libdoc.cpp | 32 | ||||
-rw-r--r-- | storage/connect/libdoc.h | 2 | ||||
-rw-r--r-- | storage/connect/plgxml.h | 2 | ||||
-rw-r--r-- | storage/connect/tabxml.cpp | 31 |
8 files changed, 91 insertions, 27 deletions
diff --git a/storage/connect/domdoc.cpp b/storage/connect/domdoc.cpp index 48aef29d6d8..95426be97bc 100644 --- a/storage/connect/domdoc.cpp +++ b/storage/connect/domdoc.cpp @@ -295,16 +295,41 @@ PXNODE DOMNODE::GetChild(PGLOBAL g) /******************************************************************/ /* Return the content of a node and subnodes. */ /******************************************************************/ -char *DOMNODE::GetText(char *buf, int len) +RCODE DOMNODE::GetContent(PGLOBAL g, char *buf, int len) { + RCODE rc = RC_OK; + // Nodep can be null for a missing HTML table column - if (Nodep) - strncpy(buf, Nodep->text, len); - else + if (Nodep) { + if (!WideCharToMultiByte(CP_UTF8, 0, Nodep->text, -1, + buf, len, NULL, NULL)) { + DWORD lsr = GetLastError(); + + switch (lsr) { + case 0: + case ERROR_INSUFFICIENT_BUFFER: // 122L + sprintf(g->Message, "Truncated %s content", GetName(g)); + rc = RC_INFO; + break; + case ERROR_NO_UNICODE_TRANSLATION: // 1113L + sprintf(g->Message, "Invalid character(s) in %s content", + GetName(g)); + rc = RC_INFO; + break; + default: + sprintf(g->Message, "System error getting %s content", + GetName(g)); + rc = RC_FX; + break; + } // endswitch + + } // endif + + } else *buf = '\0'; - return buf; - } // end of GetText + return rc; + } // end of GetContent /******************************************************************/ /* Set the text content of an attribute. */ @@ -319,8 +344,8 @@ bool DOMNODE::SetContent(PGLOBAL g, char *txtp, int len) Len = len; } // endif len - if (!MultiByteToWideChar(CP_ACP, 0, txtp, strlen(txtp) + 1, - Ws, Len + 1)) { + if (!MultiByteToWideChar(CP_UTF8, 0, txtp, strlen(txtp) + 1, + Ws, Len + 1)) { sprintf(g->Message, MSG(WS_CONV_ERR), txtp); return true; } // endif diff --git a/storage/connect/domdoc.h b/storage/connect/domdoc.h index e025ee13fc6..fc157950df8 100644 --- a/storage/connect/domdoc.h +++ b/storage/connect/domdoc.h @@ -71,7 +71,7 @@ class DOMNODE : public XMLNODE { virtual PXNODE GetChild(PGLOBAL g); // Methods - virtual char *GetText(char *buf, int len); + virtual RCODE GetContent(PGLOBAL g, char *buf, int len); virtual bool SetContent(PGLOBAL g, char *txtp, int len); virtual PXNODE Clone(PGLOBAL g, PXNODE np); virtual PXLIST GetChildElements(PGLOBAL g, char *xp, PXLIST lp); diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 44924aa1995..48935985317 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -153,7 +153,7 @@ extern "C" char nmfile[]; extern "C" char pdebug[]; extern "C" { - char version[]= "Version 1.01.0002 February 19, 2013"; + char version[]= "Version 1.01.0003 March 02, 2013"; #if defined(XMSG) char msglang[]; // Default message language @@ -3195,6 +3195,7 @@ ha_rows ha_connect::records_in_range(uint inx, key_range *min_key, DBUG_RETURN(rows); } // end of records_in_range +#if defined(MARIADB) /** Convert an ISO-8859-1 column name to UTF-8 */ @@ -3657,6 +3658,7 @@ bool ha_connect::pre_create(THD *thd, HA_CREATE_INFO *create_info, my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); return true; } // end of pre_create +#endif // MARIADB /** @brief diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h index 19013a923c7..2bf5154c274 100644 --- a/storage/connect/ha_connect.h +++ b/storage/connect/ha_connect.h @@ -335,7 +335,9 @@ const char *GetValStr(OPVAL vop, bool neg); ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); int delete_table(const char *from); +#if defined(MARIADB) bool pre_create(THD *thd, HA_CREATE_INFO *crt_info, void *alt_info); +#endif // MARIADB int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); ///< required bool check_if_incompatible_data(HA_CREATE_INFO *info, @@ -347,6 +349,7 @@ const char *GetValStr(OPVAL vop, bool neg); protected: char *GetListOption(const char *opname, const char *oplist, const char *def= NULL); +#if defined(MARIADB) char *encode(PGLOBAL g, char *cnm); bool add_fields(THD *thd, void *alter_info, LEX_STRING *field_name, @@ -361,6 +364,7 @@ protected: // uint uint_geom_type, void *vcol_info, engine_option_value *create_options); +#endif // MARIADB // Members static ulong num; // Tracable handler number diff --git a/storage/connect/libdoc.cpp b/storage/connect/libdoc.cpp index e094f935c80..95b98931680 100644 --- a/storage/connect/libdoc.cpp +++ b/storage/connect/libdoc.cpp @@ -463,8 +463,10 @@ PXNODE XML2NODE::GetChild(PGLOBAL g) /******************************************************************/ /* Return the content of a node and subnodes. */ /******************************************************************/ -char *XML2NODE::GetText(char *buf, int len) +RCODE XML2NODE::GetContent(PGLOBAL g, char *buf, int len) { + RCODE rc = RC_OK; + if (Content) xmlFree(Content); @@ -474,18 +476,24 @@ char *XML2NODE::GetText(char *buf, int len) bool b = false; // Copy content eliminating extra characters - for (; *p1 && (p2 - buf) < len; p1++) - if (strchr(extra, *p1)) { - if (b) { - // This to have one blank between sub-nodes - *p2++ = ' '; - b = false; - } // endif b + for (; *p1; p1++) + if ((p2 - buf) < len) { + if (strchr(extra, *p1)) { + if (b) { + // This to have one blank between sub-nodes + *p2++ = ' '; + b = false; + } // endif b + + } else { + *p2++ = *p1; + b = true; + } // endif p1 } else { - *p2++ = *p1; - b = true; - } // endif p1 + sprintf(g->Message, "Truncated %s content", Nodep->name); + rc = RC_INFO; + } // endif len *p2 = 0; @@ -497,7 +505,7 @@ char *XML2NODE::GetText(char *buf, int len) } else *buf = '\0'; - return buf; + return rc; } // end of GetText /******************************************************************/ diff --git a/storage/connect/libdoc.h b/storage/connect/libdoc.h index d34431e254a..97f97f99ccc 100644 --- a/storage/connect/libdoc.h +++ b/storage/connect/libdoc.h @@ -80,7 +80,7 @@ class XML2NODE : public XMLNODE { virtual PXNODE GetChild(PGLOBAL g); // Methods - virtual char *GetText(char *buf, int len); + virtual RCODE GetContent(PGLOBAL g, char *buf, int len); virtual bool SetContent(PGLOBAL g, char *txtp, int len); virtual PXNODE Clone(PGLOBAL g, PXNODE np); virtual PXLIST GetChildElements(PGLOBAL g, char *xp, PXLIST lp); diff --git a/storage/connect/plgxml.h b/storage/connect/plgxml.h index a1d25e6b581..8fc95eabef7 100644 --- a/storage/connect/plgxml.h +++ b/storage/connect/plgxml.h @@ -110,7 +110,7 @@ class XMLNODE : public BLOCK { virtual PXNODE GetChild(PGLOBAL) = 0; // Methods - virtual char *GetText(char *, int) = 0; + virtual RCODE GetContent(PGLOBAL, char *, int) = 0; virtual bool SetContent(PGLOBAL, char *, int) = 0; virtual PXNODE Clone(PGLOBAL, PXNODE) = 0; virtual PXLIST GetChildElements(PGLOBAL, char * = NULL, PXLIST = NULL) = 0; diff --git a/storage/connect/tabxml.cpp b/storage/connect/tabxml.cpp index be1c4925268..0040ee93fa9 100644 --- a/storage/connect/tabxml.cpp +++ b/storage/connect/tabxml.cpp @@ -1212,7 +1212,16 @@ void XMLCOL::ReadColumn(PGLOBAL g) } // endif type // Get the Xname value from the XML file - ValNode->GetText(Valbuf, Long); + switch (ValNode->GetContent(g, Valbuf, Long + 1)) { + case RC_OK: + break; + case RC_INFO: + PushWarning(g, Tdbp); + break; + default: + longjmp(g->jumper[g->jump_level], TYPE_AM_XML); + } // endswitch + } else *Valbuf = '\0'; @@ -1405,7 +1414,15 @@ void XMULCOL::ReadColumn(PGLOBAL g) } // endif type // Get the Xname value from the XML file - ValNode->GetText(p, len); + switch (ValNode->GetContent(g, p, len + 1)) { + case RC_OK: + break; + case RC_INFO: + PushWarning(g, Tdbp); + break; + default: + longjmp(g->jumper[g->jump_level], TYPE_AM_XML); + } // endswitch if (!Tdbp->Xpand) { // Concatenate all values @@ -1627,7 +1644,15 @@ void XPOSCOL::ReadColumn(PGLOBAL g) if ((ValNode = Tdbp->Clist->GetItem(g, Rank, Vxnp))) // Get the column value from the XML file - ValNode->GetText(Valbuf, Long); + switch (ValNode->GetContent(g, Valbuf, Long + 1)) { + case RC_OK: + break; + case RC_INFO: + PushWarning(g, Tdbp); + break; + default: + longjmp(g->jumper[g->jump_level], TYPE_AM_XML); + } // endswitch Value->SetValue_psz(Valbuf); Nx = Tdbp->Irow; |