Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete support for C++ integer types #954

Merged
merged 38 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7644240
Update core code for complete integer type support
zann1x Apr 5, 2022
53f6aba
Update MySQL backend for complete integer type support
zann1x Apr 5, 2022
f27f144
Update SQLite3 backend for complete integer type support
zann1x Apr 5, 2022
dd45b6d
Update PostgreSQL backend for complete integer type support
zann1x Apr 5, 2022
8fc34db
Update Oracle backend for complete integer type support
zann1x Apr 5, 2022
9d0d7c4
Update DB2 backend for complete integer type support
zann1x Apr 5, 2022
e0d0038
Update Firebird backend for complete integer type support
zann1x Apr 5, 2022
6aa6aa7
Update ODBC backend for complete integer type support
zann1x Apr 5, 2022
ca28449
Update soci-simple for complete integer type support
zann1x Apr 5, 2022
9e39f97
Update shared unit tests for complete integer type support
zann1x Apr 5, 2022
8544cab
Update unit tests of MySQL backend for complete integer type support
zann1x Apr 5, 2022
44a4365
Update unit tests of SQLite3 backend for complete integer type support
zann1x Apr 7, 2022
236966f
Update unit tests of PostgreSQL backend for complete integer type
zann1x Apr 5, 2022
0a8f450
Update unit tests of Oracle backend for complete integer type support
zann1x Apr 5, 2022
455a580
Update unit tests of DB2 backend for complete integer type support
zann1x May 8, 2022
b56224e
Update unit test of Firebird backend for complete integer type support
zann1x Apr 5, 2022
43ab82f
Update unit tests of ODBC backend for complete integer type support
zann1x May 8, 2022
71d9b87
Add *_int and *_long_long methods back to the soci-simple API
zann1x Jun 18, 2022
d4414a3
Update docs for complete integer type support
zann1x Jun 18, 2022
8dba000
Correct ODBC error message for unsigned types
zann1x Oct 5, 2022
3d16170
Replace stdint.h with cstdint
zann1x Sep 28, 2022
ff90687
Add back removed dt_* and x_* types
zann1x Oct 5, 2022
367c0c0
Revert unnecessary changes in unit tests
zann1x Oct 5, 2022
4e80322
Fix header include order
zann1x Nov 29, 2022
d95c716
Remove abbreviation in user-facing ODBC error message
zann1x Nov 29, 2022
a824ac8
Fix incorrect extraction of Postgres bool type
zann1x Nov 29, 2022
ede341c
Remove unnecessary type casts
zann1x Dec 31, 2022
60da2f0
Merge separate integer unit tests into one
zann1x Dec 31, 2022
4c36213
Remove unsigned type support checks in unit tests
zann1x Dec 31, 2022
88e2cb4
Fix uint64 vector unit tests
zann1x Jan 3, 2023
ea4ce9d
Simplify platform-specific data type defines
zann1x Dec 30, 2022
e8e4fc9
Fix MSSQL ODBC unit tests
zann1x Jan 4, 2023
4de379f
Fix Postgres unit test
zann1x Jan 8, 2023
1c3e069
Fix MySQL ODBC unit tests
zann1x Jan 15, 2023
ff7e29c
Handle potential overflow in mysql into-conversion
zann1x Aug 13, 2023
826fa77
Expose new db_type for dynamic type mapping
zann1x Aug 11, 2023
037a332
Add db_type description to docs
zann1x Oct 18, 2023
06b68c2
Forward create_column_type() to db_type overload
zann1x Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions include/soci/sqlite3/soci-sqlite3.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#endif

#include <cstdarg>
#include <stdint.h>
#include <vector>
#include <soci/soci-backend.h>

Expand Down Expand Up @@ -174,8 +175,14 @@ struct sqlite3_column
union
{
sqlite3_column_buffer buffer_;
int int32_;
int8_t int8_;
uint8_t uint8_;
int16_t int16_;
uint16_t uint16_;
int32_t int32_;
uint32_t uint32_;
sqlite_api::sqlite3_int64 int64_;
sqlite_api::sqlite3_uint64 uint64_;
double double_;
};
};
Expand Down Expand Up @@ -318,9 +325,14 @@ struct sqlite3_session_backend : details::session_backend
case dt_double:
return "real";
case dt_date:
case dt_integer:
case dt_long_long:
case dt_unsigned_long_long:
case dt_int8:
case dt_uint8:
case dt_int16:
case dt_uint16:
case dt_int32:
case dt_uint32:
case dt_int64:
case dt_uint64:
return "integer";
vadz marked this conversation as resolved.
Show resolved Hide resolved
case dt_blob:
return "blob";
Expand Down
52 changes: 40 additions & 12 deletions src/backends/sqlite3/standard-into-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,58 @@ void sqlite3_standard_into_type_backend::post_fetch(bool gotData,
break;
}

