protected override DbCommand GetCommand(QueryCommand query, object[] paramValues)
 {
     SQLiteCommand cmd;
     if (!this.provider.commandCache.TryGetValue(query, out cmd))
     {
         cmd = (SQLiteCommand)this.provider.Connection.CreateCommand();
         cmd.CommandText = query.CommandText;
         this.SetParameterValues(query, cmd, paramValues);
         cmd.Prepare();
         this.provider.commandCache.Add(query, cmd);
         if (this.provider.Transaction != null)
         {
             cmd = (SQLiteCommand)cmd.Clone();
             cmd.Transaction = (SQLiteTransaction)this.provider.Transaction;
         }
     }
     else
     {
         cmd = (SQLiteCommand)cmd.Clone();
         cmd.Transaction = (SQLiteTransaction)this.provider.Transaction;
         this.SetParameterValues(query, cmd, paramValues);
     }
     return cmd;
 }
            private IEnumerable<int> ExecuteBatch(QueryCommand query, IEnumerable<object[]> paramSets, int batchSize)
            {
                SqlCommand cmd = (SqlCommand)this.GetCommand(query, null);
                DataTable dataTable = new DataTable();
                for (int i = 0, n = query.Parameters.Count; i < n; i++)
                {
                    var qp = query.Parameters[i];
                    cmd.Parameters[i].SourceColumn = qp.Name;
                    dataTable.Columns.Add(qp.Name, TypeHelper.GetNonNullableType(qp.Type));
                }
                SqlDataAdapter dataAdapter = new SqlDataAdapter();
                dataAdapter.InsertCommand = cmd;
                dataAdapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
                dataAdapter.UpdateBatchSize = batchSize;

                this.LogMessage("-- Start SQL Batching --");
                this.LogMessage("");
                this.LogCommand(query, null);

                IEnumerator<object[]> en = paramSets.GetEnumerator();
                using (en)
                {
                    bool hasNext = true;
                    while (hasNext)
                    {
                        int count = 0;
                        for (; count < dataAdapter.UpdateBatchSize && (hasNext = en.MoveNext()); count++)
                        {
                            var paramValues = en.Current;
                            dataTable.Rows.Add(paramValues);
                            this.LogParameters(query, paramValues);
                            this.LogMessage(string.Empty);
                        }
                        if (count > 0)
                        {
                            int n = dataAdapter.Update(dataTable);
                            for (int i = 0; i < count; i++)
                            {
                                yield return (i < n) ? 1 : 0;
                            }
                            dataTable.Rows.Clear();
                        }
                    }
                }

                this.LogMessage(string.Format("-- End SQL Batching --"));
                this.LogMessage(string.Empty);
            }
 /// <summary>
 /// 执行对 <typeparamref name="T"/> 类型的批量操作。
 /// </summary>
 /// <param name="query">查询.</param>
 /// <param name="paramSets">查询参数集</param>
 /// <param name="batchSize">批量语句大小.</param>
 /// <param name="stream">是否使用流,if set to <c>true</c> [stream].</param>
 /// <returns></returns>
 public override IEnumerable<int> ExecuteBatch(QueryCommand query, IEnumerable<object[]> paramSets, int batchSize, bool stream)
 {
     this.StartUsingConnection();
     try
     {
         var result = this.ExecuteBatch(query, paramSets, batchSize);
         if (!stream || this.ActionOpenedConnection)
         {
             return result.ToList();
         }
         else
         {
             return new EnumerateOnce<int>(result);
         }
     }
     finally
     {
         this.StopUsingConnection();
     }
 }