mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-11 02:59:34 -06:00
Merge pull request #885 from liquidata-inc/tim/cpp-mysql-client-tests
Tim/cpp mysql client tests
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -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
|
||||
|
||||
@@ -21,6 +21,9 @@ RUN apt install -y \
|
||||
bats \
|
||||
perl \
|
||||
cpanminus \
|
||||
cmake \
|
||||
g++ \
|
||||
libmysqlcppconn-dev \
|
||||
git
|
||||
|
||||
# install go
|
||||
|
||||
@@ -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
|
||||
|
||||
1
mysql-client-tests/.gitignore
vendored
1
mysql-client-tests/.gitignore
vendored
@@ -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/
|
||||
17
mysql-client-tests/cpp/CMakeLists.txt
Normal file
17
mysql-client-tests/cpp/CMakeLists.txt
Normal 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()
|
||||
14
mysql-client-tests/cpp/Makefile
Normal file
14
mysql-client-tests/cpp/Makefile
Normal 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
|
||||
28
mysql-client-tests/cpp/README.md
Normal file
28
mysql-client-tests/cpp/README.md
Normal 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
|
||||
```
|
||||
77
mysql-client-tests/cpp/mysql-connector-cpp-test.cpp
Normal file
77
mysql-client-tests/cpp/mysql-connector-cpp-test.cpp
Normal 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;
|
||||
}
|
||||
1
mysql-client-tests/cpp/third_party/mysql-connector-cpp
vendored
Submodule
1
mysql-client-tests/cpp/third_party/mysql-connector-cpp
vendored
Submodule
Submodule mysql-client-tests/cpp/third_party/mysql-connector-cpp added at 6b2fc10205
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user