Skip to content

Commit

Permalink
Fix MDEV-7890
Browse files Browse the repository at this point in the history
  • Loading branch information
Buggynours committed Apr 4, 2015
1 parent 836740c commit 05b30fb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
30 changes: 17 additions & 13 deletions storage/connect/ha_connect.cc
Expand Up @@ -2173,12 +2173,12 @@ int ha_connect::CheckRecord(PGLOBAL g, const uchar *oldbuf, uchar *newbuf)
/***********************************************************************/
/* Return the where clause for remote indexed read. */
/***********************************************************************/
bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q,
bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL op, char q,
const void *key, int klen)
{
const uchar *ptr;
uint rem, len, stlen; //, prtlen;
bool nq, b= false;
bool nq, oom, b= false;
Field *fp;
KEY *kfp;
KEY_PART_INFO *kpart;
Expand All @@ -2190,7 +2190,7 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q,
return true;
} // endif key

strcat(qry, " WHERE (");
oom= qry->Append(" WHERE (");
kfp= &table->key_info[active_index];
rem= kfp->user_defined_key_parts,
len= klen,
Expand All @@ -2203,42 +2203,44 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q,
nq= fp->str_needs_quotes();

if (b)
strcat(qry, " AND ");
oom|= qry->Append(" AND ");
else
b= true;

strcat(strncat(strcat(qry, q), fp->field_name, strlen(fp->field_name)), q);
oom|= qry->Append(q);
oom|= qry->Append((PSZ)fp->field_name);
oom|= qry->Append(q);

switch (op) {
case OP_EQ:
case OP_GT:
case OP_GE:
strcat(qry, GetValStr(op, false));
oom|= qry->Append((PSZ)GetValStr(op, false));
break;
default:
strcat(qry, " ??? ");
oom|= qry->Append(" ??? ");
} // endwitch op

if (nq)
strcat(qry, "'");
oom|= qry->Append('\'');

if (kpart->key_part_flag & HA_VAR_LENGTH_PART) {
String varchar;
uint var_length= uint2korr(ptr);

varchar.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH,
var_length, &my_charset_bin);
strncat(qry, varchar.ptr(), varchar.length());
oom|= qry->Append(varchar.ptr(), varchar.length());
} else {
char strbuff[MAX_FIELD_WIDTH];
String str(strbuff, sizeof(strbuff), kpart->field->charset()), *res;

res= fp->val_str(&str, ptr);
strncat(qry, res->ptr(), res->length());
oom|= qry->Append(res->ptr(), res->length());
} // endif flag

if (nq)
strcat(qry, "'");
oom|= qry->Append('\'');

if (stlen >= len)
break;
Expand All @@ -2251,8 +2253,10 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q,
ptr+= stlen - MY_TEST(kpart->null_bit);
} // endfor kpart

strcat(qry, ")");
return false;
if ((oom|= qry->Append(")")))
strcpy(g->Message, "Out of memory");

return oom;
} // end of MakeKeyWhere


Expand Down
2 changes: 1 addition & 1 deletion storage/connect/ha_connect.h
Expand Up @@ -235,7 +235,7 @@ class ha_connect: public handler
int CheckRecord(PGLOBAL g, const uchar *oldbuf, uchar *newbuf);
int ReadIndexed(uchar *buf, OPVAL op, const uchar* key= NULL,
uint key_len= 0);
bool MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q,
bool MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL op, char q,
const void *key, int klen);
inline char *Strz(LEX_STRING &ls);

Expand Down
3 changes: 1 addition & 2 deletions storage/connect/tabmysql.cpp
Expand Up @@ -1078,8 +1078,7 @@ bool TDBMYSQL::ReadKey(PGLOBAL g, OPVAL op, const void *key, int len)
if (Myc.m_Res)
Myc.FreeResult();

To_Def->GetHandler()->MakeKeyWhere(g, Query->GetStr(),
op, "`", key, len);
To_Def->GetHandler()->MakeKeyWhere(g, Query, op, '`', key, len);

if (To_CondFil) {
oom = Query->Append(" AND (");
Expand Down
28 changes: 28 additions & 0 deletions storage/connect/xobject.cpp
Expand Up @@ -289,6 +289,34 @@ bool STRING::Set(char *s, uint n)
return false;
} // end of Set

/***********************************************************************/
/* Append a char* to a STRING. */
/***********************************************************************/
bool STRING::Append(const char *s, uint ln)
{
if (!s)
return false;

uint len = Length + ln + 1;

if (len > Size) {
char *p = Realloc(len);

if (!p)
return true;
else if (p != Strp) {
strcpy(p, Strp);
Strp = p;
} // endif p

} // endif n

strncpy(Strp + Length, s, ln);
Length = len - 1;
Strp[Length] = 0;
return false;
} // end of Append

/***********************************************************************/
/* Append a PSZ to a STRING. */
/***********************************************************************/
Expand Down
1 change: 1 addition & 0 deletions storage/connect/xobject.h
Expand Up @@ -134,6 +134,7 @@ class DllExport STRING : public BLOCK {
inline void Reset(void) {*Strp = 0;}
bool Set(PSZ s);
bool Set(char *s, uint n);
bool Append(const char *s, uint ln);
bool Append(PSZ s);
bool Append(STRING &str);
bool Append(char c);
Expand Down

0 comments on commit 05b30fb

Please sign in to comment.