Added GWBUF type GWBUF_TYPE_SINGLE_STMT to indicate that buffer only includes single complete stmt. Added macro for checking the flag and changed existing routines as necessary.

This commit is contained in:
VilhoRaatikka
2014-06-24 21:51:54 +03:00
parent 619aeb4afa
commit 442ac7fefb
2 changed files with 29 additions and 27 deletions

View File

@ -185,30 +185,28 @@ GWBUF *gwbuf_clone_transform(
goto return_clonebuf; goto return_clonebuf;
} }
switch (src_type) if (GWBUF_IS_TYPE_MYSQL(head))
{ {
case GWBUF_TYPE_MYSQL: if (GWBUF_TYPE_PLAINSQL == targettype)
if (targettype == GWBUF_TYPE_PLAINSQL) {
{ /** Crete reference to string part of buffer */
/** Crete reference to string part of buffer */ clonebuf = gwbuf_clone_portion(
clonebuf = gwbuf_clone_portion( head,
head, 5,
5, GWBUF_LENGTH(head)-5);
GWBUF_LENGTH(head)-5); ss_dassert(clonebuf != NULL);
ss_dassert(clonebuf != NULL); /** Overwrite the type with new format */
/** Overwrite the type with new format */ gwbuf_set_type(clonebuf, targettype);
clonebuf->gwbuf_type = targettype; }
} else
else {
{
clonebuf = NULL;
}
break;
default:
clonebuf = NULL; clonebuf = NULL;
break; }
} /*< switch (src_type) */ }
else
{
clonebuf = NULL;
}
return_clonebuf: return_clonebuf:
return clonebuf; return clonebuf;
@ -308,6 +306,7 @@ bool gwbuf_set_type(
case GWBUF_TYPE_MYSQL: case GWBUF_TYPE_MYSQL:
case GWBUF_TYPE_PLAINSQL: case GWBUF_TYPE_PLAINSQL:
case GWBUF_TYPE_UNDEFINED: case GWBUF_TYPE_UNDEFINED:
case GWBUF_TYPE_SINGLE_STMT: /*< buffer contains one stmt */
buf->gwbuf_type |= type; buf->gwbuf_type |= type;
succp = true; succp = true;
break; break;

View File

@ -46,13 +46,16 @@
typedef enum typedef enum
{ {
GWBUF_TYPE_UNDEFINED = 0x00, GWBUF_TYPE_UNDEFINED = 0x00,
GWBUF_TYPE_PLAINSQL = 0x01, GWBUF_TYPE_PLAINSQL = 0x01,
GWBUF_TYPE_MYSQL = 0x02 GWBUF_TYPE_MYSQL = 0x02,
GWBUF_TYPE_SINGLE_STMT = 0x04
} gwbuf_type_t; } gwbuf_type_t;
#define GWBUF_IS_TYPE_PLAINSQL(b) (b->gwbuf_type & GWBUF_TYPE_PLAINSQL) #define GWBUF_IS_TYPE_UNDEFINED(b) (b->gwbuf_type == 0)
#define GWBUF_IS_TYPE_MYSQL(b) (b->gwbuf_type & GWBUF_TYPE_MYSQL) #define GWBUF_IS_TYPE_PLAINSQL(b) (b->gwbuf_type & GWBUF_TYPE_PLAINSQL)
#define GWBUF_IS_TYPE_MYSQL(b) (b->gwbuf_type & GWBUF_TYPE_MYSQL)
#define GWBUF_IS_TYPE_SINGLE_STMT(b) (b->gwbuf_type & GWBUF_TYPE_SINGLE_STMT)
/** /**
* A structure to encapsulate the data in a form that the data itself can be * A structure to encapsulate the data in a form that the data itself can be