public BSONArrayObj ReadBSONArray() { long elements = ReadLong(); BSONArrayObj res = new BSONArrayObj(); for (long x = 0; x < elements; x++) { BSONObj o = ReadBSON(); res.Add(o); } return(res); }
private bool InternalNext() { if (_status == CursorStatus.CS_CLOSED) { throw new ApplicationException("Cursor is Closed"); } bool result = true; if (_count > _pos) { _current = _rows[_pos]; _pos++; } else { if (_status == CursorStatus.CS_LOADING) { BSONArrayObj page = _command.FetchRecords(_cursorId); if (page == null) { _status = CursorStatus.CS_RECORDS_LOADED; result = false; } else { _rows.Add(page); _count += page.Count; result = InternalNext(); } } else { result = false; } } return(result); }
public DjondbCursor ExecuteQuery(string query) { this._network.Reset(); this._network.WriteHeader(); this._network.WriteInt32((int)CommandType.EXECUTEQUERY); WriteOptions(); this._network.WriteString(query); this._network.Flush(); int flag = this._network.ReadInt32(); DjondbCursor cursor = null; if (flag == 1) { CommandType commandType = (CommandType)this._network.ReadInt32(); switch (commandType) { case CommandType.INSERT: ReadResultInsert(); break; case CommandType.BACKUP: ReadResultBackup(); break; case CommandType.COMMIT: ReadResultCommit(); break; case CommandType.CREATEINDEX: ReadResultCreateIndex(); break; case CommandType.DROPNAMESPACE: ReadResultDropNamespace(); break; case CommandType.FIND: cursor = ReadResultFind(); break; case CommandType.REMOVE: ReadResultRemove(); break; case CommandType.ROLLBACK: ReadResultRollbackTransaction(); break; case CommandType.SHOWDBS: string[] dbs = ReadResultShowDbs(); BSONArrayObj arrDbs = new BSONArrayObj(); foreach (string db in dbs) { BSONObj o = new BSONObj(); o.add("db", db); arrDbs.Add(o); } cursor = new DjondbCursor(this, null, arrDbs); break; case CommandType.SHOWNAMESPACES: string[] nss = ReadResultShowNameSpaces(); BSONArrayObj arrNs = new BSONArrayObj(); foreach (string ns in nss) { BSONObj o = new BSONObj(); o.add("ns", ns); arrNs.Add(o); } cursor = new DjondbCursor(this, null, arrNs); break; case CommandType.UPDATE: ReadResultUpdate(); break; } } if (cursor == null) { BSONArrayObj arr = new BSONArrayObj(); BSONObj result = new BSONObj(); result.add("date", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss:nn")); result.add("success", true); arr.Add(result); cursor = new DjondbCursor(this, null, arr); } readErrorInformation(); return(cursor); }