Esempio n. 1
0
        /// <summary>
        /// Creates a <see cref="RemoveStatement"/> with the given identifier that can be used to remove a single
        /// document from a collection.
        /// </summary>
        /// <param name="id">The identifier to match the document.</param>
        /// <returns>A <see cref="RemoveStatement"/> object set with the given identifier.</returns>
        /// <remarks>The statement can then be further modified before execution.</remarks>
        public RemoveStatement Remove(object id)
        {
            string key = id is string?
                         "\"" + id.ToString() + "\"" : id.ToString();
            string          condition = String.Format("_id = {0}", key);
            RemoveStatement stmt      = new RemoveStatement(this, condition);

            return(stmt);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a <see cref="RemoveStatement"/> with the given condition that can be used to remove
        /// one or more documents from a collection.The statement can then be further modified before execution.
        /// </summary>
        /// <param name="condition">The condition to match documents.</param>
        /// <returns>A <see cref="RemoveStatement"/> object set with the given condition.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="condition"/> is <c>null</c> or white space.</exception>
        /// <remarks>The statement can then be further modified before execution.</remarks>
        public RemoveStatement Remove(string condition)
        {
            if (string.IsNullOrWhiteSpace(condition))
            {
                throw new ArgumentNullException(nameof(condition), Resources.ParameterNullOrEmpty);
            }

            RemoveStatement stmt = new RemoveStatement(this, condition);

            return(stmt);
        }
Esempio n. 3
0
 /// <summary>
 ///     Visits a REMOVE statement
 /// </summary>
 /// <param name="removeStatement"></param>
 protected virtual void VisitRemoveStatement(RemoveStatement removeStatement)
 {
     if (removeStatement.ListExpression != null)
     {
         VisitExpression(removeStatement.ListExpression);
     }
     if (removeStatement.Condition != null)
     {
         VisitExpression(removeStatement.Condition);
     }
 }
 protected Result ExecuteRemoveStatement(RemoveStatement stmt)
 {
     return(stmt.Execute());
 }
Esempio n. 5
0
        public int PrepareStatement <TResult>(BaseStatement <TResult> statement)
            where TResult : BaseResult
        {
            int stmtId = Interlocked.Increment(ref _stmtId);

            switch (statement.GetType().Name)
            {
            case nameof(FindStatement):
                FindStatement fs = statement as FindStatement;
                Debug.Assert(fs != null);
                protocol.SendPrepareStatement(
                    (uint)stmtId,
                    DataAccess.PreparedStatementType.Find,
                    fs.Target.Schema.Name,
                    fs.Target.Name,
                    false,
                    fs.FilterData,
                    fs.findParams);
                break;

            case nameof(TableSelectStatement):
                TableSelectStatement ss = statement as TableSelectStatement;
                Debug.Assert(ss != null);
                protocol.SendPrepareStatement(
                    (uint)stmtId,
                    DataAccess.PreparedStatementType.Find,
                    ss.Target.Schema.Name,
                    ss.Target.Name,
                    true,
                    ss.FilterData,
                    ss.findParams);
                break;

            case nameof(ModifyStatement):
                ModifyStatement ms = statement as ModifyStatement;
                Debug.Assert(ms != null);
                protocol.SendPrepareStatement(
                    (uint)stmtId,
                    DataAccess.PreparedStatementType.Update,
                    ms.Target.Schema.Name,
                    ms.Target.Name,
                    false,
                    ms.FilterData,
                    null,
                    ms.Updates);
                break;

            case nameof(TableUpdateStatement):
                TableUpdateStatement us = statement as TableUpdateStatement;
                Debug.Assert(us != null);
                protocol.SendPrepareStatement(
                    (uint)stmtId,
                    DataAccess.PreparedStatementType.Update,
                    us.Target.Schema.Name,
                    us.Target.Name,
                    true,
                    us.FilterData,
                    null,
                    us.updates);
                break;

            case nameof(RemoveStatement):
                RemoveStatement rs = statement as RemoveStatement;
                Debug.Assert(rs != null);
                protocol.SendPrepareStatement(
                    (uint)stmtId,
                    DataAccess.PreparedStatementType.Delete,
                    rs.Target.Schema.Name,
                    rs.Target.Name,
                    false,
                    rs.FilterData,
                    null);
                break;

            case nameof(TableDeleteStatement):
                TableDeleteStatement ds = statement as TableDeleteStatement;
                Debug.Assert(ds != null);
                protocol.SendPrepareStatement(
                    (uint)stmtId,
                    DataAccess.PreparedStatementType.Delete,
                    ds.Target.Schema.Name,
                    ds.Target.Name,
                    true,
                    ds.FilterData,
                    null);
                break;

            case nameof(TableInsertStatement):
                TableInsertStatement insert = statement as TableInsertStatement;
                Debug.Assert(insert != null);
                protocol.SendPrepareStatement(
                    (uint)stmtId,
                    DataAccess.PreparedStatementType.Insert,
                    insert.Target.Schema.Name,
                    insert.Target.Name,
                    true,
                    null,
                    null,
                    null,
                    insert.values.ToArray(),
                    insert.fields,
                    false);
                break;

            case nameof(SqlStatement):
                SqlStatement sqlStatement = statement as SqlStatement;
                Debug.Assert(sqlStatement != null);
                protocol.SendPrepareStatement(
                    (uint)stmtId,
                    DataAccess.PreparedStatementType.SqlStatement,
                    null,
                    null,
                    true,
                    null,
                    null,
                    null,
                    sqlStatement.parameters.ToArray(),
                    null,
                    false,
                    sqlStatement.SQL);
                break;

            default:
                throw new NotSupportedException(statement.GetType().Name);
            }
            _preparedStatements.Add(stmtId);
            return(stmtId);
        }
Esempio n. 6
0
 public Result DeleteDocs(RemoveStatement rs)
 {
     protocol.SendDelete(rs.Target.Schema.Name, rs.Target.Name, false, rs.FilterData);
     return(new Result(this));
 }