case x_short:
exchange_type_cast<x_short>(data_)
= static_cast<exchange_type_traits<x_short>::value_type >(
case x_int8:
exchange_type_cast<x_int8>(data_)
= static_cast<exchange_type_traits<x_int8>::value_type >(
sqlite3_column_int(statement_.stmt_, pos)
);
break;

case x_integer:
exchange_type_cast<x_integer>(data_)
= static_cast<exchange_type_traits<x_integer>::value_type >(
case x_uint8:
exchange_type_cast<x_uint8>(data_)
= static_cast<exchange_type_traits<x_uint8>::value_type >(
sqlite3_column_int(statement_.stmt_, pos)
);
break;

case x_int16:
exchange_type_cast<x_int16>(data_)
= static_cast<exchange_type_traits<x_int16>::value_type >(
sqlite3_column_int(statement_.stmt_, pos)
);
break;

case x_uint16:
exchange_type_cast<x_uint16>(data_)
= static_cast<exchange_type_traits<x_uint16>::value_type >(
sqlite3_column_int(statement_.stmt_, pos)
);
break;

case x_int32:
exchange_type_cast<x_int32>(data_)
= static_cast<exchange_type_traits<x_int32>::value_type >(
sqlite3_column_int(statement_.stmt_, pos)
);
break;

case x_long_long:
exchange_type_cast<x_long_long>(data_)
= static_cast<exchange_type_traits<x_long_long>::value_type >(
case x_uint32:
exchange_type_cast<x_uint32>(data_)
= static_cast<exchange_type_traits<x_uint32>::value_type >(
sqlite3_column_int(statement_.stmt_, pos)
);
break;

case x_int64:
exchange_type_cast<x_int64>(data_)
= static_cast<exchange_type_traits<x_int64>::value_type >(
sqlite3_column_int64(statement_.stmt_, pos)
);
break;

case x_unsigned_long_long:
exchange_type_cast<x_unsigned_long_long>(data_)
= static_cast<exchange_type_traits<x_unsigned_long_long>::value_type >(
case x_uint64:
exchange_type_cast<x_uint64>(data_)
= static_cast<exchange_type_traits<x_uint64>::value_type >(
sqlite3_column_int64(statement_.stmt_, pos)
);
break;
Expand Down
48 changes: 34 additions & 14 deletions src/backends/sqlite3/standard-use-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace soci::details;

sqlite3_standard_use_type_backend::sqlite3_standard_use_type_backend(
sqlite3_statement_backend &st)
: statement_(st), data_(NULL), type_(x_integer), position_(-1)
: statement_(st), data_(NULL), type_(x_int32), position_(-1)
{
}

Expand Down Expand Up @@ -112,24 +112,44 @@ void sqlite3_standard_use_type_backend::pre_use(indicator const * ind)
break;
}

case x_short:
col.type_ = dt_integer;
col.int32_ = exchange_type_cast<x_short>(data_);
case x_int8:
col.type_ = dt_int8;
col.int8_ = exchange_type_cast<x_int8>(data_);
break;

case x_integer:
col.type_ = dt_integer;
col.int32_ = exchange_type_cast<x_integer>(data_);
case x_uint8:
col.type_ = dt_uint8;
col.uint8_ = exchange_type_cast<x_uint8>(data_);
break;

case x_long_long:
col.type_ = dt_long_long;
col.int64_ = exchange_type_cast<x_long_long>(data_);
case x_int16:
col.type_ = dt_int16;
col.int16_ = exchange_type_cast<x_int16>(data_);
break;

case x_unsigned_long_long:
col.type_ = dt_long_long;
col.int64_ = exchange_type_cast<x_unsigned_long_long>(data_);
case x_uint16:
col.type_ = dt_uint16;
col.uint16_ = exchange_type_cast<x_uint16>(data_);
break;

case x_int32:
col.type_ = dt_int32;
col.int32_ = exchange_type_cast<x_int32>(data_);
break;

case x_uint32:
col.type_ = dt_uint32;
col.uint32_ = exchange_type_cast<x_uint32>(data_);
break;

case x_int64:
col.type_ = dt_int64;
col.int64_ = exchange_type_cast<x_int64>(data_);
break;

case x_uint64:
col.type_ = dt_uint64;
col.uint64_ = exchange_type_cast<x_uint64>(data_);
break;

case x_double:
Expand All @@ -155,7 +175,7 @@ void sqlite3_standard_use_type_backend::pre_use(indicator const * ind)

case x_rowid:
{
col.type_ = dt_long_long;
col.type_ = dt_int64;
// RowID is internally identical to unsigned long
rowid *rid = static_cast<rowid *>(data_);
sqlite3_rowid_backend *rbe = static_cast<sqlite3_rowid_backend *>(rid->get_backend());
Expand Down
85 changes: 61 additions & 24 deletions src/backends/sqlite3/statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cstring>
#include <functional>
#include <sstream>
#include <stdint.h>
#include <string>

#ifdef _MSC_VER
Expand Down Expand Up @@ -177,14 +178,30 @@ sqlite3_statement_backend::load_rowset(int totalRows)
col.double_ = sqlite3_column_double(stmt_, c);
break;

case dt_integer:
col.int32_ = sqlite3_column_int(stmt_, c);
case dt_int8:
col.int8_ = static_cast<int8_t>(sqlite3_column_int(stmt_, c));
break;

case dt_long_long:
case dt_unsigned_long_long:
case dt_uint8:
col.uint8_ = static_cast<uint8_t>(sqlite3_column_int(stmt_, c));
break;
case dt_int16:
col.int16_ = static_cast<int16_t>(sqlite3_column_int(stmt_, c));
break;
case dt_uint16:
col.uint16_ = static_cast<uint16_t>(sqlite3_column_int(stmt_, c));
break;
case dt_int32:
col.int32_ = static_cast<int32_t>(sqlite3_column_int(stmt_, c));
break;
case dt_uint32:
col.uint32_ = static_cast<uint32_t>(sqlite3_column_int(stmt_, c));
break;
case dt_int64:
col.int64_ = sqlite3_column_int64(stmt_, c);
break;
case dt_uint64:
col.uint64_ = static_cast<sqlite_api::sqlite3_uint64>(sqlite3_column_int64(stmt_, c));
break;

case dt_blob:
col.buffer_.size_ = sqlite3_column_bytes(stmt_, c);
Expand Down Expand Up @@ -283,14 +300,30 @@ sqlite3_statement_backend::bind_and_execute(int number)
bindRes = sqlite3_bind_double(stmt_, pos, col.double_);
break;

case dt_integer:
bindRes = sqlite3_bind_int(stmt_, pos, col.int32_);
case dt_int8:
bindRes = sqlite3_bind_int(stmt_, pos, static_cast<int>(col.int8_));
break;

case dt_long_long:
case dt_unsigned_long_long:
case dt_uint8:
bindRes = sqlite3_bind_int(stmt_, pos, static_cast<int>(col.uint8_));
break;
case dt_int16:
bindRes = sqlite3_bind_int(stmt_, pos, static_cast<int>(col.int16_));
break;
case dt_uint16:
bindRes = sqlite3_bind_int(stmt_, pos, static_cast<int>(col.uint16_));
break;
case dt_int32:
bindRes = sqlite3_bind_int(stmt_, pos, static_cast<int>(col.int32_));
break;
case dt_uint32:
bindRes = sqlite3_bind_int64(stmt_, pos, static_cast<sqlite_api::sqlite3_int64>(col.uint32_));
break;
case dt_int64:
bindRes = sqlite3_bind_int64(stmt_, pos, col.int64_);
break;
case dt_uint64:
bindRes = sqlite3_bind_int64(stmt_, pos, static_cast<sqlite_api::sqlite3_int64>(col.int64_));
break;

case dt_blob:
bindRes = sqlite3_bind_blob(stmt_, pos, col.buffer_.constData_, static_cast<int>(col.buffer_.size_), NULL);
Expand Down Expand Up @@ -433,18 +466,22 @@ static sqlite3_data_type_map get_data_type_map()
m["numeric"] = dt_double;
m["real"] = dt_double;

// dt_integer
m["boolean"] = dt_integer;
m["int"] = dt_integer;
m["integer"] = dt_integer;
m["int2"] = dt_integer;
m["mediumint"] = dt_integer;
m["smallint"] = dt_integer;
m["tinyint"] = dt_integer;
// dt_int8
m["tinyint"] = dt_int8;

// dt_int16
m["smallint"] = dt_int16;

// dt_int32
m["boolean"] = dt_int32;
m["int"] = dt_int32;
m["integer"] = dt_int32;
m["int2"] = dt_int32;
m["mediumint"] = dt_int32;

// dt_long_long
m["bigint"] = dt_long_long;
m["int8"] = dt_long_long;
// dt_int64
m["bigint"] = dt_int64;
m["int8"] = dt_int64;

// dt_string
m["char"] = dt_string;
Expand All @@ -457,8 +494,8 @@ static sqlite3_data_type_map get_data_type_map()
m["varchar"] = dt_string;
m["varyingcharacter"] = dt_string;

// dt_unsigned_long_long
m["unsignedbigint"] = dt_unsigned_long_long;
// dt_uint64
m["unsignedbigint"] = dt_uint64;


return m;
Expand Down Expand Up @@ -524,7 +561,7 @@ void sqlite3_statement_backend::describe_column(int colNum, data_type & type,
switch (sqlite3_type)
{
case SQLITE_INTEGER:
type = dt_integer;
type = dt_int32;
break;
case SQLITE_FLOAT:
type = dt_double;
Expand Down
Loading