/***********************************************************************//** * @brief Append rows to the table * * @param[in] nrows Number of rows to be appended. * * This method appends rows to a FITS table. This implies that all columns * will be loaded into memory. ***************************************************************************/ void GFitsTable::append_rows(const int& nrows) { // Set row number for insertion to end of the file int rownum = this->nrows(); // Insert rows insert_rows(rownum, nrows); // Return return; }
static ib_err_t test_phase_I(void) /*==============*/ { int i; ib_err_t err; int dups = 0; err = create_database(DATABASE); assert(err == DB_SUCCESS); err = create_table(DATABASE, TABLE); assert(err == DB_SUCCESS); for (i = 0; i < N_TRX; ++i) { ib_crsr_t crsr; ib_trx_t ib_trx; ib_trx = ib_trx_begin(IB_TRX_REPEATABLE_READ); assert(ib_trx != NULL); err = open_table(DATABASE, TABLE, ib_trx, &crsr); assert(err == DB_SUCCESS); err = ib_cursor_lock(crsr, IB_LOCK_IX); assert(err == DB_SUCCESS); err = insert_rows(crsr, i * N_RECS, N_RECS); assert(err == DB_SUCCESS || err == DB_DUPLICATE_KEY); if (err == DB_DUPLICATE_KEY) { ++dups; } err = ib_cursor_close(crsr); assert(err == DB_SUCCESS); crsr = NULL; err = ib_trx_commit(ib_trx); assert(err == DB_SUCCESS); } assert(dups == 0 || dups == N_TRX); return(dups == N_TRX ? DB_DUPLICATE_KEY : DB_SUCCESS); }
err_t insert_filled_rows(Ledger *ledger, char **entries, int row, int howmany){ int field, i; char local_entry[ENTRYSIZE]; /* Check for bad input */ if(ledger == NULL || entries == NULL) return LFAILURE; for(field = 0; field < NFIELDS; ++field) if(strlen(entries[field]) >= ENTRYSIZE){ fprintf(stderr, "Error: entries[field] too big.\n"); return LFAILURE; } if(row < 0 || row > ledger->nrows){ fprintf(stderr, "Error: illegal row index \"%d\" in edit_row().\n", row); return LFAILURE; } /* insert new blank rows */ insert_rows(ledger, row, howmany); /* fill that blank row with input */ for(field = 0; field < NFIELDS; ++field) for(i = 0; i < howmany; ++i) if(edit_entry_noretotal(ledger, entries[field], row + i, field, 0) == LFAILURE) continue; if(retotal(ledger) == LFAILURE) return LFAILURE; return LSUCCESS; }
command(TableUI *tui, int cmd) { switch (cmd) { case CmdClearFile: clear_file(tui); break; case CmdOpenFile: clear_and_open(tui, tui->filename); if (row_count(tui->table) < MAX_ROWS_FOR_FIT && max_col_count(tui->table) < MAX_COLS_FOR_FIT) { unsigned i; for (i = 0; i < max_col_count(tui->table); i++) auto_resize_col(tui, i); } break; case CmdSaveFile: save_csv(tui, tui->filename); break; case CmdSetAnchor: set_anchor(tui); break; case CmdClearAnchor: clear_anchor(tui); break; case CmdClearRow: clear_selected_rows(tui); break; case CmdDeleteRow: delete_selected_rows(tui); break; case CmdDeleteCell: delete_selected_cells(tui); break; case CmdClearCell: clear_selected_cells(tui); break; case CmdCopy: copy_to_clipboard(tui); break; case CmdCutClear: copy_to_clipboard(tui); clear_selected_cells(tui); break; case CmdCutDelete: copy_to_clipboard(tui); delete_selected_cells(tui); break; case CmdPaste: clear_anchor(tui); paste_clipboard(tui); break; case CmdReturn: clear_anchor(tui); move_cursor(tui, 1, 0); break; case CmdTab: clear_anchor(tui); move_cursor(tui, 0, 1); break; case CmdUnReturn: clear_anchor(tui); move_cursor(tui, -1, 0); break; case CmdUnTab: clear_anchor(tui); move_cursor(tui, 0, -1); break; case CmdEditCell: start_edit(tui, 1); break; case CmdEditCellClear: start_edit(tui, 0); break; case CmdCommitEdit: end_edit(tui); break; case CmdCancelEdit: cancel_edit(tui); break; case CmdMoveUp: move_cursor(tui, -1, 0); break; case CmdMoveDown: move_cursor(tui, 1, 0); break; case CmdMoveLeft: move_cursor(tui, 0, -1); break; case CmdMoveRight: move_cursor(tui, 0, 1); break; case CmdScrollUp: scroll(tui, -1, 0); break; case CmdScrollDown: scroll(tui, 1, 0); break; case CmdScrollLeft: scroll(tui, 0, -1); break; case CmdScrollRight: scroll(tui, 0, 1); break; case CmdHomeCol: jump_cursor(tui, 0, tui->cur_col); break; case CmdHomeRow: jump_cursor(tui, tui->cur_row, 0); break; case CmdEndCol: jump_cursor(tui, row_count(tui->table) - 1, tui->cur_col); break; case CmdEndRow: jump_cursor(tui, tui->cur_row, col_count(tui->table, tui->cur_row) - 1); break; case CmdInsertDate: insert_datetime(tui, 0); break; case CmdInsertDateTime: insert_datetime(tui, 1); break; case CmdInsertCell: insert_cells(tui->table, tui->cur_row, tui->cur_col, 1); redraw_rows(tui, tui->cur_row, tui->cur_row); break; case CmdInsertRow: insert_rows(tui->table, tui->cur_row, 1); redraw_rows(tui, tui->cur_row, -1); break; case CmdFindColumn: find_cell_text_col(tui, tui->cur_row, tui->cur_col, tui->find_text); break; case CmdFindRow: find_cell_text_row(tui, tui->cur_row, tui->cur_col, tui->find_text); break; } }
int main(int argc, char* argv[]) { ib_err_t err; ib_crsr_t crsr; ib_trx_t ib_trx; (void)argc; (void)argv; err = ib_init(); assert(err == DB_SUCCESS); test_configure(); err = ib_startup("barracuda"); assert(err == DB_SUCCESS); err = create_database(DATABASE); assert(err == DB_SUCCESS); printf("Create table\n"); err = create_table(DATABASE, TABLE); assert(err == DB_SUCCESS); printf("Begin transaction\n"); ib_trx = ib_trx_begin(IB_TRX_REPEATABLE_READ); assert(ib_trx != NULL); printf("Open cursor\n"); err = open_table(DATABASE, TABLE, ib_trx, &crsr); assert(err == DB_SUCCESS); printf("Lock table in IX\n"); err = ib_cursor_lock(crsr, IB_LOCK_IX); assert(err == DB_SUCCESS); printf("Insert rows\n"); err = insert_rows(crsr); assert(err == DB_SUCCESS); printf("Query table\n"); err = do_query(crsr); assert(err == DB_SUCCESS); printf("Close cursor\n"); err = ib_cursor_close(crsr); assert(err == DB_SUCCESS); crsr = NULL; printf("Commit transaction\n"); err = ib_trx_commit(ib_trx); assert(err == DB_SUCCESS); printf("Drop table\n"); err = drop_table(DATABASE, TABLE); assert(err == DB_SUCCESS); err = ib_shutdown(IB_SHUTDOWN_NORMAL); assert(err == DB_SUCCESS); #ifdef UNIV_DEBUG_VALGRIND VALGRIND_DO_LEAK_CHECK; #endif return(EXIT_SUCCESS); }