程序里的CString里面保存了很长的一段SQL语句,通过watch看只能看一小部分,我想把这段sql语句输出到debug窗口仔细看看,还能复制到plsql里排版看,但是好像不能直接通过TRACE把CString的内容输出到窗口,是不是要把CSring转成string才能输出啊??

解决方案 »

  1.   

    CString str(_T("aaaa "));
    TRACE(_T("%s"),str);
      

  2.   

    CString strSql = _T("");
    if(CSqlLink::GetDBType()==_sybase)
    strSql.Format(_T("select A.OutNo,A.countdb,B.TarrifTypeID,B.OutNoSumKWH,B.OutNoSumKVARH,B.countsum from \
    (select OutNo,count(SubObjID) as countdb from POB_CalcItemDts where  ItemID=%d  and SubObjType=15  and BeginTime<='%s' and (EndTime is null or EndTime>='%s') group by OutNo ) A \
    left join ( select b.TarrifTypeID,a.OutNo,\
    sum(case (a.SubObjNo) when 1 then (case (a.Symbol ) when 1 then a.Factor * b.KWHRec when 2 then -1*a.Factor * b.KWHRec  else 0 end ) when 2 then (case (a.Symbol ) when 1 then a.Factor * b.KWHDel when 2 then -1*a.Factor * b.KWHDel else 0 end ) else 0   end )  as OutNoSumKWH,\
    sum(case (a.SubObjNo) when 1 then (case (a.Symbol ) when 1 then a.Factor * b.KVARHRec when 2 then -1*a.Factor * b.KVARHRec else 0 end ) when 2 then (case (a.Symbol ) when 1 then a.Factor * b.KVARHDel  when 2 then -1*a.Factor * b.KVARHDel  else 0 end ) else 0 end ) as OutNoSumKVARH,count(b.PointID) as countsum from POB_CalcItemDts a,\
    (select PointID,TarrifTypeID, KWHRec,KWHDel,KVARHRec,KVARHDel from %s where StartTime='%s' and SchemeID=%d and TarrifTypeID=0) b where a.SubObjID=b.PointID and a.SubObjType=15 and a.ItemID=%d and a.BeginTime<='%s' and (a.EndTime is null or a.EndTime>='%s' ) group by b.TarrifTypeID,a.OutNo ) B on A.OutNo=B.OutNo")
    ,dwItemID,tEnd.Format("%Y-%m-%d %H:%M:%S"),tBegin.Format("%Y-%m-%d %H:%M:%S"),strTableName,
    DataTime.Format("%Y-%m-%d %H:%M:%S"),wSchemeID,dwItemID,tEnd.Format("%Y-%m-%d %H:%M:%S"),tBegin.Format("%Y-%m-%d %H:%M:%S")); else
    strSql.Format(_T("select A.OutNo,A.countdb,B.TarrifTypeID,B.OutNoSumKWH,B.OutNoSumKVARH,B.countsum from \
    (select OutNo,count(SubObjID) as countdb from POB_CalcItemDts where  ItemID=%d  and SubObjType=15  and BeginTime<='%s' and (EndTime is null or EndTime>='%s') group by OutNo ) A \
    left join ( select b.TarrifTypeID,a.OutNo,\
    sum(case (a.SubObjNo) when 1 then (case (a.Symbol ) when 1 then a.Factor * nvl(b.KWHRec,0) when 2 then -1*a.Factor * nvl(b.KWHRec,0)  else 0 end ) when 2 then (case (a.Symbol ) when 1 then a.Factor * nvl(b.KWHDel,0) when 2 then -1*a.Factor * nvl(b.KWHDel,0) else 0 end ) else 0   end )  as OutNoSumKWH,\
    sum(case (a.SubObjNo) when 1 then (case (a.Symbol ) when 1 then a.Factor * b.KVARHRec when 2 then -1*a.Factor * nvl(b.KVARHRec,0) else 0 end ) when 2 then (case (a.Symbol ) when 1 then a.Factor * nvl(b.KVARHRec,0)  when 2 then -1*a.Factor * nvl(b.KVARHDel,0)  else 0 end ) else 0 end ) as OutNoSumKVARH,\
    count(b.PointID) as countsum from POB_CalcItemDts a,(select PointID,TarrifTypeID, KWHRec,KWHDel,KVARHRec,KVARHDel from %s where StartTime='%s' and SchemeID=%d and TarrifTypeID=0) b where a.SubObjID=b.PointID and a.SubObjType=15 and a.ItemID=%d and a.BeginTime<='%s' and (a.EndTime is null or a.EndTime>='%s' ) group by b.TarrifTypeID,a.OutNo ) B on A.OutNo=B.OutNo")
    ,dwItemID,tEnd.Format("%Y-%m-%d %H:%M:%S"),tBegin.Format("%Y-%m-%d %H:%M:%S"),strTableName,
    DataTime.Format("%Y-%m-%d %H:%M:%S"),wSchemeID,dwItemID,tEnd.Format("%Y-%m-%d %H:%M:%S"),tBegin.Format("%Y-%m-%d %H:%M:%S")); // static CLogFile file("sql.log");
     // file.WriteLog(strSql);// AfxMessageBox(strSql);
    TRACE(_T("%s"),strsql);
      

  3.   

    用 TRACE1  看看呢?
      

  4.   


    #if defined(_DEBUG)|| !defined(NDEBUG)  
    #define TRACELONGSTR(strSql) TraceLongStr(strSql)void TraceLongStr(const CString strSql)
    {
    CString str;
    int len =strSql.getlength();
    for(i=0;i<len;i+=256)
    {
         str=strSql.Mid(i,min(i+256,len));
         TRACE("%s",str);
    }
    }
    #else
    #define TRACELONGSTR(strSql)
    #endif//这样使用
    RACELONGSTR(StrSql);
      

  5.   

    afxDump<<str; 可以像cout直接输出到调试窗口
      

  6.   

    #ifdef _DEBUG
    afxDump<<XXXX;
    #endif