test executable now works

This commit is contained in:
Markus Makela
2014-09-24 12:25:53 +03:00
parent 4d6bcdbfc1
commit 1cf3fa367c

View File

@ -8,11 +8,12 @@
#include <unistd.h> #include <unistd.h>
static char* server_options[] = { static char* server_options[] = {
"SkySQL Gateway", "SkySQL Gateway",
"--datadir=./", "--no-defaults",
"--language=./", "--datadir=.",
"--skip-innodb", "--language=.",
"--default-storage-engine=myisam", "--skip-innodb",
"--default-storage-engine=myisam",
NULL NULL
}; };
@ -27,12 +28,14 @@ static char* server_groups[] = {
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
GWBUF* gwbuff; int rd = 0,buffsz = getpagesize(),strsz = 0;
int rd = 0,buffsz = getpagesize(),strsz = buffsz;
char buffer[buffsz], *strbuff = (char*)calloc(buffsz,sizeof(char)); char buffer[buffsz], *strbuff = (char*)calloc(buffsz,sizeof(char));
while((rd = fread(buffer,sizeof(char),buffsize,stdin))){ mysql_library_init(num_elements, server_options, server_groups);
while((rd = fread(buffer,sizeof(char),buffsz,stdin))){
/**Fill the read buffer*/
if(strsz + rd >= buffsz){ if(strsz + rd >= buffsz){
char* tmp = (char*)calloc((buffsz*2),sizeof(char)); char* tmp = (char*)calloc((buffsz*2),sizeof(char));
@ -47,13 +50,102 @@ int main(int argc, char** argv)
} }
memcpy(strbuff+strsz,buffer,rd); memcpy(strbuff+strsz,buffer,rd);
querysz += rd; strsz += rd;
}
if(querysz > 0){ char *tok,*nlptr;
printf("%s",strbuff);
free(strbuff);
}
/**Remove newlines*/
while((nlptr = strpbrk(strbuff,"\n")) != NULL && (nlptr - strbuff) < strsz){
memmove(nlptr,nlptr+1,strsz - (nlptr + 1 - strbuff));
strsz -= 1;
}
/**Parse read buffer for full queries*/
while(strpbrk(strbuff,";") != NULL){
tok = strpbrk(strbuff,";");
int qlen = tok - strbuff;
GWBUF* buff = gwbuf_alloc(qlen+5);
*((unsigned char*)(buff->start)) = qlen;
*((unsigned char*)(buff->start + 1)) = (qlen >> 8);
*((unsigned char*)(buff->start + 2)) = (qlen >> 16);
*((unsigned char*)(buff->start + 3)) = 0x00;
*((unsigned char*)(buff->start + 4)) = 0x03;
memcpy(buff->start+5, strbuff, qlen);
memmove(strbuff,tok + 1, strsz - qlen);
strsz -= qlen;
memset(strbuff + strsz,0,buffsz - strsz);
skygw_query_type_t type = query_classifier_get_type(buff);
if(type == QUERY_TYPE_UNKNOWN){
printf("QUERY_TYPE_UNKNOWN ");
}
if(type & QUERY_TYPE_LOCAL_READ){
printf("QUERY_TYPE_LOCAL_READ ");
}
if(type & QUERY_TYPE_READ){
printf("QUERY_TYPE_READ ");
}
if(type & QUERY_TYPE_WRITE){
printf("QUERY_TYPE_WRITE ");
}
if(type & QUERY_TYPE_MASTER_READ){
printf("QUERY_TYPE_MASTER_READ ");
}
if(type & QUERY_TYPE_SESSION_WRITE){
printf("QUERY_TYPE_SESSION_WRITE ");
}
if(type & QUERY_TYPE_USERVAR_READ){
printf("QUERY_TYPE_USERVAR_READ ");
}
if(type & QUERY_TYPE_SYSVAR_READ){
printf("QUERY_TYPE_SYSVAR_READ ");
}
if(type & QUERY_TYPE_GSYSVAR_READ){
printf("QUERY_TYPE_GSYSVAR_READ ");
}
if(type & QUERY_TYPE_GSYSVAR_WRITE){
printf("QUERY_TYPE_GSYSVAR_WRITE ");
}
if(type & QUERY_TYPE_BEGIN_TRX){
printf("QUERY_TYPE_BEGIN_TRX ");
}
if(type & QUERY_TYPE_ENABLE_AUTOCOMMIT){
printf("QUERY_TYPE_ENABLE_AUTOCOMMIT ");
}
if(type & QUERY_TYPE_DISABLE_AUTOCOMMIT){
printf("QUERY_TYPE_DISABLE_AUTOCOMMIT ");
}
if(type & QUERY_TYPE_ROLLBACK){
printf("QUERY_TYPE_ROLLBACK ");
}
if(type & QUERY_TYPE_COMMIT){
printf("QUERY_TYPE_COMMIT ");
}
if(type & QUERY_TYPE_PREPARE_NAMED_STMT){
printf("QUERY_TYPE_PREPARE_NAMED_STMT ");
}
if(type & QUERY_TYPE_PREPARE_STMT){
printf("QUERY_TYPE_PREPARE_STMT ");
}
if(type & QUERY_TYPE_EXEC_STMT){
printf("QUERY_TYPE_EXEC_STMT ");
}
if(type & QUERY_TYPE_CREATE_TMP_TABLE){
printf("QUERY_TYPE_CREATE_TMP_TABLE ");
}
if(type & QUERY_TYPE_READ_TMP_TABLE){
printf("QUERY_TYPE_READ_TMP_TABLE ");
}
printf("\n");
gwbuf_free(buff);
}
}
free(strbuff);
return 0; return 0;
} }