[td-11818] support drop user/account
This commit is contained in:
parent
d37d594178
commit
79d93ee7a5
|
@ -35,7 +35,7 @@ enum {
|
|||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SELECT, "select" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_FETCH, "fetch" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_INSERT, "insert" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_UPDATE_TAGS_VAL, "update-tag-val" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_UPDATE_TAG_VAL, "update-tag-val" )
|
||||
|
||||
// the SQL below is for mgmt node
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MGMT, "mgmt" )
|
||||
|
@ -54,7 +54,7 @@ enum {
|
|||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_ALTER_TABLE, "alter-table" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_ALTER_DB, "alter-db" )
|
||||
|
||||
TSDB_DEFINE_SQL_TYPE(TSDB_SQL_SYNC_DB_REPLICA, "sync db-replica")
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SYNC_DB_REPLICA, "sync db-replica")
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_MNODE, "create-mnode" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_MNODE, "drop-mnode" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_DNODE, "create-dnode" )
|
||||
|
|
|
@ -153,7 +153,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
void* output = NULL;
|
||||
int32_t outputLen = 0;
|
||||
code = qParseQuerySql(pRequest->sqlstr, sqlLen, pRequest->requestId, &type, &output, &outputLen, pRequest->msgBuf, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW || type == TSDB_SQL_DROP_USER || type == TSDB_SQL_CREATE_DB) {
|
||||
if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW || type == TSDB_SQL_DROP_USER || type == TSDB_SQL_DROP_ACCT || type == TSDB_SQL_CREATE_DB || type == TSDB_SQL_CREATE_ACCT) {
|
||||
pRequest->type = type;
|
||||
pRequest->body.param = output;
|
||||
pRequest->body.paramLen = outputLen;
|
||||
|
|
|
@ -407,7 +407,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
|
|||
}
|
||||
|
||||
// single table query error need to be handled here.
|
||||
if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_UPDATE_TAGS_VAL) &&
|
||||
if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_UPDATE_TAG_VAL) &&
|
||||
(((rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID)) ||
|
||||
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || rpcMsg->code == TSDB_CODE_APP_NOT_READY)) {
|
||||
|
||||
|
@ -3176,6 +3176,15 @@ int32_t doBuildMsgSupp(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
|
|||
case TSDB_SQL_CREATE_USER:
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_USER;
|
||||
break;
|
||||
case TSDB_SQL_DROP_USER:
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_DROP_USER;
|
||||
break;
|
||||
case TSDB_SQL_CREATE_ACCT:
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_ACCT;
|
||||
break;
|
||||
case TSDB_SQL_DROP_ACCT:
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_DROP_ACCT;
|
||||
break;
|
||||
case TSDB_SQL_CREATE_DB: {
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_DB;
|
||||
|
||||
|
@ -3328,7 +3337,7 @@ void initMsgHandleFp() {
|
|||
tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg;
|
||||
tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg;
|
||||
tscBuildMsg[TSDB_SQL_ALTER_TABLE] = tscBuildAlterTableMsg;
|
||||
tscBuildMsg[TSDB_SQL_UPDATE_TAGS_VAL] = tscBuildUpdateTagMsg;
|
||||
tscBuildMsg[TSDB_SQL_UPDATE_TAG_VAL] = tscBuildUpdateTagMsg;
|
||||
tscBuildMsg[TSDB_SQL_ALTER_DB] = tscAlterDbMsg;
|
||||
tscBuildMsg[TSDB_SQL_COMPACT_VNODE] = tscBuildCompactMsg;
|
||||
|
||||
|
@ -3383,6 +3392,10 @@ void initMsgHandleFp() {
|
|||
handleRequestRspFp[TSDB_SQL_CONNECT] = processConnectRsp;
|
||||
|
||||
buildRequestMsgFp[TSDB_SQL_CREATE_USER] = doBuildMsgSupp;
|
||||
buildRequestMsgFp[TSDB_SQL_DROP_USER] = doBuildMsgSupp;
|
||||
|
||||
buildRequestMsgFp[TSDB_SQL_CREATE_ACCT] = doBuildMsgSupp;
|
||||
buildRequestMsgFp[TSDB_SQL_DROP_ACCT] = doBuildMsgSupp;
|
||||
|
||||
buildRequestMsgFp[TSDB_SQL_SHOW] = doBuildMsgSupp;
|
||||
handleRequestRspFp[TSDB_SQL_SHOW] = processShowRsp;
|
||||
|
|
|
@ -189,7 +189,6 @@ static void doDestroyRequest(void* p) {
|
|||
tfree(pRequest->pInfo);
|
||||
|
||||
if (pRequest->body.pResInfo != NULL) {
|
||||
tfree(pRequest->body.pResInfo->pData);
|
||||
tfree(pRequest->body.pResInfo->pMsg);
|
||||
tfree(pRequest->body.pResInfo);
|
||||
}
|
||||
|
|
|
@ -40,15 +40,22 @@ TEST(testCase, driverInit_Test) {
|
|||
|
||||
TEST(testCase, connect_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
// assert(pConn != NULL);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_user_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
// assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
|
||||
TAOS_RES* pRes = taos_query(pConn, "drop user abc");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create user abc pass 'abc'");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
@ -57,22 +64,48 @@ TEST(testCase, create_user_Test) {
|
|||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, drop_user_Test) {
|
||||
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
TEST(testCase, create_account_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "drop user abc");
|
||||
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, drop_account_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "drop account aabc");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, drop_user_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "drop user abc");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, show_user_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
// assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show users");
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
@ -91,7 +124,7 @@ TEST(testCase, show_user_Test) {
|
|||
|
||||
TEST(testCase, show_db_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
// assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show databases");
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
@ -110,9 +143,9 @@ TEST(testCase, show_db_Test) {
|
|||
|
||||
TEST(testCase, create_db_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
// assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc");
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
ASSERT_TRUE(pFields == NULL);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "taosmsg.h"
|
||||
|
||||
SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen);
|
||||
SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen);
|
||||
SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen);
|
||||
SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, char* msgBuf, int32_t msgLen);
|
||||
|
||||
|
|
|
@ -23,6 +23,21 @@ SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgB
|
|||
return pMsg;
|
||||
}
|
||||
|
||||
SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen) {
|
||||
if (pInfo->pMiscInfo->user.user.n >= TSDB_USER_LEN) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDropUserMsg* pMsg = calloc(1, sizeof(SDropUserMsg));
|
||||
if (pMsg == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0);
|
||||
strncpy(pMsg->user, pName->z, pName->n);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen) {
|
||||
SShowMsg* pShowMsg = calloc(1, sizeof(SShowMsg));
|
||||
|
||||
|
@ -89,7 +104,7 @@ static int32_t setTimePrecision(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreate
|
|||
|
||||
pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default
|
||||
|
||||
SToken* pToken = &pCreateDbInfo->precision;
|
||||
SToken* pToken = (SToken*) &pCreateDbInfo->precision;
|
||||
if (pToken->n > 0) {
|
||||
pToken->n = strdequote(pToken->z);
|
||||
|
||||
|
@ -141,7 +156,6 @@ int32_t setDbOptions(SCreateDbMsg* pCreateDbMsg, const SCreateDbInfo* pCreateDbS
|
|||
|
||||
// todo configurable
|
||||
pCreateDbMsg->numOfVgroups = htonl(2);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -4227,6 +4227,12 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in
|
|||
*output = buildUserManipulationMsg(pInfo, id, msgBuf, msgBufLen);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_DROP_ACCT:
|
||||
case TSDB_SQL_DROP_USER: {
|
||||
*output = buildDropUserMsg(pInfo, id, msgBuf, msgBufLen);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_SQL_SHOW: {
|
||||
code = setShowInfo(pInfo, output, outputLen, pMsgBuf);
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
#include "queryInfoUtil.h"
|
||||
#include <function.h>
|
||||
#include "astGenerator.h"
|
||||
#include "function.h"
|
||||
#include "os.h"
|
||||
#include "queryInfoUtil.h"
|
||||
#include "function.h"
|
||||
#include "parser.h"
|
||||
#include "parserInt.h"
|
||||
#include "parserUtil.h"
|
||||
|
||||
static struct SSchema _s = {
|
||||
|
|
|
@ -294,7 +294,7 @@ void msgInit() {
|
|||
tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg;
|
||||
tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg;
|
||||
tscBuildMsg[TSDB_SQL_ALTER_TABLE] = tscBuildAlterTableMsg;
|
||||
tscBuildMsg[TSDB_SQL_UPDATE_TAGS_VAL] = tscBuildUpdateTagMsg;
|
||||
tscBuildMsg[TSDB_SQL_UPDATE_TAG_VAL] = tscBuildUpdateTagMsg;
|
||||
tscBuildMsg[TSDB_SQL_ALTER_DB] = tscAlterDbMsg;
|
||||
tscBuildMsg[TSDB_SQL_COMPACT_VNODE] = tscBuildCompactMsg;
|
||||
|
||||
|
|
Loading…
Reference in New Issue