从sql解析器中提取订单类型
使用从sql解析器中提取订单类型,sql,parsing,general-sql-parser,Sql,Parsing,General Sql Parser,使用全局sql解析器(gsp)从order sql查询中提取列和排序类型,并从where条件中提取and或 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 如果psqlsmt是gsp_selectState
全局sql解析器(gsp)
从order sql查询中提取列和排序类型,并从where条件中提取and或
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
如果psqlsmt是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;
}
}
if(psqlsmt->orderbyClause!=nullptr)
{
字符串排序类型;
int colNumOrderBy=psqlsmt->orderbyClause->items->length;
for(int i=0;iorderbyClause->items->head));
//按列名获取订单
char*sortCol=gsp_node_text(重新解释强制转换(字段->排序键));
如果(字段->sortToken==nullptr)
{
//错误
}
其他的
{
//找出分拣类型(ASC/DESC)
sortType=sortType.substr(0,字段->sortToken->nStrLen);
}
免费(sortCol);
psqlsmt->orderbyClause->items->head=psqlsmt->orderbyClause->items->head->nextCell;
}
}
老实说,如果你的问题是用阿拉伯语写的,我会更容易理解它(我会读阿拉伯语)。订单类型由selectزا㶈㶈㶈㶈㶦㶦㶦中的select㶈㶈㶈㶈㶈㶦㶦㶦㶦㶦㶦㶦,从这个选择中,DESC似乎不符合问题(C++根据标签要求而不是SQL),乔,我知道通用SQL分析器(GSP)附带java、VCL、C++和C++版本。这是C++的解决方案。