diff --git a/CMakeLists.txt b/CMakeLists.txt index 82acc83fc446db08e0a7c68ca28dbf8b478a5489..afbafcba47cda218aec57b496a3a0ff806c4a3a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,6 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR lib) endif(NOT DEFINED CMAKE_INSTALL_LIBDIR) -set(PLUGIN_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/tarantool/plugins") include(cmake/utils.cmake) @@ -151,6 +150,13 @@ include_directories(${PROJECT_SOURCE_DIR}/src) include_directories(${PROJECT_BINARY_DIR}/src) include_directories(${PROJECT_SOURCE_DIR}/src/lib) include_directories("${PROJECT_SOURCE_DIR}") + +# +# Specify Tarantool modules prefixes +# +set(MODULE_DIR "${CMAKE_INSTALL_LIBDIR}/tarantool/") +set(MODULE_DIR "${MODULE_DIR}${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") + # # Specify prefixes # @@ -177,12 +183,8 @@ endif() # # Specify Tarantool modules Lua prefixes # -if (NOT DEFINED LUA_LIBPATH) - set (LUA_LIBPATH "") -endif() -if (NOT DEFINED LUA_LIBCPATH) - set (LUA_LIBCPATH "") -endif() +set (LUA_LIBPATH "${LUA_LIBPATH};${MODULE_DIR}/?.lua") +set (LUA_LIBCPATH "${LUA_LIBCPATH};${MODULE_DIR}/?.so") # # Now handle all configuration options. @@ -388,7 +390,7 @@ message (STATUS "CXX_COMPILER: ${TARANTOOL_CXX_COMPILER}") message (STATUS "C_FLAGS:${TARANTOOL_C_FLAGS}") message (STATUS "CXX_FLAGS:${TARANTOOL_CXX_FLAGS}") message (STATUS "PREFIX: ${CMAKE_INSTALL_PREFIX}") -message (STATUS "MODULES: ${TARANTOOL_MODULES}") +message (STATUS "MODULE_DIR: ${MODULE_DIR}") message (STATUS "ENABLE_STATIC: ${ENABLE_STATIC}") message (STATUS "ENABLE_SSE2: ${ENABLE_SSE2}") message (STATUS "ENABLE_AVX: ${ENABLE_AVX}") diff --git a/client/tarantar/main.c b/client/tarantar/main.c index bcbb5732d230e83323f8586538d84fe1e3450cbe..01f0d518552bc5138134e86d9c4e275eb76682d3 100644 --- a/client/tarantar/main.c +++ b/client/tarantar/main.c @@ -139,31 +139,37 @@ int main(int argc, char *argv[]) return 1; } - char cur_dir_snap[PATH_MAX], cur_dir_wal[PATH_MAX]; - tss.snap_dir = cur_dir_snap; - tss.wal_dir = cur_dir_wal; + char workdir[PATH_MAX]; + char snapdir[PATH_MAX], waldir[PATH_MAX]; + + tss.snap_dir = snapdir; + tss.wal_dir = waldir; + + if (tss.opts.cfg.work_dir != NULL) + snprintf(workdir, sizeof(workdir), "%s", tss.opts.cfg.work_dir); + else + getcwd(workdir, PATH_MAX); - if (tss.opts.cfg.work_dir != NULL) { - strncpy((char *)tss.snap_dir, tss.opts.cfg.work_dir, PATH_MAX); - strncpy((char *)tss.wal_dir, tss.opts.cfg.work_dir, PATH_MAX); - } else { - getcwd((char *)tss.snap_dir, PATH_MAX); - getcwd((char *)tss.wal_dir, PATH_MAX); - } if (tss.opts.cfg.snap_dir != NULL) { if (tss.opts.cfg.snap_dir[0] == '/') tss.snap_dir = tss.opts.cfg.snap_dir; - else - strncat((char *)tss.snap_dir, tss.opts.cfg.snap_dir, - PATH_MAX); + else { + snprintf(snapdir, sizeof(snapdir), "%s/%s", workdir, + tss.opts.cfg.snap_dir); + } + } else { + snprintf(snapdir, sizeof(snapdir), "%s", workdir); } if (tss.opts.cfg.wal_dir != NULL) { if (tss.opts.cfg.wal_dir[0] == '/') tss.wal_dir = tss.opts.cfg.wal_dir; else - strncat((char *)tss.wal_dir, tss.opts.cfg.wal_dir, - PATH_MAX); + snprintf(waldir, sizeof(waldir), "%s/%s", workdir, + tss.opts.cfg.wal_dir); + } else { + snprintf(waldir, sizeof(waldir), "%s", workdir); } + /* create spaces */ rc = ts_space_init(&tss.s); if (rc == -1) { diff --git a/client/tarantar/space.c b/client/tarantar/space.c index 17c6b93b2fb9502c15dc6e90967c51bc78e4ab2f..e58d5f42fa9a26f695f67e0d3142604f8ee964ea 100644 --- a/client/tarantar/space.c +++ b/client/tarantar/space.c @@ -239,6 +239,8 @@ int ts_space_fillof(struct ts_spaces *s, int n, tarantool_cfg_space *cs) int ts_space_fill(struct ts_spaces *s, struct ts_options *opts) { + if (opts->cfg.space == NULL) + return 0; int i = 0; for (; opts->cfg.space[i]; i++) { tarantool_cfg_space *cs = opts->cfg.space[i]; diff --git a/debian/control b/debian/control index 93e5aed49908afb943ec5e74eb4bae2fa780f338..361db0ac11437ab197d23260f2e3794dd0c68c26 100644 --- a/debian/control +++ b/debian/control @@ -45,19 +45,20 @@ Description: In-memory database with Lua application server . This package provides Tarantool server. -Package: tarantool-plugins +Package: tarantool-modules Architecture: i386 amd64 kfreebsd-i386 kfreebsd-amd64 hurd-i386 Priority: optional Depends: ${shlibs:Depends}, ${misc:Depends}, tarantool (= ${binary:Version}), - tarantool-postgresql-plugin, - tarantool-mysql-plugin + tarantool-sql-module, + tarantool-postgresql-module, + tarantool-mysql-module Suggests: tarantool-dbg, libdr-tarantool-perl Description: Tarantool in-memory database - all plug-ins bundle Tarantool is an in-memory database and Lua application server. This package provides (or depends on) all Tarantool plug-ins. -Package: tarantool-postgresql-plugin +Package: tarantool-sql-module Architecture: i386 amd64 kfreebsd-i386 kfreebsd-amd64 hurd-i386 Priority: optional Depends: ${shlibs:Depends}, ${misc:Depends}, @@ -68,10 +69,23 @@ Description: Tarantool in-memory database - PostgreSQL connector This package contains a connector to PostgreSQL database for Tarantool Lua stored procedures. -Package: tarantool-mysql-plugin +Package: tarantool-postgresql-module Architecture: i386 amd64 kfreebsd-i386 kfreebsd-amd64 hurd-i386 Priority: optional Depends: ${shlibs:Depends}, ${misc:Depends}, + tarantool-sql-module (= ${binary:Version}), + tarantool (= ${binary:Version}) +Suggests: tarantool-dbg, libdr-tarantool-perl +Description: Tarantool in-memory database - PostgreSQL connector + Tarantool is an in-memory database and Lua application server. + This package contains a connector to PostgreSQL database for + Tarantool Lua stored procedures. + +Package: tarantool-mysql-module +Architecture: i386 amd64 kfreebsd-i386 kfreebsd-amd64 hurd-i386 +Priority: optional +Depends: ${shlibs:Depends}, ${misc:Depends}, + tarantool-sql-module (= ${binary:Version}), tarantool (= ${binary:Version}) Suggests: tarantool-dbg, libdr-tarantool-perl Description: Tarantool in-memory database - MySQL connector diff --git a/debian/tarantool-mysql-module.install b/debian/tarantool-mysql-module.install new file mode 100644 index 0000000000000000000000000000000000000000..9e715df39ba271c48ea4f34de5c76b40067fdef2 --- /dev/null +++ b/debian/tarantool-mysql-module.install @@ -0,0 +1,2 @@ +usr/lib/tarantool/1.6/box/net/mysql.so + diff --git a/debian/tarantool-mysql-plugin.install b/debian/tarantool-mysql-plugin.install deleted file mode 100644 index ee5b91ba8c16b78fda9989e39ccee7e38fda2dd2..0000000000000000000000000000000000000000 --- a/debian/tarantool-mysql-plugin.install +++ /dev/null @@ -1,2 +0,0 @@ -usr/lib/tarantool/plugins/libmysql.so - diff --git a/debian/tarantool-postgresql-module.install b/debian/tarantool-postgresql-module.install new file mode 100644 index 0000000000000000000000000000000000000000..253c7ec7ec08d673e8d9f968f7b407eaefdeab13 --- /dev/null +++ b/debian/tarantool-postgresql-module.install @@ -0,0 +1 @@ +usr/lib/tarantool/1.6/box/net/pg.so diff --git a/debian/tarantool-postgresql-plugin.install b/debian/tarantool-postgresql-plugin.install deleted file mode 100644 index a7b5de3c7914973de68d671a95b4c91b567e2110..0000000000000000000000000000000000000000 --- a/debian/tarantool-postgresql-plugin.install +++ /dev/null @@ -1 +0,0 @@ -usr/lib/tarantool/plugins/libpg.so diff --git a/debian/tarantool-sql-module.install b/debian/tarantool-sql-module.install new file mode 100644 index 0000000000000000000000000000000000000000..a59e9211eac0dadbd7c38e9dd27a58078256445f --- /dev/null +++ b/debian/tarantool-sql-module.install @@ -0,0 +1 @@ +usr/lib/tarantool/1.6/box/net/sql.lua diff --git a/extra/rpm.spec.in b/extra/rpm.spec.in index d5eae67cfab4607ae23db88ef7d1c3487ab10696..3d1f2751e5a5ebeb5f40e3bddb0a06adedc0e7de 100644 --- a/extra/rpm.spec.in +++ b/extra/rpm.spec.in @@ -22,6 +22,21 @@ replication, online backup, stored procedures in Lua. This package provides the server daemon and administration scripts. +# Tarantool sql module + +%package sql-module +Summary: Tarantool common sql interface +Vendor: tarantool.org +Group: Applications/Databases +Provides: tarantool-sql-module +Obsoletes: tarantool-sql-module +%description -n tarantool-sql-module +Tarantool is a high performance in-memory NoSQL database. +It supports replication, online backup, stored procedures in Lua. + +This package provides a common sql interface to use with +tarantool-pg-module or by tarantool-mysql-module. + # Tarantool client spec %package client @@ -153,6 +168,13 @@ useradd -r -g tarantool tarantool > /dev/null 2>&1 # "/usr/lib/libtarantoolsql.so.1" # "/usr/lib/libtarantoolsql.so.1.1" +%files sql-module +%defattr(-,root,root,-) +%dir "/usr/lib/tarantool/1.6" +%dir "/usr/lib/tarantool/1.6/box" +%dir "/usr/lib/tarantool/1.6/box/net" +"/usr/lib/tarantool/1.6/box/net/sql.lua" + %files client %defattr(-,root,root,-) "%{_mandir}/man1/tarantool.1.gz" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e41191e8826922661a7238a0addb614581da4796..0a8094274dce8f06c33f65acd5f152eae5956629 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,7 +4,7 @@ enable_tnt_compile_flags() if (NOT TARGET_OS_DARWIN) - add_subdirectory(plugin) + add_subdirectory(module) endif() include_directories(${LIBEV_INCLUDE_DIR}) @@ -68,7 +68,6 @@ set (common_sources assoc.c say.c fio.c - plugin.c crc32.c tbuf.c opts.c @@ -79,7 +78,6 @@ set (common_sources lua/info.cc lua/stat.cc lua/errinj.cc - lua/plugin.cc lua/ipc.cc lua/socket.cc lua/session.cc diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index 5b3bddfa463c9b5f22e2a4b8abecf0f36e24b5aa..43f9dfecea96e4fddcb33a8438fd901743f2b222 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -9,7 +9,6 @@ lua_source(lua_sources lua/schema.lua) lua_source(lua_sources lua/box.lua) lua_source(lua_sources lua/box_net.lua) lua_source(lua_sources lua/misc.lua) -lua_source(lua_sources lua/sql.lua) add_custom_target(box_generate_lua_sources WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src/box diff --git a/src/box/lua/call.cc b/src/box/lua/call.cc index 5f1003e8caa9967922431c1e44c9d1d5489e4ff7..9f68a0d3e78eabdae43d0eaee548bc8ff2d34b77 100644 --- a/src/box/lua/call.cc +++ b/src/box/lua/call.cc @@ -46,8 +46,8 @@ #include "bit/bit.h" /* contents of box.lua, misc.lua, box.net.lua respectively */ -extern char schema_lua[], box_lua[], box_net_lua[], misc_lua[], sql_lua[]; -static const char *lua_sources[] = { schema_lua, box_lua, box_net_lua, misc_lua, sql_lua, NULL }; +extern char schema_lua[], box_lua[], box_net_lua[], misc_lua[] ; +static const char *lua_sources[] = { schema_lua, box_lua, box_net_lua, misc_lua, NULL }; /* * Functions, exported in box_lua.h should have prefix diff --git a/src/lua/init.cc b/src/lua/init.cc index 025ae5745b1a8fabca68b2155c7b6c617ccd438d..ca8abfbb83786288d189e5ae6f037d07756c26ae 100644 --- a/src/lua/init.cc +++ b/src/lua/init.cc @@ -27,7 +27,6 @@ * SUCH DAMAGE. */ #include "lua/init.h" -#include "lua/plugin.h" #include "lua/utils.h" #include "tarantool.h" #include "box/box.h" @@ -58,7 +57,6 @@ extern "C" { #include "lua/msgpack.h" #include <ctype.h> -#include <plugin.h> #include "small/region.h" extern "C" { @@ -308,7 +306,6 @@ tarantool_lua_init() tarantool_lua_errinj_init(L); tarantool_lua_fiber_init(L); tarantool_lua_admin_init(L); - tarantool_lua_plugin_init(L); tarantool_lua_cjson_init(L); tarantool_lua_yaml_init(L); tarantool_lua_info_init(L); @@ -329,9 +326,6 @@ tarantool_lua_init() box_lua_init(L); - /* init after internal luas are processed */ - tarantool_plugin_init(L); - /* clear possible left-overs of init */ lua_settop(L, 0); tarantool_L = L; diff --git a/src/lua/plugin.cc b/src/lua/plugin.cc deleted file mode 100644 index ef5421288f82e5ffc02ca2237cb5d3a676b0cff7..0000000000000000000000000000000000000000 --- a/src/lua/plugin.cc +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include "lua/plugin.h" - -extern "C" { -#include <lua.h> -#include <lauxlib.h> -#include <lualib.h> -} /* extern "C" */ - -#include <plugin.h> -#include "lua/utils.h" - -static int -plugin_lua_stat_cb(struct tarantool_plugin *p, void *cb_ctx) -{ - struct lua_State *L = (struct lua_State *) cb_ctx; - lua_pushstring(L, p->name); - lua_newtable(L); - lua_pushstring(L, "version"); - luaL_pushnumber64(L, p->version); - lua_settable(L, -3); - lua_settable(L, -3); - return 0; -} - -static int -lbox_plugin_info(struct lua_State *L) -{ - lua_newtable(L); - lua_pushstring(L, "plugin"); - lua_newtable(L); - plugin_foreach(plugin_lua_stat_cb, L); - lua_settable(L, -3); - return 1; -} - -/** Initialize box.plugin package. */ - -void -tarantool_lua_plugin_init(struct lua_State *L) -{ - lua_getfield(L, LUA_GLOBALSINDEX, "box"); - lua_pushstring(L, "plugin"); - lua_newtable(L); - - lua_pushstring(L, "info"); - lua_pushcfunction(L, lbox_plugin_info); - lua_settable(L, -3); - - lua_settable(L, -3); - lua_pop(L, 1); -} diff --git a/src/lua/plugin.h b/src/lua/plugin.h deleted file mode 100644 index 0c12162f16ec901a0e0451a0f1570b0cafded608..0000000000000000000000000000000000000000 --- a/src/lua/plugin.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TARANTOOL_LUA_PLUGIN_H_INCLUDED -#define TARANTOOL_LUA_PLUGIN_H_INCLUDED -/* - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -struct lua_State; -void tarantool_lua_plugin_init(struct lua_State *L); - -#endif /* TARANTOOL_LUA_PLUGIN_H_INCLUDED */ diff --git a/src/plugin/CMakeLists.txt b/src/module/CMakeLists.txt similarity index 67% rename from src/plugin/CMakeLists.txt rename to src/module/CMakeLists.txt index 11853612e6329d8385e4881a2d57a8ddc9bba4e4..293ce2e04fa816d455812e08148e913534e69aa9 100644 --- a/src/plugin/CMakeLists.txt +++ b/src/module/CMakeLists.txt @@ -1,3 +1,3 @@ +add_subdirectory(sql) add_subdirectory(pg) add_subdirectory(mysql) - diff --git a/src/plugin/mysql/CMakeLists.txt b/src/module/mysql/CMakeLists.txt similarity index 59% rename from src/plugin/mysql/CMakeLists.txt rename to src/module/mysql/CMakeLists.txt index e7ea8df5751a432550238b7b2c5f9b40f3602cdd..3851206dbaf36cc781fcbd440748274b1b346f25 100644 --- a/src/plugin/mysql/CMakeLists.txt +++ b/src/module/mysql/CMakeLists.txt @@ -1,13 +1,11 @@ find_optional_package(MySQL) if (MYSQL_FOUND) - message(STATUS "box.net.sql(mysql) INC=${MYSQL_INCLUDE_DIRS}") - message(STATUS "box.net.sql(mysql) LIBS=${MYSQL_LIBRARIES}") - include_directories(${MYSQL_INCLUDE_DIRS}) add_library(mysql SHARED mysql.cc) target_link_libraries(mysql ${MYSQL_LIBRARIES} -rdynamic) - install(TARGETS mysql LIBRARY DESTINATION ${PLUGIN_DIR}) + set_target_properties(mysql PROPERTIES PREFIX "") + install(TARGETS mysql LIBRARY DESTINATION ${MODULE_DIR}/box/net) else() message(STATUS "MySQL client not found, box.net.sql(mysql) disabled") endif() diff --git a/src/plugin/mysql/mysql.cc b/src/module/mysql/mysql.cc similarity index 92% rename from src/plugin/mysql/mysql.cc rename to src/module/mysql/mysql.cc index 9039de04c1798c9def29ce4adc324c29c6cb8fa6..6eb010210a363fc34931e65150ee13779785fb40 100644 --- a/src/plugin/mysql/mysql.cc +++ b/src/module/mysql/mysql.cc @@ -27,10 +27,6 @@ * SUCH DAMAGE. */ - -#define PLUGIN_NAME "mysql" -#define PLUGIN_VERSION 1 - #include <stddef.h> extern "C" { @@ -46,15 +42,12 @@ extern "C" { #include <coeio.h> #include "third_party/tarantool_ev.h" - +#include <lua/init.h> #include <lua/utils.h> #include <say.h> #include <mysql.h> #include <scoped_guard.h> -#include <plugin.h> - - /** * gets MYSQL connector from lua stack (or object) */ @@ -88,12 +81,12 @@ lua_check_mysql(struct lua_State *L, int index) static ssize_t connect_mysql(va_list ap) { - MYSQL *mysql = va_arg(ap, typeof(mysql)); - const char *host = va_arg(ap, typeof(host)); - const char *port = va_arg(ap, typeof(port)); - const char *user = va_arg(ap, typeof(user)); - const char *password = va_arg(ap, typeof(password)); - const char *db = va_arg(ap, typeof(db)); + MYSQL *mysql = va_arg(ap, MYSQL*); + const char *host = va_arg(ap, const char*); + const char *port = va_arg(ap, const char*); + const char *user = va_arg(ap, const char*); + const char *password = va_arg(ap, const char*); + const char *db = va_arg(ap, const char*); int iport = 0; @@ -140,9 +133,9 @@ self_field(struct lua_State *L, const char *name, int index) static ssize_t exec_mysql(va_list ap) { - MYSQL *mysql = va_arg(ap, typeof(mysql)); - const char *sql = va_arg(ap, typeof(sql)); - size_t len = va_arg(ap, typeof(len)); + MYSQL *mysql = va_arg(ap, MYSQL*); + const char *sql = va_arg(ap, const char*); + size_t len = va_arg(ap, size_t); int res = mysql_real_query(mysql, sql, len); if (res == 0) { @@ -157,9 +150,9 @@ exec_mysql(va_list ap) static ssize_t fetch_result(va_list ap) { - MYSQL *mysql = va_arg(ap, typeof(mysql)); - MYSQL_RES **result = va_arg(ap, typeof(result)); - int resno = va_arg(ap, typeof(resno)); + MYSQL *mysql = va_arg(ap, MYSQL*); + MYSQL_RES **result = va_arg(ap, MYSQL_RES**); + int resno = va_arg(ap, int); if (resno) { if (mysql_next_result(mysql) > 0) return -2; @@ -384,7 +377,7 @@ lua_mysql_quote(struct lua_State *L) size_t len; const char *s = lua_tolstring(L, -1, &len); - char *sout = (typeof(sout))malloc(len * 2 + 1); + char *sout = (char*)malloc(len * 2 + 1); if (!sout) { luaL_error(L, "Can't allocate memory for variable"); } @@ -465,9 +458,11 @@ lbox_net_mysql_connect(struct lua_State *L) return 1; } +extern "C" { + int LUA_API luaopen_box_net_mysql(lua_State*); +} -static void -init(struct lua_State *L) +int LUA_API luaopen_box_net_mysql(lua_State *L) { lua_getfield(L, LUA_GLOBALSINDEX, "box"); /* stack: box */ @@ -487,6 +482,5 @@ init(struct lua_State *L) /* cleanup stack */ lua_pop(L, 4); + return 0; } - -DECLARE_PLUGIN(PLUGIN_NAME, PLUGIN_VERSION, init, NULL); diff --git a/src/plugin/pg/CMakeLists.txt b/src/module/pg/CMakeLists.txt similarity index 68% rename from src/plugin/pg/CMakeLists.txt rename to src/module/pg/CMakeLists.txt index dcaf15475d4c33dd6ad7b3008ed5bc11ee30a45c..7c9a002a6b3139ead094a9c4e780c79ce1f21f89 100644 --- a/src/plugin/pg/CMakeLists.txt +++ b/src/module/pg/CMakeLists.txt @@ -1,16 +1,13 @@ # A special hack for buggy FindPostgreSQL.cmake in Debian/Ubuntu set(PostgreSQL_ROOT /usr/include/postgresql;/usr/include/postgres) find_optional_package(PostgreSQL) -if (PostgreSQL_FOUND) - message(STATUS "box.net.sql(pg): INC=${PostgreSQL_INCLUDE_DIRS}") - message(STATUS "box.net.sql(pg): LIBS=${PostgreSQL_LIBRARIES}") +if (PostgreSQL_FOUND) include_directories(${PostgreSQL_INCLUDE_DIRS}) add_library(pg SHARED pg.cc) target_link_libraries(pg ${PostgreSQL_LIBRARIES} -rdynamic) - install(TARGETS pg LIBRARY DESTINATION ${PLUGIN_DIR}) - + set_target_properties(pg PROPERTIES PREFIX "") + install(TARGETS pg LIBRARY DESTINATION ${MODULE_DIR}/box/net) else() message(STATUS "PostgreSQL client not found, box.net.sql(pg) disabled") endif() - diff --git a/src/plugin/pg/pg.cc b/src/module/pg/pg.cc similarity index 93% rename from src/plugin/pg/pg.cc rename to src/module/pg/pg.cc index c653a708dd0cfab321b404b284d7c1284e3104e9..27f71bbd9f5bcfac573c84bae517eabb88b371ce 100644 --- a/src/plugin/pg/pg.cc +++ b/src/module/pg/pg.cc @@ -34,8 +34,6 @@ extern "C" { #undef PACKAGE_VERSION } -#define PLUGIN_VERSION 1 -#define PLUGIN_NAME "postgresql" #include <stddef.h> extern "C" { @@ -43,7 +41,6 @@ extern "C" { #include <lauxlib.h> #include <lualib.h> } -#include <plugin.h> #include <stdio.h> #include <stdlib.h> @@ -52,12 +49,10 @@ extern "C" { #include <coeio.h> #include "third_party/tarantool_ev.h" - -#include <lua/utils.h> +#include <lua/init.h> #include <say.h> #include <scoped_guard.h> - static PGconn * lua_check_pgconn(struct lua_State *L, int index) { @@ -85,14 +80,14 @@ lua_check_pgconn(struct lua_State *L, int index) static ssize_t pg_exec(va_list ap) { - PGconn *conn = va_arg(ap, typeof(conn)); - const char *sql = va_arg(ap, typeof(sql)); - int count = va_arg(ap, typeof(count)); - Oid *paramTypes = va_arg(ap, typeof(paramTypes)); - const char **paramValues = va_arg(ap, typeof(paramValues)); - const int *paramLengths = va_arg(ap, typeof(paramLengths)); - const int *paramFormats = va_arg(ap, typeof(paramFormats)); - PGresult **res = va_arg(ap, typeof(res)); + PGconn *conn = va_arg(ap, PGconn*); + const char *sql = va_arg(ap, const char*); + int count = va_arg(ap, int); + Oid *paramTypes = va_arg(ap, Oid*); + const char **paramValues = va_arg(ap, const char**); + const int *paramLengths = va_arg(ap, int*); + const int *paramFormats = va_arg(ap, int*); + PGresult **res = va_arg(ap, PGresult**); *res = PQexecParams(conn, sql, count, paramTypes, paramValues, paramLengths, paramFormats, 0); @@ -323,8 +318,8 @@ pg_notice(void *arg, const char *message) static ssize_t pg_connect(va_list ap) { - const char *constr = va_arg(ap, typeof(constr)); - PGconn **conn = va_arg(ap, typeof(conn)); + const char *constr = va_arg(ap, const char*); + PGconn **conn = va_arg(ap, PGconn**); *conn = PQconnectdb(constr); if (*conn) PQsetNoticeProcessor(*conn, pg_notice, NULL); @@ -491,9 +486,11 @@ lbox_net_pg_connect(struct lua_State *L) return 1; } +extern "C" { + int LUA_API luaopen_box_net_pg(lua_State*); +} -static void -init(struct lua_State *L) +int LUA_API luaopen_box_net_pg(lua_State *L) { lua_getfield(L, LUA_GLOBALSINDEX, "box"); /* stack: box */ @@ -506,9 +503,6 @@ init(struct lua_State *L) lua_pushstring(L, "connectors"); lua_rawget(L, -2); /* stack: box.net.sql.connectors */ - - - /* stack: box, box.net.sql.connectors */ lua_pushstring(L, "pg"); lua_pushcfunction(L, lbox_net_pg_connect); @@ -521,7 +515,5 @@ init(struct lua_State *L) /* cleanup stack */ lua_pop(L, 4); + return 0; } - - -DECLARE_PLUGIN(PLUGIN_NAME, PLUGIN_VERSION, init, NULL); diff --git a/src/module/sql/CMakeLists.txt b/src/module/sql/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2a75cd5015537e773d0954dd2e9304e961479213 --- /dev/null +++ b/src/module/sql/CMakeLists.txt @@ -0,0 +1,3 @@ + +install(FILES ${PROJECT_SOURCE_DIR}/src/module/sql/sql.lua + DESTINATION ${MODULE_DIR}/box/net) diff --git a/src/box/lua/sql.lua b/src/module/sql/sql.lua similarity index 100% rename from src/box/lua/sql.lua rename to src/module/sql/sql.lua diff --git a/src/plugin.c b/src/plugin.c deleted file mode 100644 index 646715f762cb8b4762c7d04561b4b3fa472a3c96..0000000000000000000000000000000000000000 --- a/src/plugin.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include "plugin.h" -#include <stdio.h> -#include <sys/types.h> -#include <dirent.h> -#include <dlfcn.h> -#include <string.h> -#include "say.h" -#include <limits.h> - -static RLIST_HEAD(loaded_plugins); - -/** - * Iterate over all loaded plug-ins. - */ -int -plugin_foreach(plugin_foreach_cb cb, void *cb_ctx) -{ - int res; - struct tarantool_plugin *p; - rlist_foreach_entry(p, &loaded_plugins, list) { - res = cb(p, cb_ctx); - if (res != 0) - return res; - } - return 0; -} - -static void -plugin_load(void *ctx, const char *plugin) -{ - if (strstr(plugin, ".so") == NULL) - return; - - say_info("Loading plugin: %s", plugin); - - void *dl = dlopen(plugin, RTLD_NOW); - if (!dl) { - say_error("Can't load plugin %s: %s", plugin, dlerror()); - return; - } - - struct tarantool_plugin *p = (typeof(p))dlsym(dl, "plugin_meta"); - - if (!p) { - say_error("Can't find plugin metadata in plugin %s", plugin); - dlclose(dl); - return; - } - - if (p->api_version != PLUGIN_API_VERSION) { - say_error("Plugin %s has api_version: %d but tarantool has: %d", - plugin, - p->api_version, - PLUGIN_API_VERSION); - return; - } - - rlist_add_entry(&loaded_plugins, p, list); - - if (p->init) - p->init(ctx); - - say_info("Plugin '%s' was loaded, version: %d", p->name, p->version); -} - -/** Load all plugins in a plugin dir. */ -static void -plugin_dir(struct lua_State *L, const char *dir) -{ - if (!dir) - return; - if (!*dir) - return; - DIR *dh = opendir(dir); - - if (!dh) - return; - - struct dirent *dent; - while ((dent = readdir(dh)) != NULL) { - if (dent->d_type != DT_REG) - continue; - char path[PATH_MAX]; - (void) snprintf(path, sizeof(path), "%s/%s", dir, - dent->d_name); - plugin_load(L, path); - } - - closedir(dh); -} - -void -tarantool_plugin_init(struct lua_State *L) -{ - char *plugins = getenv("TARANTOOL_PLUGIN_DIR"); - - if (plugins) { - plugins = strdup(plugins); - char *ptr = plugins; - for (;;) { - char *divider = strchr(ptr, ':'); - if (divider == NULL) { - plugin_dir(L, ptr); - break; - } - *divider = 0; - plugin_dir(L, ptr); - ptr = divider + 1; - } - free(plugins); - } - plugin_dir(L, PLUGIN_DIR); -} diff --git a/src/plugin.h b/src/plugin.h deleted file mode 100644 index 1365c676196f77c38f881c297e0fd275644b8fc1..0000000000000000000000000000000000000000 --- a/src/plugin.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef TARANTOOL_PLUGIN_H_INCLUDED -#define TARANTOOL_PLUGIN_H_INCLUDED -/* - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include <stddef.h> -#if defined(__cplusplus) -extern "C" { -#endif /* defined(__cplusplus) */ - -#define PLUGIN_API_VERSION 1 - -#include <stddef.h> -#include "salad/rlist.h" - -struct lua_State; -struct tbuf; - -typedef void(*plugin_init_cb)(struct lua_State *L); -typedef void(*plugin_stat_cb)(struct tbuf *out); - -struct tarantool_plugin { - int api_version; - int version; - const char *name; - plugin_init_cb init; - plugin_stat_cb stat; - struct rlist list; -}; - -#define DECLARE_PLUGIN(name, version, init, stat) \ - extern "C" { \ - struct tarantool_plugin plugin_meta = { \ - PLUGIN_API_VERSION, \ - version, \ - name, \ - init, \ - stat, \ - { NULL, NULL } \ - }; \ - } - - -/** - * Iterate over all loaded plug-ins with a callback. - */ -typedef int (*plugin_foreach_cb)(struct tarantool_plugin *p, - void *cb_ctx); - -int -plugin_foreach(plugin_foreach_cb cb, void *cb_ctx); - -/** - * Initialize plug-in subsystem. - */ -void -tarantool_plugin_init(struct lua_State *L); - -#if defined(__cplusplus) -} /* extern "C" */ -#endif /* defined(__cplusplus) */ - -#endif /* TARANTOOL_PLUGIN_H_INCLUDED */ diff --git a/src/trivia/config.h.cmake b/src/trivia/config.h.cmake index 51c2ad539b954716d71ffa184d11742fbbb3d1e2..9df089425674effb4284282e764e196b08c85489 100644 --- a/src/trivia/config.h.cmake +++ b/src/trivia/config.h.cmake @@ -138,7 +138,7 @@ #define LUA_LIBPATH "@LUA_LIBPATH@" #define LUA_LIBCPATH "@LUA_LIBCPATH@" -#define PLUGIN_DIR "@PLUGIN_DIR@" +#define MODULE_DIR "@MODULE_DIR" #define DEFAULT_CFG_FILENAME "tarantool.cfg" #define DEFAULT_CFG SYSCONF_DIR "/" DEFAULT_CFG_FILENAME diff --git a/test/box/configuration.result b/test/box/configuration.result index ce0d4c3b4008bcdda0f39cede9ab9de32f22b0a8..6ff79f4b2bafcb3bb769e6b7e12aaa4955ecb1e5 100644 --- a/test/box/configuration.result +++ b/test/box/configuration.result @@ -74,11 +74,11 @@ floor(1.1) ... string.gmatch(package_path, '([^;]*)')() --- -- ./?.lua +- ... string.gmatch(package_cpath, '([^;]*)')() --- -- ./?.so +- ... mod.test(10, 15) --- diff --git a/test/box/misc.result b/test/box/misc.result index 726b8a3f65faad62cbd7824520a21d6eb8555002..50709569789b3b4e97c15bff3284bbc74a03b826 100644 --- a/test/box/misc.result +++ b/test/box/misc.result @@ -36,7 +36,6 @@ t - net - on_reload_configuration - pack - - plugin - process - raise - schema diff --git a/test/box/net_sql.common.lua b/test/box/net_sql.common.lua new file mode 100644 index 0000000000000000000000000000000000000000..715defa4329f047bde96bf188d89845fb69d2c5f --- /dev/null +++ b/test/box/net_sql.common.lua @@ -0,0 +1,5 @@ +package.path = "../../src/module/sql/?.lua;"..package.path +require("sql") +if type(box.net.sql) ~= "table" then + error("net.sql load failed") +end diff --git a/test/box/net_sql.common.result b/test/box/net_sql.common.result index 673688104f98221cb5585c4a5055a998cded9c4c..2d077342608b7be479ad3ca5c7a9e20d95954ee0 100644 --- a/test/box/net_sql.common.result +++ b/test/box/net_sql.common.result @@ -1,12 +1,8 @@ -lua c = box.net.sql.connect('abcd') ---- -error: '[string "-- sql.lua (internal file)..."]:29: Unknown driver ''abcd''' -... -lua c = box.net.sql.connect('mysql') +lua type(box.net.sql) --- -error: '[string "-- sql.lua (internal file)..."]:64: Usage: box.net.sql.connect(''mysql'', host, port, user, password, db, ...)' + - table ... -lua c = box.net.sql.connect('pg') +lua c = box.net.sql.connect('abcd') --- -error: '[string "-- sql.lua (internal file)..."]:64: Usage: box.net.sql.connect(''pg'', host, port, user, password, db, ...)' +error: '../../src/module/sql/sql.lua:29: Unknown driver ''abcd''' ... diff --git a/test/box/net_sql.common.skipcond b/test/box/net_sql.common.skipcond deleted file mode 100644 index 8ae9523c3e5ec5d0f5b4906d396c876170a77be5..0000000000000000000000000000000000000000 --- a/test/box/net_sql.common.skipcond +++ /dev/null @@ -1,18 +0,0 @@ -# encoding: tarantool - -import os - -try: - (host, port, user, password, db) = os.getenv('MYSQL').split(':') - -except (RuntimeError, TypeError, NameError, AttributeError, ValueError): - self.skip = 1 - - -import os - -try: - (host, port, user, password, db) = os.getenv('PG').split(':') - -except (RuntimeError, TypeError, NameError, AttributeError, ValueError): - self.skip = 1 diff --git a/test/box/net_sql.common.test b/test/box/net_sql.common.test index 8a5340f369a37a2614e86a74dcf900ed32f51916..eba4a3d6713f2dd56923d493e76ea079ed07a297 100644 --- a/test/box/net_sql.common.test +++ b/test/box/net_sql.common.test @@ -1,7 +1,6 @@ -# encoding: tarantool +server.stop() +server.deploy(init_lua="box/net_sql.common.lua") -exec admin "lua c = box.net.sql.connect('abcd')" - -exec admin "lua c = box.net.sql.connect('mysql')" -exec admin "lua c = box.net.sql.connect('pg')" +admin("type(box.net.sql)") +admin("c = box.net.sql.connect('abcd')") diff --git a/test/box/net_sql.mysql.lua b/test/box/net_sql.mysql.lua new file mode 100644 index 0000000000000000000000000000000000000000..d3ff697f2492ed4360d0aef96ffcf1df9c45f27d --- /dev/null +++ b/test/box/net_sql.mysql.lua @@ -0,0 +1,6 @@ +package.path = "../../src/module/sql/?.lua;"..package.path +require("sql") +if type(box.net.sql) ~= "table" then + error("net.sql load failed") +end +require("box.net.mysql") diff --git a/test/box/net_sql.mysql.test b/test/box/net_sql.mysql.test new file mode 100644 index 0000000000000000000000000000000000000000..ea112574d5e4298d8dc199d15e0894298471c39f --- /dev/null +++ b/test/box/net_sql.mysql.test @@ -0,0 +1,40 @@ +# encoding: tarantool +import os +import shutil + +module_path = os.path.join(vardir, "box/net") +module_path_so = module_path + "/mysql.so" +os.makedirs(module_path) +shutil.copy("../src/module/mysql/mysql.so", module_path_so) + +server.stop() +server.deploy(init_lua="box/net_sql.mysql.lua") + +exec admin "lua c = box.net.sql.connect('abcd')" +exec admin "lua dump = function(v) return box.cjson.encode(v) end" + +exec admin "lua connect = {}" +exec admin "lua for tk in string.gmatch(os.getenv('MYSQL'), '[^:]+') do table.insert(connect, tk) end" + +# mysql +exec admin "lua c = box.net.sql.connect('mysql', unpack(connect))" +exec admin "lua for k, v in pairs(c) do print(k, ': ', type(v)) end" +exec admin "lua c:execute('SEL ECT 1')" +exec admin "lua dump({c:execute('SELECT ? AS bool1, ? AS bool2, ? AS nil, ? AS num, ? AS str', true, false, nil, 123, 'abc')})" + +exec admin "lua dump({c:execute('SELECT * FROM (SELECT ?) t WHERE 1 = 0', 2)})" +exec admin "lua dump({c:execute('CREATE PROCEDURE p1() BEGIN SELECT 1 AS One; SELECT 2 AS Two, 3 AS Three; END')})" +exec admin "lua dump({c:execute('CALL p1')})" +exec admin "lua dump({c:execute('DROP PROCEDURE p1')})" +exec admin "lua dump({c:execute('SELECT 1 AS one UNION ALL SELECT 2')})" +exec admin "lua dump({c:execute('SELECT 1 AS one UNION ALL SELECT 2; SELECT ? AS two', 'abc')})" + +exec admin "lua c:quote('test \"abc\" test')" + +exec admin "lua c:begin_work()" +exec admin "lua c:rollback()" +exec admin "lua c:begin_work()" +exec admin "lua c:commit()" + +os.unlink(module_path_so) +os.removedirs(module_path) diff --git a/test/box/net_sql.pg.lua b/test/box/net_sql.pg.lua new file mode 100644 index 0000000000000000000000000000000000000000..6711d955d3d5ee4d9146eaf87c16ae3d5a205773 --- /dev/null +++ b/test/box/net_sql.pg.lua @@ -0,0 +1,6 @@ +package.path = "../../src/module/sql/?.lua;"..package.path +require("sql") +if type(box.net.sql) ~= "table" then + error("net.sql load failed") +end +require("box.net.pg") diff --git a/test/box/net_sql.pg.result b/test/box/net_sql.pg.result index 8a13c80e0d888e1305392105611619367056a462..454b897926e919f9e71f693389c2b88d95dc95e4 100644 --- a/test/box/net_sql.pg.result +++ b/test/box/net_sql.pg.result @@ -1,6 +1,10 @@ c = box.net.sql.connect('abcd') --- -- error: '[string "-- sql.lua (internal file)..."]:29: Unknown driver ''abcd''' +error: '../../src/module/sql/sql.lua:29: Unknown driver ''abcd''' +... +c = box.net.sql.connect('pg') +--- +error: '../../src/module/sql/sql.lua:64: Usage: box.net.sql.connect(''pg'', host, port, user, password, db, ...)' ... dump = function(v) return box.cjson.encode(v) end --- @@ -69,8 +73,7 @@ dump({c:select('SELECT * FROM (VALUES (1,2), (2,3)) t')}) ... dump({c:single('SELECT * FROM (VALUES (1,2), (2,3)) t')}) --- -- error: '[string "-- sql.lua (internal file)..."]:156: SQL request returned multiply - rows' +error: '../../src/module/sql/sql.lua:156: SQL request returned multiply rows' ... dump({c:single('SELECT * FROM (VALUES (1,2)) t')}) --- @@ -82,12 +85,14 @@ dump({c:perform('SELECT * FROM (VALUES (1,2), (2,3)) t')}) ... c:execute('SELEC T') --- -- error: "[string \"-- sql.lua (internal file)...\"]:105: ERROR: syntax error at - or near \"SELEC\"\nLINE 1: SELEC T\n ^\n" +error: '../../src/module/sql/sql.lua:105: ERROR: syntax error at or near "SELEC" +LINE 1: SELEC T + ^ +' ... c = box.net.sql.connect('abcd') --- -- error: '[string "-- sql.lua (internal file)..."]:29: Unknown driver ''abcd''' +error: '../../src/module/sql/sql.lua:29: Unknown driver ''abcd''' ... c:quote('abc\"cde\"def') --- diff --git a/test/box/net_sql.pg.test b/test/box/net_sql.pg.test new file mode 100644 index 0000000000000000000000000000000000000000..b78e9274338b5cd71bfcdfbcdb1227c55767d938 --- /dev/null +++ b/test/box/net_sql.pg.test @@ -0,0 +1,55 @@ +# encoding: tarantool +import os +import shutil + +module_path = os.path.join(vardir, "box/net") +module_path_so = module_path + "/pg.so" +os.makedirs(module_path) +shutil.copy("../src/module/pg/pg.so", module_path_so) + +server.stop() +server.deploy(init_lua="box/net_sql.pg.lua") + +exec admin "lua c = box.net.sql.connect('abcd')" +exec admin "lua c = box.net.sql.connect('pg')" + +exec admin "lua dump = function(v) return box.cjson.encode(v) end" + +exec admin "lua connect = {}" +exec admin "lua for tk in string.gmatch(os.getenv('PG'), '[^:]+') do table.insert(connect, tk) end" + +# postgresql +exec admin "lua c = box.net.sql.connect('pg', unpack(connect))" +exec admin "lua dump({c:execute('SELECT 123::text AS bla, 345')})" +exec admin "lua dump({c:execute('SELECT -1 AS neg, NULL AS abc')})" +exec admin "lua dump({c:execute('SELECT -1.1 AS neg, 1.2 AS pos')})" +exec admin "lua dump({c:execute('SELECT ARRAY[1,2] AS neg, 1.2 AS pos')})" +exec admin "lua dump({c:execute('SELECT ? AS val', 'abc')})" +exec admin "lua dump({c:execute('SELECT ? AS val', 123)})" +exec admin "lua dump({c:execute('SELECT ? AS val', true)})" +exec admin "lua dump({c:execute('SELECT ? AS val', false)})" +exec admin "lua dump({c:execute('SELECT ? AS val, ? AS num, ? AS str', false, 123, 'abc')})" +exec admin "lua dump({c:execute('DROP TABLE IF EXISTS unknown_table')})" +exec admin "lua dump({c:execute('SELECT * FROM (VALUES (1,2), (2,3)) t')})" +exec admin "lua c:ping()" +exec admin "lua dump({c:select('SELECT * FROM (VALUES (1,2), (2,3)) t')})" +exec admin "lua dump({c:single('SELECT * FROM (VALUES (1,2), (2,3)) t')})" +exec admin "lua dump({c:single('SELECT * FROM (VALUES (1,2)) t')})" +exec admin "lua dump({c:perform('SELECT * FROM (VALUES (1,2), (2,3)) t')})" +exec admin "lua c:execute('SELEC T')" + +exec admin "lua c = box.net.sql.connect('abcd')" + + +exec admin "lua c:quote('abc\"cde\"def')" + + +exec admin "lua c:begin_work()" +exec admin "lua c:rollback()" +exec admin "lua c:begin_work()" +exec admin "lua c:commit()" + +exec admin "lua c:txn(function(dbi) dbi:single('SELECT 1') end)" + +os.unlink(module_path_so) +os.removedirs(module_path) diff --git a/test/box/socket.result b/test/box/socket.result index 42c512366fb3757b056fca6d59c378f7d61aff89..173c32f1a2caba3c35b76e165862260d8ea04f99 100644 --- a/test/box/socket.result +++ b/test/box/socket.result @@ -946,7 +946,7 @@ reps test_listen_done = false --- ... - function server() ms = box.socket.tcp() ms:bind('127.0.0.1', 8181) ms:listen() test_listen_done = true while true do local s = ms:accept( .5 ) if s ~= 'timeout' then print("accepted connection ", s) s:send('Hello world') s:shutdown(box.socket.SHUT_RDWR) end end end box.fiber.wrap(server) + function server() ms = box.socket.tcp() ms:bind('127.0.0.1', 8181) ms:listen() test_listen_done = true while true do local s = ms:accept( .5 ) if s ~= 'timeout' then print("accepted connection ", s) s:send('Hello world') s:shutdown(box.socket.SHUT_RDWR) end end end fbr = box.fiber.wrap(server) --- ... wait_cout = 100 while not test_listen_done and wait_cout > 0 do box.fiber.sleep(0.001) wait_cout = wait_cout - 1 end diff --git a/test/box/socket.test.py b/test/box/socket.test.py index cee89ad906f0207379fbfc45136d4bcdcc3dff12..6a025e1686d81139a35420b8cad07334cd6ffe34 100644 --- a/test/box/socket.test.py +++ b/test/box/socket.test.py @@ -597,7 +597,7 @@ function server() end end -box.fiber.wrap(server) +fbr = box.fiber.wrap(server) """ admin("test_listen_done = false") admin(test.replace('\n', ' '))