parsing - Extracting order type from sql parser -
using global sql parser (gsp)
extracting column , sorting type order sql query , extract , or condition
select employee_id, dept, name, age, salary employee_info dept = 'sales' , id=1 order salary, age desc,id;
i can extracting column name can extract order type
1- how can extract order type?
2- how can extract , , or sql?
if psqlstmt gsp_selectstatement * can this:
if(psqlstmt->orderbyclause != nullptr) { string sorttype; int colnumorderby = psqlstmt->orderbyclause->items->length; for(int = 0; < colnumorderby; i++) { gsp_orderbyitem *field = reinterpret_cast<gsp_orderbyitem *>(gsp_list_celldata(psqlstmt->orderbyclause->items->head)); //get order 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; } }
Comments
Post a Comment