void testStore(void) { // setup struct Command* createDatabaseCommand = createCreateDatabaseCommand("test_store"); createDatabase(createDatabaseCommand); char names[FIELD_SIZE][NAME_LIMIT] = { "name1", "name2", "name3", "name4", }; char values[FIELD_SIZE][VALUE_LIMIT] = { "1", "value2", "1/1/2015", "3", }; FieldType types[FIELD_SIZE][1] = { INTEGER, TEXT, DATE, INTEGER, }; struct Field* fields = createFieldList(names, values, types, 4); struct Command* createTableCmd = createCreateTableCommand("table", fields); createTable(createTableCmd); // test struct Command* insertCmd = createInsertCommand("table", fields); insertTuple(insertCmd); values[0][0] = '2'; insertTuple(insertCmd); // teardown destroyCommand(createDatabaseCommand); destroyCommand(createTableCmd); }
QString Table::getInitialDataCommands(void) { QStringList buffer=initial_data.split(DATA_LINE_BREAK); if(!buffer.isEmpty() && !buffer.at(0).isEmpty()) { QStringList col_names, col_values, commands, selected_cols; int curr_col=0; QList<int> ignored_cols; col_names=(buffer.at(0)).split(DATA_SEPARATOR); col_names.removeDuplicates(); buffer.removeFirst(); //Separating valid columns (selected) from the invalids (ignored) for(QString col_name : col_names) { if(getObjectIndex(col_name, OBJ_COLUMN) >= 0) selected_cols.append(col_name); else ignored_cols.append(curr_col); curr_col++; } for(QString buf_row : buffer) { curr_col=0; //Filtering the invalid columns' values for(QString value : buf_row.split(DATA_SEPARATOR)) { if(ignored_cols.contains(curr_col)) continue; col_values.append(value); } commands.append(createInsertCommand(selected_cols, col_values)); col_values.clear(); } return(commands.join('\n')); } return(QString()); }