libidav/davqlparser.c

changeset 49
2f71f4ee247a
parent 1
b5bb7b3cd597
equal deleted inserted replaced
48:ae61523bce20 49:2f71f4ee247a
103 } 103 }
104 } 104 }
105 105
106 static void dav_debug_ql_stmt_print(DavQLStatement *stmt) { 106 static void dav_debug_ql_stmt_print(DavQLStatement *stmt) {
107 // Basic information 107 // Basic information
108 size_t fieldcount = stmt->fields ? stmt->fields->size : 0; 108 size_t fieldcount = stmt->fields ? cxListSize(stmt->fields) : 0;
109 int specialfield = 0; 109 int specialfield = 0;
110 if (stmt->fields && stmt->fields->size > 0) { 110 if (fieldcount > 0) {
111 DavQLField* firstfield = (DavQLField*)cxListAt(stmt->fields, 0); 111 DavQLField* firstfield = (DavQLField*)cxListAt(stmt->fields, 0);
112 if (firstfield->expr->type == DAVQL_IDENTIFIER) { 112 if (firstfield->expr->type == DAVQL_IDENTIFIER) {
113 switch (firstfield->expr->srctext.ptr[0]) { 113 switch (firstfield->expr->srctext.ptr[0]) {
114 case '*': specialfield = 1; break; 114 case '*': specialfield = 1; break;
115 case '-': specialfield = 2; break; 115 case '-': specialfield = 2; break;
144 if (stmt->orderby) { 144 if (stmt->orderby) {
145 CxIterator i = cxListIterator(stmt->orderby); 145 CxIterator i = cxListIterator(stmt->orderby);
146 cx_foreach(DavQLOrderCriterion*, critdata, i) { 146 cx_foreach(DavQLOrderCriterion*, critdata, i) {
147 printf("%.*s %s%s", (int)critdata->column->srctext.length, critdata->column->srctext.ptr, 147 printf("%.*s %s%s", (int)critdata->column->srctext.length, critdata->column->srctext.ptr,
148 critdata->descending ? "desc" : "asc", 148 critdata->descending ? "desc" : "asc",
149 i.index+1 < stmt->orderby->size ? ", " : "\n"); 149 i.index+1 < cxListSize(stmt->orderby) ? ", " : "\n");
150 } 150 }
151 } else { 151 } else {
152 printf("nothing\n"); 152 printf("nothing\n");
153 } 153 }
154 154
294 case DQLD_CMD_PT: dav_debug_ql_tree_print(examineexpr, 1); break; 294 case DQLD_CMD_PT: dav_debug_ql_tree_print(examineexpr, 1); break;
295 case DQLD_CMD_PF: dav_debug_ql_fnames_print(stmt); break; 295 case DQLD_CMD_PF: dav_debug_ql_fnames_print(stmt); break;
296 case DQLD_CMD_F: 296 case DQLD_CMD_F:
297 examineclause = DQLD_CMD_F; 297 examineclause = DQLD_CMD_F;
298 examineelem = stmt->fields; 298 examineelem = stmt->fields;
299 if (stmt->fields && stmt->fields->size > 0) { 299 if (stmt->fields && cxListSize(stmt->fields) > 0) {
300 DavQLField* field = cxListAt(stmt->fields, 0); 300 DavQLField* field = cxListAt(stmt->fields, 0);
301 examineexpr = field->expr; 301 examineexpr = field->expr;
302 dav_debug_ql_field_print(field); 302 dav_debug_ql_field_print(field);
303 } else { 303 } else {
304 examineexpr = NULL; 304 examineexpr = NULL;
310 dav_debug_ql_expr_print(examineexpr); 310 dav_debug_ql_expr_print(examineexpr);
311 break; 311 break;
312 case DQLD_CMD_O: 312 case DQLD_CMD_O:
313 examineclause = DQLD_CMD_O; 313 examineclause = DQLD_CMD_O;
314 examineelem = stmt->orderby; 314 examineelem = stmt->orderby;
315 examineexpr = stmt->orderby && stmt->orderby->size > 0 ? 315 examineexpr = stmt->orderby && cxListSize(stmt->orderby) > 0 ?
316 ((DavQLOrderCriterion*)cxListAt(stmt->orderby, 0))->column : NULL; 316 ((DavQLOrderCriterion*)cxListAt(stmt->orderby, 0))->column : NULL;
317 dav_debug_ql_expr_print(examineexpr); 317 dav_debug_ql_expr_print(examineexpr);
318 break; 318 break;
319 case DQLD_CMD_N: 319 case DQLD_CMD_N:
320 case DQLD_CMD_P: 320 case DQLD_CMD_P:
1090 if (token_is(token, DAVQL_TOKEN_COMMA)) { 1090 if (token_is(token, DAVQL_TOKEN_COMMA)) {
1091 total_consumed++; token = token->next; 1091 total_consumed++; token = token->next;
1092 DavQLField localfield; 1092 DavQLField localfield;
1093 consumed = dav_parse_named_field(stmt, token, &localfield); 1093 consumed = dav_parse_named_field(stmt, token, &localfield);
1094 if (!stmt->errorcode && consumed) { 1094 if (!stmt->errorcode && consumed) {
1095 DavQLField *field; 1095 DavQLField *add_field;
1096 dqlsec_malloc(stmt, field, DavQLField); 1096 dqlsec_malloc(stmt, add_field, DavQLField);
1097 memcpy(field, &localfield, sizeof(DavQLField)); 1097 memcpy(add_field, &localfield, sizeof(DavQLField));
1098 if(dav_stmt_add_field(stmt, field)) { 1098 if(dav_stmt_add_field(stmt, add_field)) {
1099 free(field); 1099 free(add_field);
1100 return 0; 1100 return 0;
1101 } 1101 }
1102 } 1102 }
1103 } else { 1103 } else {
1104 consumed = 0; 1104 consumed = 0;
1836 return stmt; 1836 return stmt;
1837 } 1837 }
1838 1838
1839 void dav_free_statement(DavQLStatement *stmt) { 1839 void dav_free_statement(DavQLStatement *stmt) {
1840 if(stmt->fields) { 1840 if(stmt->fields) {
1841 stmt->fields->simple_destructor = (cx_destructor_func)dav_free_field; 1841 cxDefineDestructor(stmt->fields, dav_free_field);
1842 cxListDestroy(stmt->fields); 1842 cxListDestroy(stmt->fields);
1843 } 1843 }
1844 1844
1845 if (stmt->where) { 1845 if (stmt->where) {
1846 dav_free_expression(stmt->where); 1846 dav_free_expression(stmt->where);
1848 if (stmt->errormessage) { 1848 if (stmt->errormessage) {
1849 free(stmt->errormessage); 1849 free(stmt->errormessage);
1850 } 1850 }
1851 1851
1852 if(stmt->orderby) { 1852 if(stmt->orderby) {
1853 stmt->orderby->simple_destructor = (cx_destructor_func)dav_free_order_criterion; 1853 cxDefineDestructor(stmt->orderby, dav_free_order_criterion);
1854 cxListDestroy(stmt->orderby); 1854 cxListDestroy(stmt->orderby);
1855 } 1855 }
1856 if(stmt->args) { 1856 if(stmt->args) {
1857 cxListDestroy(stmt->args); 1857 cxListDestroy(stmt->args);
1858 } 1858 }

mercurial