mirror of https://github.com/sysown/proxysql
parent
eba8a890a3
commit
940d55c701
@ -1,6 +0,0 @@
|
||||
client1
|
||||
client2
|
||||
client3
|
||||
client4
|
||||
client5
|
||||
client6
|
||||
@ -1,79 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
DEPS_PATH=../../deps
|
||||
|
||||
MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client
|
||||
MARIADB_IDIR=$(MARIADB_PATH)/include
|
||||
MARIADB_LDIR=$(MARIADB_PATH)/libmariadb
|
||||
|
||||
|
||||
DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon
|
||||
DAEMONPATH_IDIR=$(DAEMONPATH)
|
||||
DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs
|
||||
|
||||
JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc
|
||||
JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc
|
||||
JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib
|
||||
|
||||
LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9
|
||||
LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib
|
||||
LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs
|
||||
|
||||
LIBEVENT_PATH=$(DEPS_PATH)/libevent/libevent
|
||||
LIBEVENT_IDIR=$(LIBEVENT_PATH)/include
|
||||
LIBEVENT_LDIR=$(LIBEVENT_PATH)/.libs
|
||||
|
||||
RE2_PATH=$(DEPS_PATH)/re2/re2
|
||||
RE2_IDIR=$(RE2_PATH)
|
||||
|
||||
SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3
|
||||
|
||||
IDIR=../../include
|
||||
LDIR=../../lib
|
||||
IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) -I$(RE2_IDIR)
|
||||
LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(LIBEVENT_LDIR) -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR)
|
||||
|
||||
|
||||
MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb
|
||||
LDFLAGS+=
|
||||
MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK)
|
||||
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
MYLIBS+= -ldl
|
||||
endif
|
||||
ifeq ($(UNAME_S),FreeBSD)
|
||||
MYLIBS+= -lexecinfo
|
||||
endif
|
||||
|
||||
LIBPROXYSQLAR=$(LDIR)/libproxysql.a
|
||||
|
||||
.PHONY: default
|
||||
default: client1
|
||||
|
||||
client1: client1.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client2: client2.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client3: client3.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client4: client4.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client5: client5.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client6: client6.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
|
||||
default: $(EXECUTABLE)
|
||||
|
||||
clean:
|
||||
rm -f *~ core $(default)
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
|
||||
|
||||
static int wait_for_mysql(MYSQL *mysql, int status) {
|
||||
struct pollfd pfd;
|
||||
int timeout, res;
|
||||
|
||||
pfd.fd = mysql_get_socket(mysql);
|
||||
pfd.events =
|
||||
(status & MYSQL_WAIT_READ ? POLLIN : 0) |
|
||||
(status & MYSQL_WAIT_WRITE ? POLLOUT : 0) |
|
||||
(status & MYSQL_WAIT_EXCEPT ? POLLPRI : 0);
|
||||
// if (status & MYSQL_WAIT_TIMEOUT)
|
||||
// timeout = 1000*mysql_get_timeout_value(mysql);
|
||||
// else
|
||||
timeout = -1;
|
||||
res = poll(&pfd, 1, timeout);
|
||||
if (res == 0)
|
||||
return MYSQL_WAIT_TIMEOUT;
|
||||
else if (res < 0)
|
||||
return MYSQL_WAIT_TIMEOUT;
|
||||
else {
|
||||
int status = 0;
|
||||
if (pfd.revents & POLLIN) status |= MYSQL_WAIT_READ;
|
||||
if (pfd.revents & POLLOUT) status |= MYSQL_WAIT_WRITE;
|
||||
if (pfd.revents & POLLPRI) status |= MYSQL_WAIT_EXCEPT;
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
// initialize mysql
|
||||
mysql_library_init(0,NULL,NULL);
|
||||
|
||||
MYSQL *mysql=mysql_init(NULL);
|
||||
mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0);
|
||||
MYSQL *ret_mysql=NULL;
|
||||
int async_exit_status=0;
|
||||
my_bool ret_bool;
|
||||
async_exit_status=mysql_real_connect_start(&ret_mysql,mysql,"127.0.0.1","msandbox","msandbox","information_schema",21891,NULL,0);
|
||||
while (async_exit_status) {
|
||||
async_exit_status=wait_for_mysql(mysql, async_exit_status);
|
||||
async_exit_status=mysql_real_connect_cont(&ret_mysql, mysql, async_exit_status);
|
||||
}
|
||||
if (ret_mysql==NULL) {
|
||||
fprintf(stderr, "Failed to connect, error: %s\n", mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
async_exit_status=mysql_change_user_start(&ret_bool, mysql,"msandbox2","msandbox2","information_schema");
|
||||
while (async_exit_status) {
|
||||
async_exit_status=wait_for_mysql(mysql, async_exit_status);
|
||||
async_exit_status=mysql_change_user_cont(&ret_bool, mysql, async_exit_status);
|
||||
}
|
||||
if (ret_bool==TRUE) {
|
||||
fprintf(stderr, "Failed to change user, error: %s\n", mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// if (!mysql_real_connect(mysql,"127.0.0.1","msandbox","msandbox","information_schema",21891,NULL,0)) {
|
||||
// fprintf(stderr, "Failed to connect, error: %s\n", mysql_error(mysql));
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
// if (mysql_change_user(mysql,"msandbox2","msandbox2","information_schema")) {
|
||||
// fprintf(stderr, "Failed to change user, error: %s\n", mysql_error(mysql));
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
client1
|
||||
client2
|
||||
client3
|
||||
client4
|
||||
client5
|
||||
client6
|
||||
@ -1,79 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
DEPS_PATH=../../deps
|
||||
|
||||
MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client
|
||||
MARIADB_IDIR=$(MARIADB_PATH)/include
|
||||
MARIADB_LDIR=$(MARIADB_PATH)/libmariadb
|
||||
|
||||
|
||||
DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon
|
||||
DAEMONPATH_IDIR=$(DAEMONPATH)
|
||||
DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs
|
||||
|
||||
JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc
|
||||
JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc
|
||||
JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib
|
||||
|
||||
LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9
|
||||
LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib
|
||||
LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs
|
||||
|
||||
LIBEVENT_PATH=$(DEPS_PATH)/libevent/libevent
|
||||
LIBEVENT_IDIR=$(LIBEVENT_PATH)/include
|
||||
LIBEVENT_LDIR=$(LIBEVENT_PATH)/.libs
|
||||
|
||||
RE2_PATH=$(DEPS_PATH)/re2/re2
|
||||
RE2_IDIR=$(RE2_PATH)
|
||||
|
||||
SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3
|
||||
|
||||
IDIR=../../include
|
||||
LDIR=../../lib
|
||||
IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR)
|
||||
LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(LIBEVENT_LDIR) -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR)
|
||||
|
||||
|
||||
MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb
|
||||
LDFLAGS+=
|
||||
MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK)
|
||||
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
MYLIBS+= -ldl
|
||||
endif
|
||||
ifeq ($(UNAME_S),FreeBSD)
|
||||
MYLIBS+= -lexecinfo
|
||||
endif
|
||||
|
||||
LIBPROXYSQLAR=$(LDIR)/libproxysql.a
|
||||
|
||||
.PHONY: default
|
||||
default: client1
|
||||
|
||||
client1: client1.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client2: client2.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client3: client3.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client4: client4.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client5: client5.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client6: client6.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
|
||||
default: $(EXECUTABLE)
|
||||
|
||||
clean:
|
||||
rm -f *~ core $(default)
|
||||
|
||||
@ -1,135 +0,0 @@
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <thread>
|
||||
|
||||
#define QUERY1 "SELECT ?"
|
||||
#define NUMPREP 100000
|
||||
#define NUMPRO 1000
|
||||
#define NTHREADS 8
|
||||
|
||||
int shutdown_test=0;
|
||||
|
||||
typedef struct _thread_data_t {
|
||||
std::thread *thread;
|
||||
MYSQL *mysql;
|
||||
MYSQL_STMT **stmt;
|
||||
} thread_data_t;
|
||||
|
||||
|
||||
thread_data_t **GloThrData;
|
||||
|
||||
void * mysql_thread(int tid) {
|
||||
std::thread::id this_id = std::this_thread::get_id();
|
||||
std::hash<std::thread::id> hasher;
|
||||
std::mt19937 mt_rand(time(0)*hasher(this_id));
|
||||
MYSQL *mysql=mysql_init(NULL);
|
||||
if (!mysql_real_connect(mysql,"127.0.0.1","admin","admin","main",6032,NULL,0)) {
|
||||
fprintf(stderr, "Failed to connect: Error: %s\n", mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
char *query=NULL;
|
||||
while (__sync_fetch_and_add(&shutdown_test,0)==0) {
|
||||
if ((uint32_t)mt_rand()%10) { // reconnect
|
||||
mysql_close(mysql);
|
||||
mysql=mysql_init(NULL);
|
||||
if (!mysql_real_connect(mysql,"127.0.0.1","msandbox","msandbox",NULL,6033,NULL,0)) {
|
||||
fprintf(stderr, "Failed to connect: Error: %s\n", mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
query=(char *)"SELECT 1";
|
||||
if (mysql_query(mysql,query)) {
|
||||
fprintf(stderr, "Failed to run query: \"%s\" . Error: %s\n", query, mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
MYSQL_RES *result = mysql_store_result(mysql);
|
||||
mysql_free_result(result);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void * setup_admin() {
|
||||
std::thread::id this_id = std::this_thread::get_id();
|
||||
std::hash<std::thread::id> hasher;
|
||||
std::mt19937 mt_rand(time(0)*hasher(this_id));
|
||||
bool multiplex[2] = {false,false};
|
||||
bool hashed[2] = {false,false};
|
||||
MYSQL *mysql=mysql_init(NULL);
|
||||
if (!mysql_real_connect(mysql,"127.0.0.1","admin","admin","main",6032,NULL,0)) {
|
||||
fprintf(stderr, "Failed to connect to admin : Error: %s\n", mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
char *query=NULL;
|
||||
while (__sync_fetch_and_add(&shutdown_test,0)==0) {
|
||||
usleep(1000000);
|
||||
multiplex[0]=multiplex[1];
|
||||
if ((uint32_t)mt_rand()%2) {
|
||||
query=(char *)"SET mysql-multiplexing='true'";
|
||||
multiplex[1]=true;
|
||||
} else {
|
||||
query=(char *)"SET mysql-multiplexing='false'";
|
||||
multiplex[1]=false;
|
||||
}
|
||||
if (multiplex[0]!=multiplex[1]) {
|
||||
if (mysql_query(mysql,query)) {
|
||||
fprintf(stderr, "Failed to run query to admin : \"%s\" . Error: %s\n", query, mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
query=(char *)"LOAD MYSQL VARIABLES TO RUNTIME";
|
||||
if (mysql_query(mysql,query)) {
|
||||
fprintf(stderr, "Failed to run query to admin : \"%s\" . Error: %s\n", query, mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
usleep(100000);
|
||||
hashed[0]=hashed[1];
|
||||
if ((uint32_t)mt_rand()%2) {
|
||||
query=(char *)"UPDATE mysql_users SET password='msandbox' WHERE username='msandbox'";
|
||||
hashed[1]=false;
|
||||
} else {
|
||||
query=(char *)"UPDATE mysql_users SET password='*6c387fc3893dba1e3ba155e74754da6682d04747' WHERE username='msandbox'";
|
||||
hashed[1]=true;
|
||||
}
|
||||
if (hashed[0]!=hashed[1]) {
|
||||
if (mysql_query(mysql,query)) {
|
||||
fprintf(stderr, "Failed to run query to admin : \"%s\" . Error: %s\n", query, mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
query=(char *)"LOAD MYSQL USERS TO RUNTIME";
|
||||
if (mysql_query(mysql,query)) {
|
||||
fprintf(stderr, "Failed to run query to admin : \"%s\" . Error: %s\n", query, mysql_error(mysql));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// initialize mysql
|
||||
mysql_library_init(0,NULL,NULL);
|
||||
|
||||
// create a new MySQL_STMT_Manager()
|
||||
//GloMyStmt=new MySQL_STMT_Manager();
|
||||
|
||||
std::thread *admin_thread=new std::thread(&setup_admin);
|
||||
|
||||
GloThrData = (thread_data_t **)malloc(sizeof(thread_data_t *)*NTHREADS);
|
||||
// starts N threads
|
||||
int i;
|
||||
|
||||
for (i=0; i<NTHREADS; i++) {
|
||||
GloThrData[i]=(thread_data_t *)malloc(sizeof(thread_data_t));
|
||||
GloThrData[i]->thread = new std::thread(&mysql_thread,i);
|
||||
}
|
||||
sleep(30);
|
||||
__sync_fetch_and_add(&shutdown_test,1);
|
||||
admin_thread->join();
|
||||
// wait for the threads to complete
|
||||
for (i=0; i<NTHREADS; i++) {
|
||||
GloThrData[i]->thread->join();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
static unsigned int g_seed;
|
||||
|
||||
|
||||
inline void fast_srand( int seed ) {
|
||||
g_seed = seed;
|
||||
}
|
||||
inline int fastrand() {
|
||||
g_seed = (214013*g_seed+2531011);
|
||||
return (g_seed>>16)&0x7FFF;
|
||||
}
|
||||
|
||||
static char _s[128];
|
||||
|
||||
void gen_random_stdstring(string *s, const int len) {
|
||||
//char *_s=(char *)alloca(len+1);
|
||||
static const char alphanum[] =
|
||||
"0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
for (int i = 0; i < len; ++i) {
|
||||
_s[i] = alphanum[fastrand() % (sizeof(alphanum) - 1)];
|
||||
}
|
||||
_s[len] = '\0';
|
||||
*s=string(_s);
|
||||
//return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char * gen_random_string(const int len) {
|
||||
char *s=(char *)malloc(len+1);
|
||||
static const char alphanum[] =
|
||||
"0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
s[i] = alphanum[fastrand() % (sizeof(alphanum) - 1)];
|
||||
}
|
||||
|
||||
s[len] = 0;
|
||||
return s;
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
#include "polygon.hpp"
|
||||
#include <iostream>
|
||||
#include <dlfcn.h>
|
||||
|
||||
class Query_Cache;
|
||||
|
||||
int main() {
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
|
||||
// load the triangle library
|
||||
/*
|
||||
void* QC = dlopen("../lib/Shared_Query_Cache.so", RTLD_LAZY);
|
||||
if (!QC) {
|
||||
cerr << "Cannot load library: " << dlerror() << " " << errno << '\n';
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
void* triangle = dlopen("./triangle.so", RTLD_LAZY);
|
||||
if (!triangle) {
|
||||
cerr << "Cannot load library: " << dlerror() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
// reset errors
|
||||
dlerror();
|
||||
|
||||
// load the symbols
|
||||
create_t* create_triangle = (create_t*) dlsym(triangle, "create");
|
||||
const char* dlsym_error = dlerror();
|
||||
if (dlsym_error) {
|
||||
cerr << "Cannot load symbol create: " << dlsym_error << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
destroy_t* destroy_triangle = (destroy_t*) dlsym(triangle, "destroy");
|
||||
dlsym_error = dlerror();
|
||||
if (dlsym_error) {
|
||||
cerr << "Cannot load symbol destroy: " << dlsym_error << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
// create an instance of the class
|
||||
polygon* poly = create_triangle();
|
||||
|
||||
// use the class
|
||||
poly->set_side_length(7);
|
||||
cout << "The area is: " << poly->area() << '\n';
|
||||
|
||||
// destroy the class
|
||||
destroy_triangle(poly);
|
||||
|
||||
// unload the triangle library
|
||||
dlclose(triangle);
|
||||
}
|
||||
Binary file not shown.
@ -1,26 +0,0 @@
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
long monotonic_time() {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
return (((long) ts.tv_sec) * 1000000) + (ts.tv_nsec / 1000);
|
||||
}
|
||||
|
||||
|
||||
#define LOOPS 10000000
|
||||
|
||||
int main() {
|
||||
volatile int i;
|
||||
volatile long l;
|
||||
struct timespec req;
|
||||
req.tv_sec=0;
|
||||
req.tv_nsec=1;
|
||||
for (i=0;i<LOOPS;i++) {
|
||||
//usleep(1);
|
||||
//nanosleep(&req, NULL);
|
||||
l=monotonic_time();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
client1
|
||||
client2
|
||||
client3
|
||||
client4
|
||||
client5
|
||||
client6
|
||||
@ -1,79 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
DEPS_PATH=../../deps
|
||||
|
||||
MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client
|
||||
MARIADB_IDIR=$(MARIADB_PATH)/include
|
||||
MARIADB_LDIR=$(MARIADB_PATH)/libmariadb
|
||||
|
||||
|
||||
DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon
|
||||
DAEMONPATH_IDIR=$(DAEMONPATH)
|
||||
DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs
|
||||
|
||||
JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc
|
||||
JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc
|
||||
JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib
|
||||
|
||||
LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9
|
||||
LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib
|
||||
LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs
|
||||
|
||||
LIBEVENT_PATH=$(DEPS_PATH)/libevent/libevent
|
||||
LIBEVENT_IDIR=$(LIBEVENT_PATH)/include
|
||||
LIBEVENT_LDIR=$(LIBEVENT_PATH)/.libs
|
||||
|
||||
RE2_PATH=$(DEPS_PATH)/re2/re2
|
||||
RE2_IDIR=$(RE2_PATH)
|
||||
|
||||
SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3
|
||||
|
||||
IDIR=../../include
|
||||
LDIR=../../lib
|
||||
IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR) -I$(RE2_IDIR)
|
||||
LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(LIBEVENT_LDIR) -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR)
|
||||
|
||||
|
||||
MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb
|
||||
LDFLAGS+=
|
||||
MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK)
|
||||
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
MYLIBS+= -ldl
|
||||
endif
|
||||
ifeq ($(UNAME_S),FreeBSD)
|
||||
MYLIBS+= -lexecinfo
|
||||
endif
|
||||
|
||||
LIBPROXYSQLAR=$(LDIR)/libproxysql.a
|
||||
|
||||
.PHONY: default
|
||||
default: client1
|
||||
|
||||
client1: client1.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client2: client2.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client3: client3.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client4: client4.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client5: client5.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
client6: client6.cpp
|
||||
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
|
||||
default: $(EXECUTABLE)
|
||||
|
||||
clean:
|
||||
rm -f *~ core $(default)
|
||||
|
||||
@ -1,34 +0,0 @@
|
||||
#include "re2/re2.h"
|
||||
#include "re2/regexp.h"
|
||||
#include "proxysql.h"
|
||||
#include "cpp.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <thread>
|
||||
|
||||
struct __RE2_objects_t {
|
||||
re2::RE2::Options *opt;
|
||||
RE2 *re;
|
||||
};
|
||||
|
||||
typedef struct __RE2_objects_t re2_t;
|
||||
|
||||
int main() {
|
||||
re2_t *r=(re2_t *)malloc(sizeof(re2_t));
|
||||
r->opt=new re2::RE2::Options(RE2::Quiet);
|
||||
r->opt->set_case_sensitive(false);
|
||||
//char *myq=(char *)" sEt NAmEs 'utf8' ";
|
||||
char *myq=(char *)"sEt NAmEs 'utf8' ";
|
||||
r->re=new RE2(" *SET *NAMES *.* *", *r->opt);
|
||||
bool rc;
|
||||
for (int i=0;i<100000;i++) {
|
||||
string *new_query=new std::string(myq);
|
||||
rc=RE2::PartialMatch(myq,*r->re);
|
||||
//RE2::Replace(new_query,(char *)" *(\\w+) *(.*) *(.*) *",(char *)"\1 \2 \3 a");
|
||||
RE2::Replace(new_query,(char *)" *(\\w+)\\s+(\\w+)\\s+(\\w+)\\s*",(char *)"\\1 \\2 \\3");
|
||||
//std::cout << new_query->c_str() << std::endl;
|
||||
delete new_query;
|
||||
}
|
||||
printf("%d\n",rc);
|
||||
return 0;
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
setparsertest
|
||||
@ -1,62 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
DEPS_PATH=../../deps
|
||||
|
||||
RE2_PATH=$(DEPS_PATH)/re2/re2
|
||||
RE2_IDIR=$(RE2_PATH)
|
||||
|
||||
MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client
|
||||
MARIADB_IDIR=$(MARIADB_PATH)/include
|
||||
MARIADB_LDIR=$(MARIADB_PATH)/libmariadb
|
||||
|
||||
DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon
|
||||
DAEMONPATH_IDIR=$(DAEMONPATH)
|
||||
DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs
|
||||
|
||||
JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc
|
||||
JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc
|
||||
JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib
|
||||
|
||||
LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9
|
||||
LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib
|
||||
LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs
|
||||
|
||||
SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3
|
||||
|
||||
IDIR=../../include
|
||||
LDIR=../../lib
|
||||
IDIRS=-I$(IDIR) -I$(RE2_IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR)
|
||||
LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR)
|
||||
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
IDIRS+= -I/usr/local/opt/openssl/include
|
||||
endif
|
||||
|
||||
LIBPROXYSQLAR=$(LDIR)/libproxysql.a
|
||||
|
||||
MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb
|
||||
LDFLAGS+=
|
||||
MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lproxysql -ldaemon -ljemalloc -lre2 -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK)
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
MYLIBS=-lre2 -lpthread -lm -lz -liconv
|
||||
endif
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
MYLIBS+= -ldl
|
||||
endif
|
||||
ifeq ($(UNAME_S),FreeBSD)
|
||||
MYLIBS+= -lexecinfo
|
||||
endif
|
||||
|
||||
.PHONY: default
|
||||
default: setparsertest
|
||||
|
||||
setparsertest: setparsertest.cpp $(RE2_PATH)/util/test.cc $(LDIR)/set_parser.cpp $(LIBPROXYSQLAR)
|
||||
$(CXX) -o $@ $@.cpp $(RE2_PATH)/util/test.cc $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
|
||||
|
||||
clean:
|
||||
rm -f *~ core $(default)
|
||||
|
||||
@ -1,211 +0,0 @@
|
||||
#include "re2/re2.h"
|
||||
#include "re2/regexp.h"
|
||||
#include "util/test.h"
|
||||
#include "set_parser.h"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
int remove_spaces(const char *s) {
|
||||
char *inp = (char *)s, *outp = (char *)s;
|
||||
bool prev_space = false;
|
||||
bool fns = false;
|
||||
while (*inp) {
|
||||
if (isspace(*inp)) {
|
||||
if (fns) {
|
||||
if (!prev_space) {
|
||||
*outp++ = ' ';
|
||||
prev_space = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*outp++ = *inp;
|
||||
prev_space = false;
|
||||
if (!fns) fns=true;
|
||||
}
|
||||
++inp;
|
||||
}
|
||||
if (outp>s) {
|
||||
if (prev_space) {
|
||||
outp--;
|
||||
}
|
||||
}
|
||||
*outp = '\0';
|
||||
return strlen(s);
|
||||
}
|
||||
|
||||
bool iequals(const string& a, const string& b)
|
||||
{
|
||||
unsigned int sz = a.size();
|
||||
if (b.size() != sz)
|
||||
return false;
|
||||
for (unsigned int i = 0; i < sz; ++i)
|
||||
if (tolower(a[i]) != tolower(b[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void printMap(const char* prefix, const std::map<std::string, std::vector<std::string>>& dict)
|
||||
{
|
||||
std::cout << prefix << ": ";
|
||||
for(auto mapIt = begin(dict); mapIt != end(dict); ++mapIt)
|
||||
{
|
||||
std::cout << mapIt->first << " : ";
|
||||
|
||||
for(auto c : mapIt->second)
|
||||
{
|
||||
std::cout << c << " ";
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
struct Expected {
|
||||
const char* var;
|
||||
std::vector<std::string> values;
|
||||
Expected(const char* var, std::vector<std::string> values): var(var), values(values){};
|
||||
};
|
||||
|
||||
struct Test {
|
||||
const char* query;
|
||||
std::vector<Expected> results;
|
||||
};
|
||||
|
||||
static Test sql_mode[] = {
|
||||
{ "SET @@sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } },
|
||||
{ "SET SESSION sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } },
|
||||
{ "SET @@session.sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } },
|
||||
{ "SET sql_mode = 'TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } },
|
||||
{ "SET SQL_MODE ='TRADITIONAL'", { Expected("sql_mode", {"TRADITIONAL"}) } },
|
||||
{ "SET SQL_MODE = \"TRADITIONAL\"", { Expected("sql_mode", {"TRADITIONAL"}) } },
|
||||
{ "SET SQL_MODE = TRADITIONAL", { Expected("sql_mode", {"TRADITIONAL"}) } },
|
||||
{ "set sql_mode = IFNULL(NULL,\"STRICT_TRANS_TABLES\")", { Expected("sql_mode", {"IFNULL(NULL,\"STRICT_TRANS_TABLES\")"}) } },
|
||||
{ "set sql_mode = IFNULL(NULL,'STRICT_TRANS_TABLES')", { Expected("sql_mode", {"IFNULL(NULL,'STRICT_TRANS_TABLES')"}) } },
|
||||
{ "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')", { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')"}) } },
|
||||
{ "set session sql_mode = 'ONLY_FULL_GROUP_BY'" , { Expected("sql_mode", {"ONLY_FULL_GROUP_BY"}) } },
|
||||
{ "SET sql_mode = 'NO_ZERO_DATE,STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY'" , { Expected("sql_mode", {"NO_ZERO_DATE,STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY"}) } },
|
||||
{ "SET @@sql_mode = CONCAT(@@sql_mode, ',', 'ONLY_FULL_GROUP_BY')" , { Expected("sql_mode", {"CONCAT(@@sql_mode, ',', 'ONLY_FULL_GROUP_BY')"}) } },
|
||||
{ "SET @@sql_mode = REPLACE(REPLACE(REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')" , { Expected("sql_mode", {"REPLACE(REPLACE(REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')"}) } },
|
||||
{ "SET @@sql_mode = REPLACE( REPLACE( REPLACE( @@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')" , { Expected("sql_mode", {"REPLACE( REPLACE( REPLACE( @@sql_mode, 'ONLY_FULL_GROUP_BY,', ''),',ONLY_FULL_GROUP_BY', ''),'ONLY_FULL_GROUP_BY', '')"}) } },
|
||||
// { "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')", { Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ', STRICT_ALL_TABLES'), ', NO_AUTO_VALUE_ON_ZERO')"}) } },
|
||||
{ "SET SQL_MODE=IFNULL(@@sql_mode,'')", { Expected("sql_mode", { "IFNULL(@@sql_mode,'')" } ) } },
|
||||
{ "SET SQL_MODE=IFNULL(@old_sql_mode,'')", { Expected("sql_mode", { "IFNULL(@old_sql_mode,'')" } ) } },
|
||||
{ "SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')", { Expected("sql_mode", { "IFNULL(@OLD_SQL_MODE,'')" } ) } },
|
||||
};
|
||||
|
||||
void TestParse(const Test* tests, int ntests, const string& title) {
|
||||
for (int i = 0; i < ntests; i++) {
|
||||
std::map<std::string, std::vector<std::string>> data;
|
||||
for(auto it = std::begin(tests[i].results); it != std::end(tests[i].results); ++it) {
|
||||
data[it->var] = it->values;
|
||||
}
|
||||
|
||||
SetParser parser(tests[i].query);
|
||||
std::map<std::string, std::vector<std::string>> result = parser.parse1();
|
||||
|
||||
// printMap("result", result);
|
||||
// printMap("expected", data);
|
||||
|
||||
CHECK_EQ(result.size(), data.size());
|
||||
CHECK(std::equal(std::begin(result), std::end(result), std::begin(data)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(TestParse, SET_SQL_MODE) {
|
||||
TestParse(sql_mode, arraysize(sql_mode), "sql_mode");
|
||||
}
|
||||
|
||||
static Test time_zone[] = {
|
||||
{ "SET @@time_zone = 'Europe/Paris'", { Expected("time_zone", {"Europe/Paris"}) } },
|
||||
{ "SET @@time_zone = '+00:00'", { Expected("time_zone", {"+00:00"}) } },
|
||||
{ "SET @@time_zone = \"Europe/Paris\"", { Expected("time_zone", {"Europe/Paris"}) } },
|
||||
{ "SET @@time_zone = \"+00:00\"", { Expected("time_zone", {"+00:00"}) } },
|
||||
{ "SET @@time_zone = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } },
|
||||
{ "SET @@TIME_ZONE = @OLD_TIME_ZONE", { Expected("time_zone", {"@OLD_TIME_ZONE"}) } },
|
||||
};
|
||||
|
||||
TEST(TestParse, SET_TIME_ZONE) {
|
||||
TestParse(time_zone, arraysize(time_zone), "time_zone");
|
||||
}
|
||||
|
||||
static Test session_track_gtids[] = {
|
||||
{ "SET @@session_track_gtids = OFF", { Expected("session_track_gtids", {"OFF"}) } },
|
||||
{ "SET @@session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } },
|
||||
{ "SET @@SESSION.session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } },
|
||||
{ "SET SESSION session_track_gtids = OWN_GTID", { Expected("session_track_gtids", {"OWN_GTID"}) } },
|
||||
{ "SET @@session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } },
|
||||
{ "SET @@SESSION.session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } },
|
||||
{ "SET SESSION session_track_gtids = ALL_GTIDS", { Expected("session_track_gtids", {"ALL_GTIDS"}) } },
|
||||
};
|
||||
|
||||
TEST(TestParse, SET_SESSION_TRACK_GTIDS) {
|
||||
TestParse(session_track_gtids, arraysize(session_track_gtids), "session_track_gtids");
|
||||
}
|
||||
|
||||
static Test character_set_results[] = {
|
||||
{ "SET @@character_set_results = utf8", { Expected("character_set_results", {"utf8"}) } },
|
||||
{ "SET @@character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } },
|
||||
{ "SET character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } },
|
||||
{ "SET @@session.character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } },
|
||||
{ "SET session character_set_results = NULL", { Expected("character_set_results", {"NULL"}) } },
|
||||
};
|
||||
|
||||
TEST(TestParse, SET_CHARACTER_SET_RESULTS) {
|
||||
TestParse(character_set_results, arraysize(character_set_results), "character_set_results");
|
||||
}
|
||||
|
||||
static Test names[] = {
|
||||
{ "SET NAMES utf8", { Expected("names", {"utf8"}) } },
|
||||
{ "SET NAMES 'utf8'", { Expected("names", {"utf8"}) } },
|
||||
{ "SET NAMES \"utf8\"", { Expected("names", {"utf8"}) } },
|
||||
{ "SET NAMES utf8 COLLATE unicode_ci", { Expected("names", {"utf8", "unicode_ci"}) } },
|
||||
};
|
||||
|
||||
TEST(TestParse, SET_NAMES) {
|
||||
TestParse(names, arraysize(names), "names");
|
||||
}
|
||||
static Test various[] = {
|
||||
{ "SET @@SESSION.SQL_SELECT_LIMIT= DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } },
|
||||
{ "SET @@SQL_SELECT_LIMIT= DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } },
|
||||
{ "SET SESSION SQL_SELECT_LIMIT = DEFAULT", { Expected("sql_select_limit", {"DEFAULT"}) } },
|
||||
{ "SET @@SESSION.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } },
|
||||
{ "SET @@SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } },
|
||||
{ "SET SESSION SQL_SELECT_LIMIT = 1234", { Expected("sql_select_limit", {"1234"}) } },
|
||||
{ "SET @@SESSION.SQL_SELECT_LIMIT= 1234", { Expected("sql_select_limit", {"1234"}) } },
|
||||
{ "SET @@SESSION.SQL_SELECT_LIMIT= @old_sql_select_limit", { Expected("sql_select_limit", {"@old_sql_select_limit"}) } },
|
||||
{ "SET SQL_SELECT_LIMIT= @old_sql_select_limit", { Expected("sql_select_limit", {"@old_sql_select_limit"}) } },
|
||||
{ "SET @@SESSION.sql_auto_is_null = 0", { Expected("sql_auto_is_null", {"0"}) } },
|
||||
{ "SET SESSION sql_auto_is_null = 1", { Expected("sql_auto_is_null", {"1"}) } },
|
||||
{ "SET sql_auto_is_null = OFF", { Expected("sql_auto_is_null", {"OFF"}) } },
|
||||
{ "SET @@sql_auto_is_null = ON", { Expected("sql_auto_is_null", {"ON"}) } },
|
||||
{ "SET @@SESSION.sql_safe_updates = 0", { Expected("sql_safe_updates", {"0"}) } },
|
||||
{ "SET SESSION sql_safe_updates = 1", { Expected("sql_safe_updates", {"1"}) } },
|
||||
{ "SET SQL_SAFE_UPDATES = OFF", { Expected("sql_safe_updates", {"OFF"}) } },
|
||||
{ "SET @@sql_safe_updates = ON", { Expected("sql_safe_updates", {"ON"}) } },
|
||||
};
|
||||
|
||||
TEST(TestParse, SET_VARIOUS) {
|
||||
TestParse(various, arraysize(various), "various");
|
||||
}
|
||||
|
||||
static Test multiple[] = {
|
||||
{ "SET time_zone = 'Europe/Paris', sql_mode = 'TRADITIONAL'", { Expected("time_zone", {"Europe/Paris"}), Expected("sql_mode", {"TRADITIONAL"}) } },
|
||||
{ "SET time_zone = 'Europe/Paris', sql_mode = IFNULL(NULL,\"STRICT_TRANS_TABLES\")", { Expected("time_zone", {"Europe/Paris"}), Expected("sql_mode", {"IFNULL(NULL,\"STRICT_TRANS_TABLES\")"}) } },
|
||||
{ "SET sql_mode = 'TRADITIONAL', NAMES 'utf8 COLLATE 'unicode_ci'", { Expected("sql_mode", {"TRADITIONAL"}), Expected("names", {"utf8", "unicode_ci"}) } },
|
||||
{ "SET @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483",
|
||||
{ Expected("sql_mode", {"CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}),
|
||||
Expected("wait_timeout", {"2147483"}) } },
|
||||
{ "set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')", { Expected("autocommit", {"1"}), Expected("sql_mode", {"concat(@@sql_mode,',STRICT_TRANS_TABLES')"}) } },
|
||||
{ "SET NAMES utf8, @@SESSION.sql_mode = CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600",
|
||||
{ Expected("names", {"utf8"}), Expected("sql_mode", {"CONCAT(REPLACE(REPLACE(REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''), 'STRICT_ALL_TABLES', ''), 'TRADITIONAL', ''), ',NO_AUTO_VALUE_ON_ZERO')"}), Expected("sql_auto_is_null", {"0"}),
|
||||
Expected("wait_timeout", {"3600"}) } },
|
||||
{ "set autocommit=1, session_track_schema=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES'), @@SESSION.net_write_timeout=7200", { Expected("autocommit", {"1"}), Expected("session_track_schema", {"1"}), Expected("sql_mode", {"concat(@@sql_mode,',STRICT_TRANS_TABLES')"}),
|
||||
Expected("net_write_timeout", {"7200"}) } },
|
||||
};
|
||||
|
||||
TEST(TestParse, MULTIPLE) {
|
||||
TestParse(multiple, arraysize(multiple), "multiple");
|
||||
}
|
||||
Loading…
Reference in new issue