void Parser::process_command(InputType type) { switch (type){ case CREATE_: create_table(); break; case INSERT_: insert_into(); break; case OPEN_: open(); break; case CLOSE_: close(); break; case WRITE_: write(); break; case SHOW_: show(); break; case EXIT_: exit(); break; case DELETE_: delete_from(); break; case UPDATE_: update_to(); break; default: break; } }
int _exec_stmt(DB * db, stmt_t * stmt) { switch (stmt->type) { case STMT_CREAT_TABLE: return create_table(db, stmt->table, stmt->cols, stmt->ncol); case STMT_DROP_TABLE: return drop_table(db, stmt->table); case STMT_CREAT_INDEX: return create_index(db, stmt->table, stmt->attr, stmt->index); case STMT_DROP_INDEX: return drop_index(db, stmt->index); case STMT_INSERT: return insert_into(db, stmt->table, NULL, stmt->vals, stmt->nval); case STMT_DELETE: return delete_from(db, stmt->table, stmt->conds, stmt->ncond); case STMT_SELECT: return select_and_print(db, stmt->table, stmt->cols, stmt->ncol, stmt->conds, stmt->ncond); } xerrno = ERR_INVSTMT; return -1; }
/**************************************************** * Function: cbInit * Description: ***************************************************/ int main() { int bytes_recv; //struct recv_struct array[5]; int i=0; /*array[0].seq_no = 0; array[0].AERT.tv_usec = ADD_TIME(total_elapsed_time,30); printf("seq %d, time %u\n",array[0].seq_no ,array[0].AERT.tv_usec); array[0].AERT.tv_sec = total_elapsed_time.tv_sec; array[0].mode =0; array[1].seq_no = 2; array[1].AERT.tv_usec = ADD_TIME(total_elapsed_time,40); printf("seq %d, time %u\n",array[1].seq_no, array[1].AERT.tv_usec); array[1].AERT.tv_sec = total_elapsed_time.tv_sec; array[1].mode =0; array[2].seq_no = 3; array[2].AERT.tv_usec = ADD_TIME(total_elapsed_time,20); array[2].AERT.tv_sec = total_elapsed_time.tv_sec; array[2].mode =0; array[4].seq_no = 3; array[4].AERT.tv_usec = ADD_TIME(total_elapsed_time,40); array[4].AERT.tv_sec = total_elapsed_time.tv_sec; array[4].mode =1; array[3].seq_no = 2; array[3].AERT.tv_usec = ADD_TIME(total_elapsed_time,40); array[3].AERT.tv_sec = total_elapsed_time.tv_sec; array[3].mode =1;*/ /*START:Establish connection as a server with tcpd_m2 as a client on port 1052*/ TIMER_in_socket = socket(AF_INET, SOCK_DGRAM, 0); TIMER_addr.sin_family = AF_INET; // Address family to use TIMER_addr.sin_port = htons(TIMER_PORT_IN); // Port number to use TIMER_addr.sin_addr.s_addr = htonl(INADDR_ANY); // Listen on any IP address if(bind(TIMER_in_socket, (struct sockaddr *)&TIMER_addr, sizeof(TIMER_addr))!=0) { perror("Binding failure tcpd_m2\n"); return 1; } /*END:Establish connection as a server with tcpd_m2 as a client on port 1052*/ addr_len = sizeof(struct sockaddr_in); while(1) { //printf("Iteration %d\n",i); //from_tcpd = array[i]; /*START:Recv data from TCPD*/ struct in_addr addr; int ret; /* fd_set is a fixed sized buffer */ fd_set TIMER_in_set; /* FD_ZERO clears a set */ FD_ZERO(&TIMER_in_set); /* FD_SET - adds the given file descriptor to the set */ FD_SET(TIMER_in_socket,&TIMER_in_set); ret = select(TIMER_in_socket+1, &TIMER_in_set, NULL, NULL, NULL); if (FD_ISSET(TIMER_in_socket, &TIMER_in_set)) { bytes_recv = recvfrom(TIMER_in_socket,&from_tcpd, sizeof (from_tcpd), 0, (struct sockaddr *)&TCPDM2_addr, &addr_len); /*END:Recv data from TCPD*/ addr.s_addr = TCPDM2_addr.sin_addr.s_addr; printf("Received seq %u sec %u usec %u from %s %u mode %d\n" ,from_tcpd.seq_no,from_tcpd.AERT.tv_sec,from_tcpd.AERT.tv_usec, inet_ntoa(addr),ntohs(TCPDM2_addr.sin_port),from_tcpd.mode); switch (from_tcpd.mode) { case INSERT_MODE: insert_into(); break; case DELETE_MODE: delete_from(); break; } print_list(); printf("\n"); } } /*START:Recv data from TCPD*/ return 0; }