Ejemplo n.º 1
0
        public override int ExecuteNonQuery()
        {
            if (_connection == null)
            {
                throw new Exception("You must set the Connection property before execution.");
            }
            if (string.IsNullOrEmpty(_commandText))
            {
                throw new Exception("Invalid query specified.");
            }

            ICollection <Common.Server.Engine.IParameter> _params = new List <Common.Server.Engine.IParameter>();

            Alachisoft.NosDB.Common.Storage.Caching.QueryCache.QueryCache <IDqlObject> queryParser = new Alachisoft.NosDB.Common.Storage.Caching.QueryCache.QueryCache <IDqlObject>();
            IDqlObject parsedQuery = queryParser.GetParsedQuery(_commandText);

            foreach (IDataParameter idp in _parameters)
            {
                _params.Add(new Common.Server.Engine.Impl.Parameter(idp.ParameterName, idp.Value));
            }
            Client.Collection <JSONDocument> coll = ((NosDbConnection)_connection)._database.GetCollection(((IDmObject)parsedQuery).Collection);

            long val = coll.ExecuteNonQuery(_commandText, _params);

            //ICollectionReader value = _connection._database.ExecuteQuery(query);

            return((int)val);
        }
Ejemplo n.º 2
0
        protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
            if (_connection == null)
            {
                throw new Exception("You must set the Connection property before execution.");
            }
            if (string.IsNullOrEmpty(_commandText))
            {
                throw new Exception("Invalid query specified.");
            }
            if (_connection.State != ConnectionState.Open)
            {
                throw new Exception("Connection must be open to execute the command.");
            }

            try
            {
                ArrayList al = new ArrayList();
                ICollection <Common.Server.Engine.IParameter> _params = new List <Common.Server.Engine.IParameter>();

                Alachisoft.NosDB.Common.Storage.Caching.QueryCache.QueryCache <IDqlObject> queryParser = new Alachisoft.NosDB.Common.Storage.Caching.QueryCache.QueryCache <IDqlObject>();
                IDqlObject parsedQuery = queryParser.GetParsedQuery(_commandText);

                if (parsedQuery != null && parsedQuery is SelectObject)
                {
                    SelectObject select = parsedQuery as SelectObject;
                    if (select.Projections != null)
                    {
                        al = new ArrayList();
                        foreach (IEvaluable projection in select.Projections)
                        {
                            string prjct = "";
                            if (projection is BinaryExpression)
                            {
                                prjct = ((BinaryExpression)projection).Alias;
                            }
                            else
                            {
                                prjct = projection.CaseSensitiveInString.Replace("$", "");
                            }

                            if (!prjct.Contains('*'))
                            {
                                if (prjct.Contains('.')) // Incase of embedded, take the last one out.
                                {
                                    string[] parts = prjct.Split('.');
                                    prjct = parts[parts.Length - 1];
                                }
                                al.Add(prjct);
                            }
                        }
                    }
                }

                foreach (IDataParameter idp in _parameters)
                {
                    _params.Add(new Common.Server.Engine.Impl.Parameter(idp.ParameterName, idp.Value));
                }
                Client.Collection <JSONDocument> coll = ((NosDbConnection)_connection)._database.GetCollection(((SelectObject)parsedQuery).Collection);

                long val = 0;
                ICollectionReader reader = null;
                if (parsedQuery is SelectObject)
                {
                    reader = coll.ExecuteReader(_commandText, _params);
                }
                else
                {
                    val = ((NosDbConnection)_connection)._database.ExecuteNonQuery(_commandText, _params);
                }
                //    reader = _connection._database.ExecuteQuery(query);

                NosDataReader readerr = new NosDataReader(reader);
                readerr.AttributesColumns = al;
                readerr._rowsAffected     = (int)val;
                return(readerr);
            }
            finally
            {
                if (behavior == CommandBehavior.CloseConnection)
                {
                    this._connection.Close();
                }
            }
        }