コード例 #1
0
ファイル: SqlEnumerator.cs プロジェクト: timyaukey/WillowLib
 /// <summary>
 /// Create an object with a SqlDataReader created from the SqlCommand
 /// passed. The SqlConnection object from that SqlCommand will be returned
 /// to the specified ConnectionPool when Dispose() is called on the enumerator.
 /// </summary>
 /// <param name="cmd"></param>
 /// <param name="connectionPool"></param>
 protected SqlEnumerator(SqlCommand cmd, PooledConnection pooledCon)
 {
     mConnection = cmd.Connection;
     mReader     = cmd.ExecuteReader();
     mPooledCon  = pooledCon;
     mCurrent    = null;
     mDisposed   = false;
 }
コード例 #2
0
        public static SqlCommand CreateProc(string procName, PooledConnection pooledCon)
        {
            SqlCommand cmd = new SqlCommand(procName, pooledCon.Con);

            cmd.CommandType    = CommandType.StoredProcedure;
            cmd.CommandTimeout = 60 * 60;
            return(cmd);
        }
コード例 #3
0
        public static SqlDataAdapter CreateSelectAdapter(string procName, PooledConnection pooledCon)
        {
            SqlCommand     cmd     = SqlHelper.CreateProc(procName, pooledCon);
            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.SelectCommand = cmd;
            return(adapter);
        }
コード例 #4
0
 public void ExecuteNonQuery(string procName, AddSqlParametersDelegate addParams)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlCommand cmd = SqlHelper.CreateProc(procName, pooledCon))
         {
             addParams(cmd);
             cmd.ExecuteNonQuery();
         }
     }
 }
コード例 #5
0
 public virtual void Delete(TPersistable entity)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlCommand cmd = SqlHelper.CreateProc("dbo.Delete" + EntityName, pooledCon))
         {
             SqlHelper.AddParamInputId(cmd, EntityIdVarName, entity.GetIdValue());
             cmd.ExecuteNonQuery();
         }
     }
 }
コード例 #6
0
 public virtual void Insert(TPersistable entity)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlCommand cmd = SqlHelper.CreateProc("dbo.Insert" + EntityName, pooledCon))
         {
             SqlParameter param = SqlHelper.AddParamOutputId(cmd, EntityIdVarName);
             AddInsertUpdateParams(cmd, entity);
             cmd.ExecuteNonQuery();
             entity.SetIdValue((int)param.Value);
         }
     }
 }
コード例 #7
0
 public List <TPersistable> Search(string procName, AddSqlParametersDelegate addParams)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlDataAdapter adapter = SqlHelper.CreateSelectAdapter(procName, pooledCon))
         {
             using (adapter.SelectCommand)
             {
                 addParams(adapter.SelectCommand);
                 return(CreateEntities(adapter));
             }
         }
     }
 }
コード例 #8
0
 public virtual TPersistable Get(TId id)
 {
     using (PooledConnection pooledCon = GetPooledConnection())
     {
         using (SqlDataAdapter adapter = SqlHelper.CreateSelectAdapter(
                    "dbo.Get" + EntityName, pooledCon))
         {
             using (adapter.SelectCommand)
             {
                 SqlHelper.AddParamInputId(adapter.SelectCommand, EntityIdVarName, id.Value);
                 return(CreateEntities(adapter)[0]);
             }
         }
     }
 }