int main( int argc, char **argv ){ // Init the instructions init_instr_memory(); // CLOCK CYCLE LOOP int instr_buffer; while( 1 ){ // NOTE: Order matters. All functions should fetch value // from pipelined reg before the previous stage override the // reg values write_back(); memory_write(); execute_2(); execute_1(); instruction_decode(); instruction_fetch(); clk++; } free( instruction_memory ); free( data_memory ); exit( 0 ); }
void database::execute(std::string query, std::vector <std::vector <std::string>>& result_set, unsigned int& num_rows, unsigned int& num_cols) { MYSQL_RES *mysql_result = nullptr; // Assume the query returns nothing. num_rows = 0; num_cols = 0; result_set.clear(); // Do the work. execute_1 (query, result_set, nullptr, num_rows, num_cols, mysql_result); // This version of of this member function does not require any more information. // Clean up. if (mysql_result != nullptr) mysql_free_result(mysql_result); }
void database::execute(std::string query, db_row_set& row_set) { MYSQL_RES *mysql_result; MYSQL_FIELD *mysql_fields; // Prepare the base class for the database query. row_set.clear(); // Prepare a child class for the query. row_set.setup_child_phase_1(); // Execute the query. execute_1(query, row_set.result_set, &row_set.null_fields, row_set.my_num_rows, row_set.my_num_cols, mysql_result); // Resize the column descriptor list. row_set.col_desc_list.resize(row_set.my_num_cols); // Copy the required information from the MySQL result-set into the column descriptions. mysql_fields = mysql_fetch_fields(mysql_result); for (unsigned int i = 0; i < row_set.my_num_cols; i++) { // Column name if (mysql_fields[i].name != NULL) row_set.col_desc_list[i].my_name = mysql_fields[i].name; // Column name in the database (aliases are ignored) if (mysql_fields[i].org_name != NULL) row_set.col_desc_list[i].my_name_in_db = mysql_fields[i].org_name; // Database table to which the column belongs if (mysql_fields[i].table != NULL) row_set.col_desc_list[i].my_table = mysql_fields[i].table; // Data length row_set.col_desc_list[i].my_length = mysql_fields[i].length; // Number of decimals for numeric data fields row_set.col_desc_list[i].my_decimals = mysql_fields[i].decimals; // Determine if nulls are allowed row_set.col_desc_list[i].my_null_ok = (0 == (mysql_fields[i].flags & NOT_NULL_FLAG)); // Determine if this column is part of a primary key row_set.col_desc_list[i].my_pri_key = (0 != (mysql_fields[i].flags & PRI_KEY_FLAG)); // Determine if this column auto-increments row_set.col_desc_list[i].my_auto_inc = (0 != (mysql_fields[i].flags & AUTO_INCREMENT_FLAG)); // Data type switch (mysql_fields[i].type) { case MYSQL_TYPE_TINY: if (mysql_fields[i].flags & UNSIGNED_FLAG) row_set.col_desc_list[i].my_type = DB_UNSIGNED_TINYINT; else row_set.col_desc_list[i].my_type = DB_TINYINT; break; case MYSQL_TYPE_SHORT: if (mysql_fields[i].flags & UNSIGNED_FLAG) row_set.col_desc_list[i].my_type = DB_UNSIGNED_SMALLINT; else row_set.col_desc_list[i].my_type = DB_SMALLINT; break; case MYSQL_TYPE_INT24: if (mysql_fields[i].flags & UNSIGNED_FLAG) row_set.col_desc_list[i].my_type = DB_UNSIGNED_MEDIUMINT; else row_set.col_desc_list[i].my_type = DB_MEDIUMINT; break; case MYSQL_TYPE_LONG: if (mysql_fields[i].flags & UNSIGNED_FLAG) row_set.col_desc_list[i].my_type = DB_UNSIGNED_INT; else row_set.col_desc_list[i].my_type = DB_INT; break; case MYSQL_TYPE_LONGLONG: if (mysql_fields[i].flags & UNSIGNED_FLAG) row_set.col_desc_list[i].my_type = DB_UNSIGNED_BIGINT; else row_set.col_desc_list[i].my_type = DB_BIGINT; break; case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_NEWDECIMAL: row_set.col_desc_list[i].my_type = DB_DECIMAL; break; case MYSQL_TYPE_FLOAT: row_set.col_desc_list[i].my_type = DB_FLOAT; break; case MYSQL_TYPE_DOUBLE: row_set.col_desc_list[i].my_type = DB_DOUBLE; break; case MYSQL_TYPE_BIT: row_set.col_desc_list[i].my_type = DB_BIT; break; case MYSQL_TYPE_TIMESTAMP: row_set.col_desc_list[i].my_type = DB_TIMESTAMP; break; case MYSQL_TYPE_DATE: row_set.col_desc_list[i].my_type = DB_DATE; break; case MYSQL_TYPE_TIME: row_set.col_desc_list[i].my_type = DB_TIME; break; case MYSQL_TYPE_DATETIME: row_set.col_desc_list[i].my_type = DB_DATETIME; break; case MYSQL_TYPE_YEAR: row_set.col_desc_list[i].my_type = DB_YEAR; break; case MYSQL_TYPE_STRING: if (mysql_fields[i].charsetnr == 63) row_set.col_desc_list[i].my_type = DB_BINARY; else row_set.col_desc_list[i].my_type = DB_CHAR; break; case MYSQL_TYPE_VAR_STRING: if (mysql_fields[i].charsetnr == 63) row_set.col_desc_list[i].my_type = DB_VARBINARY; else row_set.col_desc_list[i].my_type = DB_VARCHAR; break; case MYSQL_TYPE_BLOB: if (mysql_fields[i].charsetnr == 63) row_set.col_desc_list[i].my_type = DB_BLOB; else row_set.col_desc_list[i].my_type = DB_TEXT; break; case MYSQL_TYPE_SET: row_set.col_desc_list[i].my_type = DB_SET; break; case MYSQL_TYPE_ENUM: row_set.col_desc_list[i].my_type = DB_ENUM; break; case MYSQL_TYPE_GEOMETRY: row_set.col_desc_list[i].my_type = DB_GEOMETRY; break; case MYSQL_TYPE_NULL: row_set.col_desc_list[i].my_type = DB_NULL; break; default: row_set.col_desc_list[i].my_type = DB_UNKNOWN_TYPE; } } // Clean up the MySQL data structures. mysql_free_result(mysql_result); // Allow a child class to prepare its data structures using the query results. row_set.setup_child_phase_2(); }