1.taos_stmt2_get_stb_fields add query type nums
2.all fields add presision
This commit is contained in:
parent
7a467df812
commit
3146db60a1
|
@ -2109,6 +2109,18 @@ int taos_stmt2_get_stb_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_STB **fie
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STscStmt2 *pStmt = (STscStmt2 *)stmt;
|
||||||
|
if (pStmt->sql.type == 0) {
|
||||||
|
int isInsert = 0;
|
||||||
|
(void)stmtIsInsert2(stmt, &isInsert);
|
||||||
|
if (!isInsert) {
|
||||||
|
pStmt->sql.type = STMT_TYPE_QUERY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pStmt->sql.type == STMT_TYPE_QUERY) {
|
||||||
|
return stmtGetParamNum2(stmt, count);
|
||||||
|
}
|
||||||
|
|
||||||
return stmtGetStbColFields2(stmt, count, fields);
|
return stmtGetStbColFields2(stmt, count, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -960,10 +960,6 @@ int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32
|
||||||
if (tags->numOfBound > 0) {
|
if (tags->numOfBound > 0) {
|
||||||
SSchema* pSchema = getTableTagSchema(pMeta);
|
SSchema* pSchema = getTableTagSchema(pMeta);
|
||||||
|
|
||||||
if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type) {
|
|
||||||
(*fields)[0].precision = pMeta->tableInfo.precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < tags->numOfBound; ++i) {
|
for (int32_t i = 0; i < tags->numOfBound; ++i) {
|
||||||
(*fields)[idx].field_type = TAOS_FIELD_TAG;
|
(*fields)[idx].field_type = TAOS_FIELD_TAG;
|
||||||
|
|
||||||
|
@ -971,16 +967,15 @@ int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32
|
||||||
tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[i].name));
|
tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[i].name));
|
||||||
(*fields)[idx].type = schema->type;
|
(*fields)[idx].type = schema->type;
|
||||||
(*fields)[idx].bytes = schema->bytes;
|
(*fields)[idx].bytes = schema->bytes;
|
||||||
|
if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
|
||||||
|
(*fields)[idx].precision = pMeta->tableInfo.precision;
|
||||||
|
}
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (boundColsInfo.numOfBound > 0) {
|
if (boundColsInfo.numOfBound > 0) {
|
||||||
SSchema* schema = &pSchema[boundColsInfo.pColIndex[0]];
|
SSchema* schema = &pSchema[boundColsInfo.pColIndex[0]];
|
||||||
if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
|
|
||||||
(*fields)[0].precision = pMeta->tableInfo.precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < boundColsInfo.numOfBound; ++i) {
|
for (int32_t i = 0; i < boundColsInfo.numOfBound; ++i) {
|
||||||
int16_t idxCol = boundColsInfo.pColIndex[i];
|
int16_t idxCol = boundColsInfo.pColIndex[i];
|
||||||
|
@ -990,7 +985,8 @@ int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32
|
||||||
tstrncpy((*fields)[i].name, "tbname", sizeof((*fields)[idx].name));
|
tstrncpy((*fields)[i].name, "tbname", sizeof((*fields)[idx].name));
|
||||||
(*fields)[idx].type = TSDB_DATA_TYPE_BINARY;
|
(*fields)[idx].type = TSDB_DATA_TYPE_BINARY;
|
||||||
(*fields)[idx].bytes = TSDB_TABLE_FNAME_LEN;
|
(*fields)[idx].bytes = TSDB_TABLE_FNAME_LEN;
|
||||||
idx++;
|
|
||||||
|
idx++;
|
||||||
continue;
|
continue;
|
||||||
} else if (idxCol < pMeta->tableInfo.numOfColumns) {
|
} else if (idxCol < pMeta->tableInfo.numOfColumns) {
|
||||||
(*fields)[idx].field_type = TAOS_FIELD_COL;
|
(*fields)[idx].field_type = TAOS_FIELD_COL;
|
||||||
|
@ -1002,6 +998,9 @@ int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32
|
||||||
tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[idx].name));
|
tstrncpy((*fields)[idx].name, schema->name, sizeof((*fields)[idx].name));
|
||||||
(*fields)[idx].type = schema->type;
|
(*fields)[idx].type = schema->type;
|
||||||
(*fields)[idx].bytes = schema->bytes;
|
(*fields)[idx].bytes = schema->bytes;
|
||||||
|
if (TSDB_DATA_TYPE_TIMESTAMP == schema->type) {
|
||||||
|
(*fields)[idx].precision = pMeta->tableInfo.precision;
|
||||||
|
}
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ void getFields(TAOS *taos, const char *sql) {
|
||||||
} else {
|
} else {
|
||||||
printf("bind nums:%d\n", fieldNum);
|
printf("bind nums:%d\n", fieldNum);
|
||||||
for (int i = 0; i < fieldNum; i++) {
|
for (int i = 0; i < fieldNum; i++) {
|
||||||
printf("field[%d]: %s, data_type:%d, field_type:%d\n", i, pFields[i].name, pFields[i].type,
|
printf("field[%d]: %s, data_type:%d, field_type:%d, precision:%d\n", i, pFields[i].name, pFields[i].type,
|
||||||
pFields[i].field_type);
|
pFields[i].field_type, pFields[i].precision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("====================================\n");
|
printf("====================================\n");
|
||||||
|
@ -32,6 +32,28 @@ void getFields(TAOS *taos, const char *sql) {
|
||||||
taos_stmt2_close(stmt);
|
taos_stmt2_close(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getQueryFields(TAOS *taos, const char *sql) {
|
||||||
|
TAOS_STMT2_OPTION option = {0};
|
||||||
|
TAOS_STMT2 *stmt = taos_stmt2_init(taos, &option);
|
||||||
|
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||||
|
if (code != 0) {
|
||||||
|
printf("failed to execute taos_stmt2_prepare. error:%s\n", taos_stmt2_error(stmt));
|
||||||
|
taos_stmt2_close(stmt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int fieldNum = 0;
|
||||||
|
TAOS_FIELD_STB *pFields = NULL;
|
||||||
|
code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields);
|
||||||
|
if (code != 0) {
|
||||||
|
printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt));
|
||||||
|
} else {
|
||||||
|
printf("bind nums:%d\n", fieldNum);
|
||||||
|
}
|
||||||
|
printf("====================================\n");
|
||||||
|
taos_stmt2_free_stb_fields(stmt, pFields);
|
||||||
|
taos_stmt2_close(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
void do_query(TAOS *taos, const char *sql) {
|
void do_query(TAOS *taos, const char *sql) {
|
||||||
TAOS_RES *result = taos_query(taos, sql);
|
TAOS_RES *result = taos_query(taos, sql);
|
||||||
int code = taos_errno(result);
|
int code = taos_errno(result);
|
||||||
|
@ -45,7 +67,7 @@ void do_query(TAOS *taos, const char *sql) {
|
||||||
|
|
||||||
void do_stmt(TAOS *taos) {
|
void do_stmt(TAOS *taos) {
|
||||||
do_query(taos, "drop database if exists db");
|
do_query(taos, "drop database if exists db");
|
||||||
do_query(taos, "create database db");
|
do_query(taos, "create database db PRECISION 'ns'");
|
||||||
do_query(taos, "use db");
|
do_query(taos, "use db");
|
||||||
do_query(taos,
|
do_query(taos,
|
||||||
"create table db.stb (ts timestamp, b binary(10)) tags(t1 "
|
"create table db.stb (ts timestamp, b binary(10)) tags(t1 "
|
||||||
|
@ -143,6 +165,18 @@ void do_stmt(TAOS *taos) {
|
||||||
"v11,v12,v13,v14,v15) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
"v11,v12,v13,v14,v15) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||||
printf("case 13 : %s\n", sql);
|
printf("case 13 : %s\n", sql);
|
||||||
getFields(taos, sql);
|
getFields(taos, sql);
|
||||||
|
|
||||||
|
// case 14 : select * from ntb where ts = ?
|
||||||
|
// query type
|
||||||
|
sql = "select * from ntb where ts = ?";
|
||||||
|
printf("case 14 : %s\n", sql);
|
||||||
|
getQueryFields(taos, sql);
|
||||||
|
|
||||||
|
// case 15 : select * from ntb where ts = ? and b = ?
|
||||||
|
// query type
|
||||||
|
sql = "select * from ntb where ts = ? and b = ?";
|
||||||
|
printf("case 15 : %s\n", sql);
|
||||||
|
getQueryFields(taos, sql);
|
||||||
printf("=================error test===================\n");
|
printf("=================error test===================\n");
|
||||||
|
|
||||||
// case 14 : INSERT INTO db.d0 using db.stb values(?,?)
|
// case 14 : INSERT INTO db.d0 using db.stb values(?,?)
|
||||||
|
@ -199,6 +233,12 @@ void do_stmt(TAOS *taos) {
|
||||||
sql = "insert into db.stb values(?,?)";
|
sql = "insert into db.stb values(?,?)";
|
||||||
printf("case 22 : %s\n", sql);
|
printf("case 22 : %s\n", sql);
|
||||||
getFields(taos, sql);
|
getFields(taos, sql);
|
||||||
|
|
||||||
|
// case 23 : select * from ? where ts = ?
|
||||||
|
// wrong query type
|
||||||
|
sql = "select * from ? where ts = ?";
|
||||||
|
printf("case 23 : %s\n", sql);
|
||||||
|
getQueryFields(taos, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
Loading…
Reference in New Issue