Esempio n. 1
0
        private DjondbCursor ReadResultFind()
        {
            string cursorId = this._network.ReadString();
            int    flag     = this._network.ReadInt32();

            DjondbCursor cursor = null;
            BSONArrayObj arr    = null;

            if (flag == 1)
            {
                arr = _network.ReadBSONArray();
            }
            cursor = new DjondbCursor(this, cursorId, arr);
            readErrorInformation();
            return(cursor);
        }
Esempio n. 2
0
        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);
        }