这里需要在底层添加一个方法,暂时整理的数据类型如下:
//根据字符串来判断数据列的类型
int Statement::GetColumnFromColumnName(const char* strDataType)
{
std::string strTemp(strDataType);
transform(strTemp.begin(), strTemp.end(), strTemp.begin(), ::toupper);
std::string strArray[] = { "INT","INTEGER", "TINYINT", "SMALLINT", "MEDIUMINT", "BIGINT", "UNSIGNED BIG INT", "INT2", "INT8" };
auto itrFind = find_if(strArray, strArray + _countof(strArray), [&](const std::string& _dataInfo)
{
return (_dataInfo.find(strTemp) != -1);
});
if (itrFind != strArray + _countof(strArray))
{
return 1;
}
std::string TextArray[] = { "CHARACTER(20)","VARCHAR(255)", "VARYING CHARACTER(255)", "NCHAR(55)", "NATIVE CHARACTER(70)", "NVARCHAR(100)", "TEXT", "CLOB" };
auto itrTextFind = find_if(TextArray, TextArray + _countof(TextArray), [&](const std::string& _dataInfo)
{
return (_dataInfo.find(strTemp) != -1);
});
if (itrTextFind != TextArray + _countof(TextArray))
{
return 3;
}
std::string strBlobArray[] = { "BLOB" };
auto itrBlobFind = find_if(strBlobArray, strBlobArray + _countof(strBlobArray), [&](const std::string& _dataInfo)
{
return (_dataInfo.find(strTemp) != -1);
});
if (itrBlobFind != strBlobArray + _countof(strBlobArray))
{
return 4;
}
std::string strRealArray[] = { "REAL","DOUBLE","DOUBLE PRECISION","FLOAT" };
auto itrRealFind = find_if(strRealArray, strRealArray + _countof(strRealArray), [&](const std::string& _dataInfo)
{
return (_dataInfo.find(strTemp) != -1);
});
if (itrRealFind != strRealArray + _countof(strRealArray))
{
return 2;
}
//NUMERIC
std::string strNumericArray[] = { "NUMERIC","DECIMAL(10,5)","BOOLEAN","DATE","DATETIME" };
auto itrNumericFind = find_if(strNumericArray, strNumericArray + _countof(strNumericArray), [&](const std::string& _dataInfo)
{
return (_dataInfo.find(strTemp) != -1);
});
if (itrNumericFind != strNumericArray + _countof(strNumericArray))
{
}
return 5;
}
//获取列类型
int Statement::getColumnDataType(const char* apName)
{
const int index = getColumnIndex(apName);
const char* strDataType = getColumnDeclaredType(index);
return GetColumnFromColumnName(strDataType);
}