用于 global sql parser (gsp)
从 order sql 查询中提取列和排序类型,并从 where 条件中提取和或
SELECT employee_id, dept, name, age, salary
FROM employee_info
WHERE dept = 'Sales' and ID=1
ORDER BY salary, age DESC,ID;
我可以提取列名,但可以提取订单类型
1-如何提取订单类型?
2-如何提取和,或从哪里sql?
用于 global sql parser (gsp)
从 order sql 查询中提取列和排序类型,并从 where 条件中提取和或
SELECT employee_id, dept, name, age, salary
FROM employee_info
WHERE dept = 'Sales' and ID=1
ORDER BY salary, age DESC,ID;
我可以提取列名,但可以提取订单类型
1-如何提取订单类型?
2-如何提取和,或从哪里sql?
如果pSqlstmt是gsp_selectStatement * 那么你可以这样做:
if(pSqlstmt->orderbyClause != nullptr)
{
string sortType;
int colNumOrderBy = pSqlstmt->orderbyClause->items->length;
for(int i = 0; i < colNumOrderBy; i++)
{
gsp_orderByItem *field = reinterpret_cast<gsp_orderByItem *>(gsp_list_celldata(pSqlstmt->orderbyClause->items->head));
//get order by column name
char *sortCol = gsp_node_text(reinterpret_cast<gsp_node*>(field->sortKey));
if(field->sortToken== nullptr)
{
//ERROR
}
else
{
//find out sorting type (ASC/DESC)
sortType = sortType.substr(0,field->sortToken->nStrLen);
}
free(sortCol);
pSqlstmt->orderbyClause->items->head = pSqlstmt->orderbyClause->items->head->nextCell;
}
}