📄 localcli.cpp
字号:
int size = 0; if (cb->get_fnc != NULL) { src = (char*)cb->get_fnc(cb->var_type, src, &size, cb->name, stmt->id, cb->user_data); } else { if (cb->var_len != NULL) { size = *cb->var_len; } else { return cli_incompatible_type; } } if (cb->var_type == cli_array_of_string) { if (fd->components->type != dbField::tpString) { return cli_incompatible_type; } } else if ((size_t)sizeof_type[cb->var_type - cli_array_of_oid] != fd->components->appSize) { return cli_incompatible_type; } fd->arrayAllocator((dbAnyArray*)dst, src, size); continue; } } return cli_unsupported_type; } return cli_ok;}int cli_insert(int statement, cli_oid_t* oid){ return dbCLI::instance.insert(statement, oid);}int dbCLI::insert(int statement, cli_oid_t* oid){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { sql_scanner scanner(stmt->sql.base()); if (scanner.get() != tkn_insert || scanner.get() != tkn_into || scanner.get() != tkn_ident) { return cli_bad_statement; } int rc = match_columns(scanner.identifier(), stmt); if (rc != cli_ok) { return rc; } stmt->prepared = true; } dbSmallBuffer buf(stmt->table->appSize); char* obj = buf.base(); memset(obj, 0, stmt->table->appSize); dbFieldDescriptor *first = stmt->table->columns, *fd = first; do { if (fd->appType == dbField::tpString) { *(char**)(obj + fd->appOffs) = ""; } } while ((fd = fd->next) != first); char* rec = (char*)buf.base(); int rc = store_columns(rec, stmt); if (rc != cli_ok) { return rc; } dbAnyReference ref; stmt->session->db->insertRecord(stmt->table, &ref, rec); stmt->oid = ref.getOid(); if (oid != NULL) { *oid = ref.getOid(); } if (stmt->n_autoincremented_columns > 0) { for (column_binding* cb = stmt->columns; cb != NULL; cb = cb->next) { if (cb->var_type == cli_autoincrement) { *(cli_int4_t*)cb->var_ptr = *(int4*)(rec + cb->field->appOffs); } } } return cli_ok;}int cli_update(int statement){ return dbCLI::instance.update(statement);}int dbCLI::update(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } if (!stmt->for_update) { return cli_not_update_mode; } if (stmt->updated) { return cli_already_updated; } if (stmt->cursor.isEmpty()) { return cli_not_found; } if (stmt->record_struct == NULL) { dbSmallBuffer buf(stmt->table->appSize); char* record = buf.base(); memset(record, 0, stmt->table->appSize); stmt->cursor.setRecord((byte*)record); stmt->cursor.fetch(); int rc = store_columns(buf.base(), stmt); if (rc != cli_ok) { stmt->cursor.setRecord(NULL); return rc; } stmt->cursor.update(); stmt->cursor.setRecord(NULL); } else { stmt->cursor.update(); } stmt->updated = true; return cli_ok;}int cli_freeze(int statement){ return dbCLI::instance.freeze(statement);}int dbCLI::freeze(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } stmt->cursor.freeze(); return cli_ok;}int cli_unfreeze(int statement){ return dbCLI::instance.unfreeze(statement);}int dbCLI::unfreeze(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } stmt->cursor.unfreeze(); return cli_ok;}int cli_get_first(int statement){ return dbCLI::instance.get_first(statement);}int dbCLI::get_first(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } if (!stmt->cursor.gotoFirst()) { return cli_not_found; } return fetch_columns(stmt);}int cli_get_last(int statement){ return dbCLI::instance.get_last(statement);}int dbCLI::get_last(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } if (!stmt->cursor.gotoLast()) { return cli_not_found; } return fetch_columns(stmt);}int cli_remove_current(int statement){ return dbCLI::instance.remove_current(statement);}int dbCLI::remove_current(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } if (!stmt->for_update) { return cli_not_update_mode; } if (stmt->cursor.isEmpty()) { return cli_not_found; } stmt->cursor.remove(); return cli_ok;}int cli_get_next(int statement){ return dbCLI::instance.get_next(statement);}int dbCLI::get_next(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } if (!((stmt->first_fetch && stmt->cursor.gotoFirst()) || (!stmt->first_fetch && stmt->cursor.moveNext()))) { return cli_not_found; } return fetch_columns(stmt);}int cli_get_prev(int statement){ return dbCLI::instance.get_prev(statement);}int dbCLI::get_prev(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } if (!((stmt->first_fetch && stmt->cursor.gotoLast()) || (!stmt->first_fetch && stmt->cursor.movePrev()))) { return cli_not_found; } return fetch_columns(stmt);}int cli_skip(int statement, int n){ return dbCLI::instance.skip(statement, n);}int dbCLI::skip(int statement, int n){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } if ((n > 0 && !((stmt->first_fetch && stmt->cursor.gotoFirst() && stmt->cursor.skip(n-1) || (!stmt->first_fetch && stmt->cursor.skip(n))))) || (n < 0 && !((stmt->first_fetch && stmt->cursor.gotoLast() && stmt->cursor.skip(n+1) || (!stmt->first_fetch && stmt->cursor.skip(n)))))) { return cli_not_found; } return fetch_columns(stmt);}int cli_seek(int statement, cli_oid_t oid){ return dbCLI::instance.seek(statement, oid);}int dbCLI::seek(int statement, cli_oid_t oid){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } if (!stmt->prepared) { return cli_not_fetched; } int pos = stmt->cursor.seek(oid); if (pos < 0) { return cli_not_found; } int rc = fetch_columns(stmt); if (rc == cli_ok) { return pos; } else { return rc; }}cli_oid_t cli_get_oid(int statement){ return dbCLI::instance.get_current_oid(statement);}cli_oid_t dbCLI::get_current_oid(int statement){ statement_desc* s = statements.get(statement); if (s == NULL) { return (cli_oid_t)cli_bad_descriptor; } return s->cursor.currId;}int cli_free(int statement){ return dbCLI::instance.free_statement(statement);}int dbCLI::free_statement(int statement){ statement_desc* stmt = statements.get(statement); if (stmt == NULL) { return cli_bad_descriptor; } return free_statement(stmt);}int dbCLI::free_statement(statement_desc* stmt){ { dbCriticalSection cs(stmt->session->mutex); statement_desc *sp, **spp = &stmt->session->stmts; while ((sp = *spp) != stmt) { if (sp == NULL) { return cli_bad_descriptor; } spp = &sp->next; } *spp = stmt->next; } return release_statement(stmt);}int dbCLI::release_statement(statement_desc* stmt){ column_binding *cb, *next_cb; for (cb = stmt->columns; cb != NULL; cb = next_cb) { next_cb = cb->next; delete[] cb->name; column_allocator.free(cb); } parameter_binding *pb, *next_pb; for (pb = stmt->params; pb != NULL; pb = next_pb) { next_pb = pb->next; delete[] pb->name; parameter_allocator.free(pb); } if (stmt->cursor.db != NULL) { stmt->cursor.reset(); } statements.free(stmt); return cli_ok;}int cli_commit(int session){ return dbCLI::instance.commit(session);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -