Skip to content
Snippets Groups Projects
Commit 387fb220 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Merge branch 'stable' of github.com:tarantool/tarantool into stable

parents b197bfa4 d04f34ec
No related branches found
No related tags found
No related merge requests found
......@@ -124,7 +124,11 @@ self_field(struct lua_State *L, const char *name, int index)
if (index < 0)
index--;
lua_rawget(L, index);
const char *res = lua_tostring(L, -1);
const char *res;
if (lua_isnil(L, -1))
res = NULL;
else
res = lua_tostring(L, -1);
lua_pop(L, 1);
return res;
}
......@@ -408,6 +412,14 @@ lbox_net_mysql_connect(struct lua_State *L)
const char *db = self_field(L, "db", 1);
if (!host || (!port) || (!user) || (!pass) || (!db)) {
luaL_error(L,
"Usage: box.net.sql.connect"
"('mysql', host, port, user, password, db, ...)"
);
}
if (coeio_custom(connect_mysql, TIMEOUT_INFINITY, mysql,
host, port, user, pass, db) == -1) {
mysql_close(mysql);
......
......@@ -341,7 +341,11 @@ self_field(struct lua_State *L, const char *name, int index)
if (index < 0)
index--;
lua_rawget(L, index);
const char *res = lua_tostring(L, -1);
const char *res;
if (lua_isnil(L, -1))
res = NULL;
else
res = lua_tostring(L, -1);
lua_pop(L, 1);
return res;
}
......@@ -401,24 +405,38 @@ lua_pg_quote_ident(struct lua_State *L)
static int
lbox_net_pg_connect(struct lua_State *L)
{
const char *host = self_field(L, "host", 1);
const char *port = self_field(L, "port", 1);
const char *user = self_field(L, "user", 1);
const char *pass = self_field(L, "password", 1);
const char *db = self_field(L, "db", 1);
if (!host || (!port) || (!user) || (!pass) || (!db)) {
luaL_error(L,
"Usage: box.net.sql.connect"
"('pg', host, port, user, password, db, ...)"
);
}
PGconn *conn = NULL;
luaL_Buffer b;
luaL_buffinit(L, &b);
luaL_addstring(&b, "host='");
luaL_addstring(&b, self_field(L, "host", 1));
luaL_addstring(&b, host);
luaL_addstring(&b, "' port='");
luaL_addstring(&b, self_field(L, "port", 1));
luaL_addstring(&b, port);
luaL_addstring(&b, "' user='");
luaL_addstring(&b, self_field(L, "user", 1));
luaL_addstring(&b, user);
luaL_addstring(&b, "' password='");
luaL_addstring(&b, self_field(L, "password", 1));
luaL_addstring(&b, pass);
luaL_addstring(&b, "' dbname='");
luaL_addstring(&b, self_field(L, "db", 1));
luaL_addstring(&b, db);
luaL_addchar(&b, '\'');
luaL_pushresult(&b);
......
lua c = box.net.sql.connect('abcd')
---
error: '[string "-- sql.lua (internal file)..."]:29: Unknown driver ''abcd'''
...
lua c = box.net.sql.connect('mysql')
---
error: '[string "-- sql.lua (internal file)..."]:64: Usage: box.net.sql.connect(''mysql'', host, port, user, password, db, ...)'
...
lua c = box.net.sql.connect('pg')
---
error: '[string "-- sql.lua (internal file)..."]:64: Usage: box.net.sql.connect(''pg'', host, port, user, password, db, ...)'
...
# 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
# encoding: tarantool
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')"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment