Merge pull request #885 from liquidata-inc/tim/cpp-mysql-client-tests

Tim/cpp mysql client tests
This commit is contained in:
Tim Sehn
2020-09-16 11:58:23 -07:00
committed by GitHub
10 changed files with 165 additions and 0 deletions

3
.gitmodules vendored
View File

@@ -10,3 +10,6 @@
[submodule "proto/third_party/grpc-go"]
path = proto/third_party/grpc-go
url = https://github.com/grpc/grpc-go.git
[submodule "mysql-client-tests/cpp/third_party/mysql-connector-cpp"]
path = mysql-client-tests/cpp/third_party/mysql-connector-cpp
url = https://github.com/mysql/mysql-connector-cpp.git

View File

@@ -21,6 +21,9 @@ RUN apt install -y \
bats \
perl \
cpanminus \
cmake \
g++ \
libmysqlcppconn-dev \
git
# install go

View File

@@ -1,2 +1,4 @@
mysql-client-tests/c/mysql-client-tests
mysql-client-tests/java/MySQLConnectorTest.class
mysql-client-tests/cpp/_build/**/*
mysql-client-tests/cpp/_build

View File

@@ -1,4 +1,5 @@
c/mysql-connector-c-test
cpp/_build
java/MySQLConnectorTest.class
java/mysql-connector-java-8.0.21.jar
node/node_modules/

View File

@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.10)
project(DoltCxxConnectorTest
VERSION 0.1
DESCRIPTION "A smoke test for mysql-connector-c++ connecting to Dolt"
LANGUAGES CXX)
add_executable(test_mysql_connector_cxx mysql-connector-cpp-test.cpp)
set_property(TARGET test_mysql_connector_cxx PROPERTY CXX_STANDARD 11)
if(WITH_JDBC)
add_subdirectory(third_party/mysql-connector-cpp EXCLUDE_FROM_ALL)
target_link_libraries(test_mysql_connector_cxx connector-jdbc)
else()
find_library(LIBMYSQLCPPCONN "mysqlcppconn")
target_link_libraries(test_mysql_connector_cxx "${LIBMYSQLCPPCONN}")
endif()

View File

@@ -0,0 +1,14 @@
MYSQL_CONCPP_DIR = /usr/local/Cellar/mysql-connector-c++/8.0.21
CPPFLAGS = -I $(MYSQL_CONCPP_DIR)/include -L $(MYSQL_CONCPP_DIR)/lib64
LDLIBS = -lmysqlcppconn8
CXX = clang++ -stdlib=libc++
CXXFLAGS = -std=c++11
all: mysql-connector-cpp-test
mysql-connector-cpp-test: mysql-connector-cpp-test.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ $^ $(LDLIBS)
.PHONY: clean
clean:
rm -f mysql-connector-cpp-test

View File

@@ -0,0 +1,28 @@
# General
This code uses git submodules. You need to recursively pull all the submodules
in order for it to build.
# Building on OS X
```sh
$ brew install cmake openssl mysql-client boost
$ export PATH=/usr/local/Cellar/mysql-client/8.0.21/bin/:"$PATH"
$ mkdir _build
$ cd _build
$ cmake .. -DWITH_SSL=/usr/local/Cellar/openssl@1.1/1.1.1g/ -DWITH_JDBC=yes
$ make -j 10
```
TODO: These instructions are coupled to openssl and mysql-client version that
happen to be installed...
# Build on Ubuntu / Debian
```sh
$ apt-get install g++ cmake libmysqlcppconn-dev
$ mkdir _build
$ cd _build
$ cmake ..
$ make -j 10
```

View File

@@ -0,0 +1,77 @@
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include "mysql_driver.h"
#include "mysql_connection.h"
#include "mysql_error.h"
#include "cppconn/connection.h"
#include "cppconn/build_config.h"
#include "cppconn/resultset.h"
#include "cppconn/sqlstring.h"
#include "cppconn/config.h"
#include "cppconn/datatype.h"
#include "cppconn/version_info.h"
#include "cppconn/driver.h"
#include "cppconn/statement.h"
#include "cppconn/metadata.h"
#include "cppconn/warning.h"
#include "cppconn/resultset_metadata.h"
#include "cppconn/parameter_metadata.h"
#include "cppconn/exception.h"
#include "cppconn/prepared_statement.h"
#include "cppconn/variant.h"
#define QUERIES_SIZE 5
std::string queries[QUERIES_SIZE] =
{
"create table test (pk int, value int, primary key(pk))",
"describe test",
"select * from test",
"insert into test (pk, value) values (0,0)",
"select * from test"
};
int is_update[QUERIES_SIZE] = {0,0,0,1,0};
int main(int argc, char **argv) {
std::string user = argv[1];
std::string port = argv[2];
std::string db = argv[3];
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:" + port, user, "");
con->setSchema(db);
for ( int i = 0; i < QUERIES_SIZE; i++ ) {
try {
sql::Statement *stmt = con->createStatement();
if ( is_update[i] ) {
int affected_rows = stmt->executeUpdate(queries[i]);
} else {
sql::ResultSet *res = stmt->executeQuery(queries[i]);
delete res;
}
delete stmt;
} catch (sql::SQLException &e) {
std::cout << "QUERY: " << queries[i] << std::endl;
std::cout << "# ERR: " << e.what();
std::cout << " (MySQL error code: " << e.getErrorCode();
std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
return 1;
}
}
delete con;
return 0;
}

View File

@@ -57,6 +57,25 @@ teardown() {
$BATS_TEST_DIRNAME/c/mysql-connector-c-test $USER $PORT $REPO_NAME
}
@test "cpp mysql connector" {
if [ -d $BATS_TEST_DIRNAME/cpp/_build ]
then
rm -rf $BATS_TEST_DIRNAME/cpp/_build/*
else
mkdir $BATS_TEST_DIRNAME/cpp/_build
fi
cd $BATS_TEST_DIRNAME/cpp/_build
if [[ `uname` = "Darwin" ]]; then
PATH=/usr/local/Cellar/mysql-client/8.0.21/bin/:"$PATH" cmake .. -DWITH_SSL=/usr/local/Cellar/openssl@1.1/1.1.1g/ -DWITH_JDBC=yes;
else
cmake ..
fi
cmake ..
make -j 10
$BATS_TEST_DIRNAME/cpp/_build/test_mysql_connector_cxx $USER $PORT $REPO_NAME
cd -
}
@test "dotnet mysql connector" {
cd $BATS_TEST_DIRNAME/dotnet/
# dotnet run uses output channel 3 which conflicts with bats so we pipe it to null