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

261 篇文章 10 订阅

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


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值