c++ SqliteCPP 使用-根据列名获取数据类型(3)

网友投稿 600 2022-11-08

c++ SqliteCPP 使用-根据列名获取数据类型(3)

c++ SqliteCPP 使用-根据列名获取数据类型(3)

这里需要在底层添加一个方法,暂时整理的数据类型如下:

//根据字符串来判断数据列的类型 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); }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:MFC-菜单
下一篇:【奇妙之旅】你在地图上绘的圆,为什么不圆?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~