@@ -614,6 +614,14 @@ struct sql_ctype
614
614
{
615
615
};
616
616
617
+ template <typename T>
618
+ struct sql_ctype <
619
+ T,
620
+ typename std::enable_if<is_integral8<T>::value && std::is_signed<T>::value>::type>
621
+ {
622
+ static const SQLSMALLINT value = SQL_C_STINYINT;
623
+ };
624
+
617
625
template <>
618
626
struct sql_ctype <uint8_t >
619
627
{
@@ -3814,9 +3822,21 @@ class result::result_impl
3814
3822
switch (col.sqltype_ )
3815
3823
{
3816
3824
case SQL_BIT:
3825
+ col.ctype_ = SQL_C_BIT;
3826
+ col.clen_ = sizeof (int8_t );
3827
+ break ;
3817
3828
case SQL_TINYINT:
3829
+ col.ctype_ = SQL_C_STINYINT;
3830
+ col.clen_ = sizeof (int8_t );
3831
+ break ;
3818
3832
case SQL_SMALLINT:
3819
- case SQL_INTEGER:
3833
+ col.ctype_ = SQL_C_SSHORT;
3834
+ col.clen_ = sizeof (int16_t );
3835
+ break ;
3836
+ case SQL_INTEGER: // TODO: Can be 32 or 64 bit? Then sizeof(SQLINTEGER)
3837
+ col.ctype_ = SQL_C_SLONG;
3838
+ col.clen_ = sizeof (int32_t );
3839
+ break ;
3820
3840
case SQL_BIGINT:
3821
3841
col.ctype_ = SQL_C_SBIGINT;
3822
3842
col.clen_ = sizeof (int64_t );
@@ -4159,6 +4179,7 @@ inline void result::result_impl::get_ref_impl(short column, T& result) const
4159
4179
}
4160
4180
4161
4181
case SQL_C_LONG:
4182
+ case SQL_C_SLONG:
4162
4183
{
4163
4184
std::string buffer (column_size + 1 , 0 ); // ensure terminating null
4164
4185
const int32_t data = *ensure_pdata<int32_t >(column);
@@ -4402,7 +4423,7 @@ inline void result::result_impl::get_ref_impl<_variant_t>(short column, _variant
4402
4423
}
4403
4424
case SQL_C_BIT:
4404
4425
{
4405
- auto const v = *(ensure_pdata<short >(column));
4426
+ auto const v = *(ensure_pdata<int8_t >(column));
4406
4427
result = _variant_t (!!v ? VARIANT_TRUE : VARIANT_FALSE, VT_BOOL);
4407
4428
break ;
4408
4429
}
@@ -4422,22 +4443,28 @@ inline void result::result_impl::get_ref_impl<_variant_t>(short column, _variant
4422
4443
}
4423
4444
case SQL_C_TINYINT:
4424
4445
case SQL_C_STINYINT:
4425
- result = (char )*(ensure_pdata<short >(column));
4446
+ result = (char )*(ensure_pdata<int16_t >(column));
4426
4447
break ;
4427
4448
case SQL_C_UTINYINT:
4428
- result = (unsigned char )*(ensure_pdata<unsigned short >(column));
4449
+ result = (unsigned char )*(ensure_pdata<uint16_t >(column));
4429
4450
break ;
4430
4451
case SQL_C_SHORT:
4431
4452
case SQL_C_SSHORT:
4432
- result = *(ensure_pdata<short >(column));
4453
+ {
4454
+ auto d = *(ensure_pdata<int16_t >(column));
4455
+ result = _variant_t (d, VT_I2);
4433
4456
break ;
4457
+ }
4434
4458
case SQL_C_USHORT:
4435
- result = *(ensure_pdata<unsigned short >(column));
4459
+ result = *(ensure_pdata<uint16_t >(column));
4436
4460
break ;
4437
4461
case SQL_C_LONG:
4438
4462
case SQL_C_SLONG:
4439
- result = *(ensure_pdata<int32_t >(column));
4463
+ {
4464
+ long d = *(ensure_pdata<int32_t >(column));
4465
+ result = _variant_t (d, VT_I4); // avoid VT_INT
4440
4466
break ;
4467
+ }
4441
4468
case SQL_C_ULONG:
4442
4469
result = *(ensure_pdata<uint32_t >(column));
4443
4470
break ;
@@ -4666,15 +4693,24 @@ void result::result_impl::get_ref_impl(short column, T& result) const
4666
4693
using namespace std ; // if int64_t is in std namespace (in c++11)
4667
4694
switch (col.ctype_ )
4668
4695
{
4696
+ case SQL_C_BIT:
4697
+ result = (T) * (ensure_pdata<int8_t >(column));
4698
+ return ;
4669
4699
case SQL_C_CHAR:
4670
4700
case SQL_C_WCHAR:
4671
4701
get_ref_from_string_column (column, result);
4672
4702
return ;
4703
+ case SQL_C_TINYINT:
4704
+ case SQL_C_STINYINT:
4705
+ result = (T) * (ensure_pdata<int8_t >(column));
4706
+ return ;
4707
+ case SQL_C_SHORT:
4673
4708
case SQL_C_SSHORT:
4674
- result = (T) * (ensure_pdata<short >(column));
4709
+ result = (T) * (ensure_pdata<int16_t >(column));
4675
4710
return ;
4711
+ case SQL_C_UTINYINT:
4676
4712
case SQL_C_USHORT:
4677
- result = (T) * (ensure_pdata<unsigned short >(column));
4713
+ result = (T) * (ensure_pdata<uint16_t >(column));
4678
4714
return ;
4679
4715
case SQL_C_LONG:
4680
4716
case SQL_C_SLONG:
0 commit comments