2013-07-15 65 views
2

我試圖運行下面的代碼:當進入情況SQL_CHAR並得到打破它跳SQLBindcol調用之前區分SQL_TYPE_DATE,怎麼可能,在C++開關故障如何?

SQLSMALLINT** column_types = new SQLSMALLINT*[*ColumnCount]; 


void** ColumnsData = new void*[*ColumnCount]; 

SQLINTEGER** rowLengths = new SQLINTEGER*[*ColumnCount]; 

int limit = *ColumnCount; 
for(int i=0;i<limit;i++) 
{ 
    column_types[i] = new SQLSMALLINT(); 
    SQLColAttribute(hStmt,i+1,SQL_DESC_TYPE,NULL,NULL,NULL,(SQLPOINTER)column_types[i]); 
    SQLSMALLINT type = *column_types[i]; 
    switch(type) 
    { 
    case SQL_CHAR: 

      ColumnsData[i] = new SQLCHAR**[*RowCount]; 
      for(int l=0;l<*RowCount;l++) 
      { 
       ((SQLCHAR**)ColumnsData[i])[l] = new SQLCHAR[512]; 
      } 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_CHAR,ColumnsData[i],512,rowLengths[i]); 
      break; //<<<<<<<<<<<<<<<<<<<<<<<<<<< 

    case SQL_VARCHAR: 

      ColumnsData[i] = new SQLCHAR**[*RowCount]; 
      for(int l=0;l<*RowCount;l++) 
      { 
       ((SQLCHAR**)ColumnsData[i])[l] = new SQLCHAR[512]; 
      } 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_VARCHAR,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_LONGVARCHAR: 

      ColumnsData[i] = new SQLCHAR**[*RowCount]; 
      for(int l=0;l<*RowCount;l++) 
      { 
       ((SQLCHAR**)ColumnsData[i])[l] = new SQLCHAR[512]; 
      } 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_LONGVARCHAR,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_WCHAR: 

      ColumnsData[i] = new SQLWCHAR**[*RowCount]; 
      for(int l=0;l<*RowCount;l++) 
      { 
       ((SQLWCHAR**)ColumnsData[i])[l] = new SQLWCHAR[512]; 
      } 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_WCHAR,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_WVARCHAR: 

      ColumnsData[i] = new SQLWCHAR**[*RowCount]; 
      for(int l=0;l<*RowCount;l++) 
      { 
       ((SQLWCHAR**)ColumnsData[i])[l] = new SQLWCHAR[512]; 
      } 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_WVARCHAR,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_WLONGVARCHAR: 

      ColumnsData[i] = new SQLWCHAR**[*RowCount]; 
      for(int l=0;l<*RowCount;l++) 
      { 
       ((SQLWCHAR**)ColumnsData[i])[l] = new SQLWCHAR[512]; 
      } 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_WLONGVARCHAR,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_DECIMAL: 

      ColumnsData[i] = new SQL_NUMERIC_STRUCT[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_DECIMAL,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_NUMERIC: 

      ColumnsData[i] = new SQL_NUMERIC_STRUCT[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_NUMERIC,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_SMALLINT: 

      ColumnsData[i] = new SQLSMALLINT[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_SMALLINT,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_INTEGER: 

      ColumnsData[i] = new SQLINTEGER[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_INTEGER,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_REAL: 

      ColumnsData[i] = new SQLREAL[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_REAL,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_FLOAT: 

      ColumnsData[i] = new SQLREAL[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_FLOAT,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_DOUBLE: 

      ColumnsData[i] = new SQLDOUBLE[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_DOUBLE,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_BIT: 

      ColumnsData[i] = new SQLCHAR[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_BIT,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_TINYINT: 

      ColumnsData[i] = new SQLSCHAR[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_TINYINT,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_BIGINT: 

      ColumnsData[i] = new SQLBIGINT[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_BIGINT,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_BINARY: 

      ColumnsData[i] = new SQLCHAR**[*RowCount]; 
      for(int l=0;l<*RowCount;l++) 
      { 
       ((SQLCHAR**)ColumnsData[i])[l] = new SQLCHAR[512]; 
      } 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_BINARY,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_TYPE_DATE: 

      ColumnsData[i] = new SQL_DATE_STRUCT[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

//>>>>>>>>>>>>>>> 
      SQLBindCol(hStmt,i+1,SQL_TYPE_DATE,ColumnsData[i],512,rowLengths[i]); 
      break; 

    case SQL_TYPE_TIME: 

      ColumnsData[i] = new SQL_TIME_STRUCT[*RowCount]; 

      rowLengths[i] = new SQLINTEGER[*RowCount]; 

      SQLBindCol(hStmt,i+1,SQL_TYPE_TIME,ColumnsData[i],512,rowLengths[i]); 
      break; 

    default: 

      break; 

    } 
} 

是故障還是我我在這裏做錯了,因爲中斷應該退出交換機

+1

在實際代碼中檢查一個額外的'}'。 – Barmar

回答

2

我建議評論除SQL_CHAR以外的所有其他開關情況並查看會發生什麼情況。如果調試器步入註釋掉的代碼,則必須進行優化。如果這種情況發生,請將其他案例逐個添加回來,並查看問題何時重新出現。這將縮小問題的原因。

+1

調試器步入註釋代碼,但我已在c/C++優化禁用(/ Od)可能你可以解釋一下,在Visual Studio中,哪裏可以設置優化? –

+3

有時候關閉視覺工作室,喝茶/尖叫,深呼吸,然後做一次重建。 – doctorlove

+0

「優化一」是一個錯字我的意思 – doctorlove

3

我打算假設你在某種調試器中看到了這種行爲,並且我將假設你已經構建了一個優化版本。在這種情況下,你所看到的只是優化器重用代碼 - 優化器通常會使調試有點困難,所以只需構建一個未優化的版本。

如果你真的沒有啓用內置的優化,我會嘗試的第一件事是做了全面清理/重建(仍然沒有優化),以確保你有一個一致的基礎測試,從工作。

+0

不錯的答案! :) –

+0

謝謝大家的答案,我正在使用visual studio調試器,我正在做一個未優化的調試版本,我也嘗試了一個完整的清理/重建,仍然沒有運氣。 –

+0

嘗試@doctorlove建議的內容,然後 –

3

我想你是這麼說的,因爲通過調試器檢查代碼。嘗試在編譯期間禁用優化。