language-extensions/python/src/PythonDataSet.cpp
//-------------------------------------------------------------------------------------------------
// Name: PythonOutputDataSet::PopulateColumnDataType
//
// Description:
//  Gets the python type from the value in the column,
//  then get the column data type by looking up the python to odbc type map.
//

:PopulateColumnDataType
Description:
Gets the python type from the value in the column,
then get the column data type by looking up the python to odbc type map.
: PopulateColumnDataType Description : Gets the python type from the value in the column then get the column data type by looking up the python to odbc type map .
SQLSMALLINT PythonOutputDataSet::PopulateColumnDataType(SQLUSMALLINT columnNumber) const
{
	LOG("PythonOutputDataSet::PopulateColumnDataType");
	string getDTypeString = m_name + ".dtypes.iloc[" + to_string(columnNumber) + "]";
	np::dtype dType = bp::extract<np::dtype>(
		bp::eval(getDTypeString.c_str(), m_mainNamespace));
	string type = "NoneType";
	if(!np::equivalent(dType, np::dtype(bp::object("O"))))
	{
		type = bp::extract<string>(bp::str(dType));
		if (regex_match(type, regex("(.S|bytes)[0-9]*")))
		{
			type = "bytes";
		}
	}
	SQLSMALLINT dataType;
	if (m_isStreaming)
	{
		PythonDataSet::pythonToOdbcStreamingTypeMap::const_iterator it =
			PythonDataSet::sm_pythonToOdbcStreamingTypeMap.find(type);
		if (it == PythonDataSet::sm_pythonToOdbcStreamingTypeMap.end())
		{
			throw invalid_argument("Unsupported data type " + type + " in output data for column # "
				+ to_string(columnNumber) + ".");
		}
		dataType = it->second;
	}
	else
	{
		PythonDataSet::pythonToOdbcTypeMap::const_iterator it =
			PythonDataSet::sm_pythonToOdbcTypeMap.find(type);
		if (it == PythonDataSet::sm_pythonToOdbcTypeMap.end())
		{
			throw invalid_argument("Unsupported data type " + type + " in output data for column # "
				+ to_string(columnNumber) + ".");
		}
		dataType = it->second;
	}
	return dataType;
}
SQLSMALLINT PythonOutputDataSet :: PopulateColumnDataType ( SQLUSMALLINT columnNumber ) const { LOG ( " " ) ; string getDTypeString = m_name + " " + to_string ( columnNumber ) + " " ; np :: dtype dType = bp :: extract < np :: dtype > ( bp :: eval ( getDTypeString . c_str ( ) , m_mainNamespace ) ) ; string type = " " ; if ( ! np :: equivalent ( dType , np :: dtype ( bp :: object ( " " ) ) ) ) { type = bp :: extract < string > ( bp :: str ( dType ) ) ; if ( regex_match ( type , regex ( " " ) ) ) { type = " " ; } } SQLSMALLINT dataType ; if ( m_isStreaming ) { PythonDataSet :: pythonToOdbcStreamingTypeMap :: const_iterator it = PythonDataSet :: sm_pythonToOdbcStreamingTypeMap . find ( type ) ; if ( it == PythonDataSet :: sm_pythonToOdbcStreamingTypeMap . end ( ) ) { throw invalid_argument ( " " + type + " " + to_string ( columnNumber ) + " " ) ; } dataType = it -> second ; } else { PythonDataSet :: pythonToOdbcTypeMap :: const_iterator it = PythonDataSet :: sm_pythonToOdbcTypeMap . find ( type ) ; if ( it == PythonDataSet :: sm_pythonToOdbcTypeMap . end ( ) ) { throw invalid_argument ( " " + type + " " + to_string ( columnNumber ) + " " ) ; } dataType = it -> second ; } return dataType ; }
Name: PythonOutputDataSet::PopulateColumnDataType
Description:
Gets the python type from the value in the column,
then get the column data type by looking up the python to odbc type map.
Name : PythonOutputDataSet :: PopulateColumnDataType Description : Gets the python type from the value in the column then get the column data type by looking up the python to odbc type map .
// For byte type objects, the dtype is formatted "bytes##" or "|S##"
 // where ## is length of string in bytes) we need to standardize the type to "bytes".
 //
