/* * Find the name of the specified table, using aliases and join aliases * where appropriate. */ struct table * findaliastable(struct func *fp, char *tname) { struct join *jp; if (fp->alias != NULL && strcmp(fp->alias, tname) == 0) { /* * OK, it's an alias for this table. */ return(fp->table); } /* * Now look through the list of joined tables... */ for (jp = fp->joins; jp != NULL; jp = jp->next) { if (strcmp(jp->alias, tname) == 0) { /* * OK, it's an alias for a joined table. */ return(fp->table); } } /* * OK, now look through the main list of tables... */ return(findtable(tname)); }
void deltable(list **head, list **tail) { list *temp; temp = findtable(*head); if (!temp) return; else if (temp == *head) { *head = (*head)->next; if (*head != NULL) { (*head)->prev = NULL; } free(temp); } else if (temp == *tail) { *tail = temp->prev; if (*tail != NULL) (*tail)->next = NULL; free(temp); } else { temp->prev->next = temp->next; temp->next->prev = temp->prev; free(temp); } }
struct func * newfunction(char *table, int flags) { struct func *fp; if ((fp = (struct func *)malloc(sizeof(struct func))) == NULL) { fprintf(stderr, "dbow: out of memory.\n"); exit(1); } if ((fp->table = findtable(table)) == NULL) { yyerror("invalid table name for function"); return(NULL); } fp->next = NULL; fp->type = DBOW_OTHER; fp->pkey = NULL; fp->name = NULL; fp->query = fp->where = fp->order = NULL; fp->args = fp->rets = NULL; fp->joins = NULL; fp->alias = NULL; fp->shead = fp->stail = NULL; fp->limit = fp->offset = fp->flags = 0; if (fhead == NULL) fhead = fp; else ftail->next = fp; ftail = fp; return(fp); }
bool insert_searchers_table(lua::state* ls) { findtable(ls, LUA_REGISTRYINDEX, "_LOADED", 1); ls->getfield(-1, LUA_LOADLIBNAME); if (ls->istable(-1)) { ls->getfield(-1, "searchers"); if (ls->istable(-1)) { lua_pushliteral(ls->self(), ""); for (int i = 1; ; i++) { ls->rawgeti(-2, i); if (ls->isnil(-1)) { ls->pushcclosure(searcher_storm, 0); ls->rawseti(-4, i); return true; } ls->pop(1); } } } return false; }
void killvar(list *head) { list *temp; temp = findtable(head); if (!temp) return; delvar(&temp->head, &temp->tail); }
void simpleinput(list *head) { list *temp; temp = findtable(head); if (temp != NULL) { temp->current = makevarnode(); putvar(&temp->head, &temp->tail, temp->current, head); temp->current->current = makedatanode(); putnode(&temp->current->head, &temp->current->tail, temp->current->current, head); } }
struct join * newjoin(char *table, char *alias) { struct join *jp; if ((jp = (struct join *)malloc(sizeof(struct join))) == NULL) return(NULL); jp->next = NULL; jp->table = findtable(table); jp->alias = alias; return(jp); }
void printtable(list *head) { list *temp; temp = findtable(head); if (temp != NULL) { printlist(temp->head); } else { puts("테이블이 없습니다."); } }
void search(list *head) { list *temp; temp = findtable(head); if (!temp) { puts("테이블이 없습니다."); } else { if (!search_var(temp->head)) { } } }
bool clear_searchers_table(lua::state* ls) { findtable(ls, LUA_REGISTRYINDEX, "_LOADED", 1); ls->getfield(-1, LUA_LOADLIBNAME); if (ls->istable(-1)) { ls->createtable(2, 0); ls->pushvalue(-2); ls->pushcclosure(searcher_preload, 1); ls->rawseti(-2, 1); ls->setfield(-2, "searchers"); return true; } return false; }