Skip to content

Commit

Permalink
Merge branch 'data_types'
Browse files Browse the repository at this point in the history
Provide complete support for all C++ integer types and map them to the
corresponding database types whenever possible.

See #954, #1116.
  • Loading branch information
vadz committed Jan 11, 2024
2 parents 1b63f94 + 41dc500 commit 78ee6ef
Show file tree
Hide file tree
Showing 90 changed files with 5,447 additions and 1,345 deletions.
45 changes: 38 additions & 7 deletions docs/api/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ enum data_type
dt_string, dt_date, dt_double, dt_integer, dt_long_long, dt_unsigned_long_long
};

// data types, as seen by the user
enum db_type
{
db_string,
db_int8,
db_uint8,
db_int16,
db_uint16,
db_int32,
db_uint32,
db_int64,
db_uint64,
db_double,
db_date,
db_blob,
db_xml
};

// the enum type for indicator variables
enum indicator { i_ok, i_null, i_truncated };

Expand All @@ -32,15 +50,26 @@ enum exchange_type
{
x_char,
x_stdstring,
x_short,
x_integer,
x_long_long,
x_unsigned_long_long,
x_int8,
x_uint8,
x_int16,
x_short = x_int16,
x_uint16,
x_int32,
x_integer = x_int32,
x_uint32,
x_int64,
x_long_long = x_int64,
x_uint64,
x_unsigned_long_long = x_uint64,
x_double,
x_stdtm,
x_statement,
x_rowid,
x_blob
x_blob,

x_xmltype,
x_longstring
};

struct cstring_descriptor
Expand All @@ -60,8 +89,9 @@ public:
};
```
The `data_type` enumeration type defines all types that form the core type support for SOCI.
The `data_type` and `db_type` enumeration type defines all types that form the core type support for SOCI.
The enum itself can be used by clients when dealing with dynamic rowset description.
`data_type` is deprecated in favor of `db_type`, so users are encouraged to use the latter.
The `indicator` enumeration type defines all recognized *states* of data.
The `i_truncated` state is provided for the case where the string is retrieved from the database
Expand Down Expand Up @@ -190,7 +220,8 @@ public:
virtual std::string rewrite_for_procedure_call(std::string const& query) = 0;

virtual int prepare_for_describe() = 0;
virtual void describe_column(int colNum, data_type& dtype,
virtual void describe_column(int colNum,
db_type& dbtype,
std::string& column_name) = 0;

virtual standard_into_type_backend* make_into_type_backend() = 0;
Expand Down
84 changes: 81 additions & 3 deletions docs/api/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ The following types are commonly used in the rest of the interface:

```cpp
// data types, as seen by the user
enum db_type { db_string, db_date, db_double, db_int8, db_uint8, db_int16, db_uint16, db_int32, db_uint32, db_int64, db_uint64 };

// deprecated data types enum which may be still used but is less precise than db_type
enum data_type { dt_string, dt_date, dt_double, dt_integer, dt_long_long, dt_unsigned_long_long };

// the enum type for indicator variables
Expand All @@ -22,7 +25,8 @@ enum indicator { i_ok, i_null, i_truncated };
class soci_error : public std::runtime_error { /* ... */ };
```
The `data_type` type defines the basic SOCI data types. User provided data types need to be associated with one of these basic types.
`db_type` defines the basic SOCI data types. User provided data types need to be associated with one of these basic types.
`data_type` is deprecated in favor of `db_type`, please don't use it in the new code any longer.
The `indicator` type defines the possible states of data.
Expand Down Expand Up @@ -443,14 +447,16 @@ class column_properties
{
public:
std::string get_name() const;
data_type get_data_type() const;
db_type get_db_type() const;
data_type_type get_data_type() const;
};
```

This class contains the following members:

* `get_name` function that returns the name of the column.
* `get_data_type` that returns the type of the column.
* `get_db_type` that returns the type of the column.
* `get_data_type` that returns the type of the column (deprecated in favor of `get_db_type`).

See [Dynamic resultset binding](../types.md#dynamic-binding) for examples.

Expand Down Expand Up @@ -642,13 +648,29 @@ The functions above create and destroy the statement object. If the statement ca
int soci_into_string (statement_handle st);
int soci_into_int (statement_handle st);
int soci_into_long_long(statement_handle st);
int soci_into_int8 (statement_handle st);
int soci_into_uint8 (statement_handle st);
int soci_into_int16 (statement_handle st);
int soci_into_uint16 (statement_handle st);
int soci_into_int32 (statement_handle st);
int soci_into_uint32 (statement_handle st);
int soci_into_int64 (statement_handle st);
int soci_into_uint64 (statement_handle st);
int soci_into_double (statement_handle st);
int soci_into_date (statement_handle st);
int soci_into_blob (statement_handle st);

int soci_into_string_v (statement_handle st);
int soci_into_int_v (statement_handle st);
int soci_into_long_long_v(statement_handle st);
int soci_into_int8_v (statement_handle st);
int soci_into_uint8_v (statement_handle st);
int soci_into_int16_v (statement_handle st);
int soci_into_uint16_v (statement_handle st);
int soci_into_int32_v (statement_handle st);
int soci_into_uint32_v (statement_handle st);
int soci_into_int64_v (statement_handle st);
int soci_into_uint64_v (statement_handle st);
int soci_into_double_v (statement_handle st);
int soci_into_date_v (statement_handle st);
```
Expand All @@ -669,13 +691,29 @@ This function returns `1` if the into element at the given position has non-null
char const * soci_get_into_string (statement_handle st, int position);
int soci_get_into_int (statement_handle st, int position);
long long soci_get_into_long_long(statement_handle st, int position);
int8_t soci_get_into_int8 (statement_handle st, int position);
uint8_t soci_get_into_uint8 (statement_handle st, int position);
int16_t soci_get_into_int16 (statement_handle st, int position);
uint16_t soci_get_into_uint16 (statement_handle st, int position);
int32_t soci_get_into_int32 (statement_handle st, int position);
uint32_t soci_get_into_uint32 (statement_handle st, int position);
int64_t soci_get_into_int64 (statement_handle st, int position);
uint64_t soci_get_into_uint64 (statement_handle st, int position);
double soci_get_into_double (statement_handle st, int position);
char const * soci_get_into_date (statement_handle st, int position);
blob_handle soci_get_into_blob (statement_handle st, int position);

char const * soci_get_into_string_v (statement_handle st, int position, int index);
int soci_get_into_int_v (statement_handle st, int position, int index);
long long soci_get_into_long_long_v(statement_handle st, int position, int index);
int8_t soci_get_into_int8_v (statement_handle st, int position, int index);
uint8_t soci_get_into_uint8_v (statement_handle st, int position, int index);
int16_t soci_get_into_int16_v (statement_handle st, int position, int index);
uint16_t soci_get_into_uint16_v (statement_handle st, int position, int index);
int32_t soci_get_into_int32_v (statement_handle st, int position, int index);
uint32_t soci_get_into_uint32_v (statement_handle st, int position, int index);
int64_t soci_get_into_int64_v (statement_handle st, int position, int index);
uint64_t soci_get_into_uint64_v (statement_handle st, int position, int index);
double soci_get_into_double_v (statement_handle st, int position, int index);
char const * soci_get_into_date_v (statement_handle st, int position, int index);
```
Expand All @@ -688,13 +726,29 @@ The functions above allow to retrieve the current value of the given into elemen
void soci_use_string (statement_handle st, char const * name);
void soci_use_int (statement_handle st, char const * name);
void soci_use_long_long(statement_handle st, char const * name);
void soci_use_int8 (statement_handle st, char const * name);
void soci_use_uint8 (statement_handle st, char const * name);
void soci_use_int16 (statement_handle st, char const * name);
void soci_use_uint16 (statement_handle st, char const * name);
void soci_use_int32 (statement_handle st, char const * name);
void soci_use_uint32 (statement_handle st, char const * name);
void soci_use_int64 (statement_handle st, char const * name);
void soci_use_uint64 (statement_handle st, char const * name);
void soci_use_double (statement_handle st, char const * name);
void soci_use_date (statement_handle st, char const * name);
void soci_use_blob (statement_handle st, char const * name);
void soci_use_string_v (statement_handle st, char const * name);
void soci_use_int_v (statement_handle st, char const * name);
void soci_use_long_long_v(statement_handle st, char const * name);
void soci_use_int8_v (statement_handle st, char const * name);
void soci_use_uint8_v (statement_handle st, char const * name);
void soci_use_int16_v (statement_handle st, char const * name);
void soci_use_uint16_v (statement_handle st, char const * name);
void soci_use_int32_v (statement_handle st, char const * name);
void soci_use_uint32_v (statement_handle st, char const * name);
void soci_use_int64_v (statement_handle st, char const * name);
void soci_use_uint64_v (statement_handle st, char const * name);
void soci_use_double_v (statement_handle st, char const * name);
void soci_use_date_v (statement_handle st, char const * name);
```
Expand All @@ -718,6 +772,14 @@ These functions get and set the size of vector use elements (see comments for ve
void soci_set_use_string (statement_handle st, char const * name, char const * val);
void soci_set_use_int (statement_handle st, char const * name, int val);
void soci_set_use_long_long(statement_handle st, char const * name, long long val);
void soci_set_use_int8 (statement_handle st, char const * name, int8_t val);
void soci_set_use_uint8 (statement_handle st, char const * name, uint8_t val);
void soci_set_use_int16 (statement_handle st, char const * name, int16_t val);
void soci_set_use_uint16 (statement_handle st, char const * name, uint16_t val);
void soci_set_use_int32 (statement_handle st, char const * name, int32_t val);
void soci_set_use_uint32 (statement_handle st, char const * name, uint32_t val);
void soci_set_use_int64 (statement_handle st, char const * name, int64_t val);
void soci_set_use_uint64 (statement_handle st, char const * name, uint64_t val);
void soci_set_use_double (statement_handle st, char const * name, double val);
void soci_set_use_date (statement_handle st, char const * name, char const * val);
void soci_set_use_blob (statement_handle st, char const * name, blob_handle blob);
Expand All @@ -726,6 +788,14 @@ void soci_set_use_state_v (statement_handle st, char const * name, int index,
void soci_set_use_string_v (statement_handle st, char const * name, int index, char const * val);
void soci_set_use_int_v (statement_handle st, char const * name, int index, int val);
void soci_set_use_long_long_v(statement_handle st, char const * name, int index, long long val);
void soci_set_use_int8_v (statement_handle st, char const * name, int index, int8_t val);
void soci_set_use_uint8_v (statement_handle st, char const * name, int index, uint8_t val);
void soci_set_use_int16_v (statement_handle st, char const * name, int index, int16_t val);
void soci_set_use_uint16_v (statement_handle st, char const * name, int index, uint16_t val);
void soci_set_use_int32_v (statement_handle st, char const * name, int index, int32_t val);
void soci_set_use_uint32_v (statement_handle st, char const * name, int index, uint32_t val);
void soci_set_use_int64_v (statement_handle st, char const * name, int index, int64_t val);
void soci_set_use_uint64_v (statement_handle st, char const * name, int index, uint64_t val);
void soci_set_use_double_v (statement_handle st, char const * name, int index, double val);
void soci_set_use_date_v (statement_handle st, char const * name, int index, char const * val);
```
Expand All @@ -739,6 +809,14 @@ int soci_get_use_state (statement_handle st, char const * name);
char const * soci_get_use_string (statement_handle st, char const * name);
int soci_get_use_int (statement_handle st, char const * name);
long long soci_get_use_long_long(statement_handle st, char const * name);
int8_t soci_get_use_int8 (statement_handle st, char const * name);
uint8_t soci_get_use_uint8 (statement_handle st, char const * name);
int16_t soci_get_use_int16 (statement_handle st, char const * name);
uint16_t soci_get_use_uint16 (statement_handle st, char const * name);
int32_t soci_get_use_int32 (statement_handle st, char const * name);
uint32_t soci_get_use_uint32 (statement_handle st, char const * name);
int64_t soci_get_use_int64 (statement_handle st, char const * name);
uint64_t soci_get_use_uint64 (statement_handle st, char const * name);
double soci_get_use_double (statement_handle st, char const * name);
char const * soci_get_use_date (statement_handle st, char const * name);
blob_handle soci_get_use_blob (statement_handle st, char const * name);
Expand Down
27 changes: 19 additions & 8 deletions docs/backends/firebird.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,25 @@ type is not known at compile time.
When calling `row::get<T>()`, the type you should pass as T depends upon the underlying database type.
For the Firebird backend, this type mapping is:

|Firebird Data Type|SOCI Data Type|`row::get<T>` specializations|
|--- |--- |--- |
|numeric, decimal (where scale > 0)|dt_double|double|
|numeric, decimal [^1] (where scale = 0)|dt_integer, dt_double|int, double|
|double precision, float|dt_double|double|
|smallint, integer|dt_integer|int|
|char, varchar|dt_string|std::string|
|date, time, timestamp|dt_date|std::tm|
| Firebird Data Type | SOCI Data Type (`data_type`) | `row::get<T>` specializations |
| --------------------------------------- | --------------------------------------- | --------------------------------- |
| numeric, decimal (where scale > 0) | dt_double | double |
| numeric, decimal [^1] (where scale = 0) | dt_integer, dt_double | int, double |
| double precision, float | dt_double | double |
| smallint, integer | dt_integer | int |
| char, varchar | dt_string | std::string |
| date, time, timestamp | dt_date | std::tm |

| Firebird Data Type | SOCI Data Type (`db_type`) | `row::get<T>` specializations |
| --------------------------------------- | --------------------------------------- | --------------------------------- |
| numeric, decimal (where scale > 0) | db_double | double |
| numeric, decimal [^1] (where scale = 0) | db_int16/db_int32/db_int64, db_double | int16_t/int32_t/int64_t, double |
| double precision, float | db_double | double |
| smallint | db_int16 | int16_t |
| integer | db_int32 | int32_t |
| bigint | db_int64 | int64_t |
| char, varchar | db_string | std::string |
| date, time, timestamp | db_date | std::tm |

[^1] There is also 64bit integer type for larger values which is
currently not supported.
Expand Down
Loading

0 comments on commit 78ee6ef

Please sign in to comment.