Skip to content

Commit

Permalink
Merge pull request #27 from pacman82/Renaming-and-safe-usage
Browse files Browse the repository at this point in the history
Change naming conventions and types
  • Loading branch information
pacman82 authored Aug 3, 2020
2 parents d02fcc8 + 9c6238c commit 6af05a5
Show file tree
Hide file tree
Showing 16 changed files with 1,307 additions and 1,284 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "odbc-sys"
version = "0.9.0"
version = "0.10.0"
authors = ["Markus Klein <[email protected]>"]
license = "MIT"
description = "ODBC ffi bindings"
Expand Down
23 changes: 17 additions & 6 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
Changelog
=========

0.10.0
------

*Breaking Changes*:

* Enum variant names have been shortend and use now idiomatic CamelCasing.
* Type Names now also use idiomatic CamelCasing.
* The `SQL` prefix has been dropped from most type names.
* `InputOutput` has been renamed to `ParamType`. As the names of the enumeration should be derived of the Prefix of the associated constants in the C Headers.
* Enumerations which have been casted from integers are now newtypes in order to prevent undefined behaviour in case the enum is not complete or the driver/driver manager is not ODBC conform.
* `SqlReturn` is now a newtype i16 with predifined constants and is now named `Return`.
* `Nullable` is now a newtype i16 with predefined constants.
* `interval_type` in `IntervalStruct` has been changed from `Interval` to `c_int`.

0.9.0
-----

* Adds `attributes::SQL_ATTR_CONNECTION_POOLING` and `attributes::SQL_ATTR_CP_MATCH` enums
* Implements Default trait for attribute values


### BREAKING CHANGES

* `SQL_ATTR_APPLICATION_KEY` constant removed because it is not part of the ODBC standard.
* *Breaking Change*: `SQL_ATTR_APPLICATION_KEY` constant removed because it is not part of the ODBC standard.
If there is any software that depends on this constant defined, users are encouraged to open an
issue report
* `SQL_OV_ODBC_2` constant removed because odbc-sys does not support OBDC versions < 3.0.
* Enum OdbcVersion renamed to `SQL_ATTR_ODBC_VERSION` to better reflect it's intended use as a value
* *Breaking Change*: `SQL_OV_ODBC_2` constant removed because odbc-sys does not support OBDC versions < 3.0.
* *Breaking Change*: Enum OdbcVersion renamed to `SQL_ATTR_ODBC_VERSION` to better reflect it's intended use as a value
for environment attribute to be used with `SQLSetEnvAttr` and `SQLGetEnvAttr` functions

0.8.2
Expand Down
79 changes: 33 additions & 46 deletions src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,100 +1,87 @@
use crate::SQLPOINTER;

pub use EnvironmentAttribute::*;
pub use SQL_ATTR_CONNECTION_POOLING::*;
pub use SQL_ATTR_CP_MATCH::*;
pub use SQL_ATTR_ODBC_VERSION::*;
use crate::Pointer;

/// Governs behaviour of EnvironmentAttribute
#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum EnvironmentAttribute {
SQL_ATTR_ODBC_VERSION = 200,
SQL_ATTR_CONNECTION_POOLING = 201,
SQL_ATTR_CP_MATCH = 202,
OdbcVersion = 200,
ConnectionPooling = 201,
CpMatch = 202,
// This attribute was commented out because there is no mention of it in the ODBC
// specification nor does this attribute exist in unixODBC or iODBC implementations.
// This attribute exists in Microsoft implementation only and it's usage is unclear.
// For private driver manager
//SQL_ATTR_APPLICATION_KEY = 203,
SQL_ATTR_OUTPUT_NTS = 10001,
OutputNts = 10001,
}

/// ODBC verions
///
/// Possible values for `SQL_ATTR_ODBC_VERSION` attribute set with `SQLSetEnvAttr` to
/// Possible values for `OdbcVersion` attribute set with `SQLSetEnvAttr` to
/// declare ODBC version
#[repr(i32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SQL_ATTR_ODBC_VERSION {
pub enum AttrOdbcVersion {
// Not supported by this crate
// SQL_OV_ODBC2 = 2,
SQL_OV_ODBC3 = 3,
Odbc3 = 3,
#[cfg(feature = "odbc_version_3_80")]
SQL_OV_ODBC3_80 = 380,
Odbc3_80 = 380,
#[cfg(feature = "odbc_version_4")]
SQL_OV_ODBC4 = 400,
Odbc4 = 400,
}

impl From<SQL_ATTR_ODBC_VERSION> for SQLPOINTER {
fn from(source: SQL_ATTR_ODBC_VERSION) -> SQLPOINTER {
source as i32 as SQLPOINTER
impl From<AttrOdbcVersion> for Pointer {
fn from(source: AttrOdbcVersion) -> Pointer {
source as i32 as Pointer
}
}
/// Connection pool configuration
///
/// Possible values for `SQL_ATTR_CONNECTION_POOLING` attribute set with `SQLSetEnvAttr` to define
/// Possible values for `ConnectionPooling` attribute set with `SQLSetEnvAttr` to define
/// which pooling scheme will be used
#[repr(u32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SQL_ATTR_CONNECTION_POOLING {
SQL_CP_OFF = 0,
SQL_CP_ONE_PER_DRIVER = 1,
SQL_CP_ONE_PER_HENV = 2,
SQL_CP_DRIVER_AWARE = 3,
pub enum AttrConnectionPooling {
Off = 0,
OnePerDriver = 1,
OnePerHenv = 2,
DriverAware = 3,
}

/// Connection pool default configuration
pub const SQL_CP_DEFAULT: SQL_ATTR_CONNECTION_POOLING = SQL_ATTR_CONNECTION_POOLING::SQL_CP_OFF;

impl Default for SQL_ATTR_CONNECTION_POOLING {
impl Default for AttrConnectionPooling {
fn default() -> Self {
SQL_CP_DEFAULT
AttrConnectionPooling::Off
}
}

impl From<SQL_ATTR_CONNECTION_POOLING> for SQLPOINTER {
fn from(source: SQL_ATTR_CONNECTION_POOLING) -> SQLPOINTER {
source as u32 as SQLPOINTER
impl From<AttrConnectionPooling> for Pointer {
fn from(source: AttrConnectionPooling) -> Pointer {
source as u32 as Pointer
}
}

/// Matching of pooled connections
///
/// Possible values for `SQL_ATTR_CP_MATCH` attribute set with `SQLSetEnvAttr` to define
/// Possible values for `CpMatch` attribute set with `SQLSetEnvAttr` to define
/// which connection attributes must match for a connection returned from the pool
#[repr(u32)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SQL_ATTR_CP_MATCH {
SQL_CP_STRICT_MATCH = 0,
SQL_CP_RELAXED_MATCH = 1,
pub enum AttrCpMatch {
Strict = 0,
Relaxed = 1,
}

/// Default matching for connections returned from the pool
pub const SQL_CP_MATCH_DEFAULT: SQL_ATTR_CP_MATCH = SQL_ATTR_CP_MATCH::SQL_CP_STRICT_MATCH;

impl Default for SQL_ATTR_CP_MATCH {
impl Default for AttrCpMatch {
fn default() -> Self {
SQL_CP_MATCH_DEFAULT
AttrCpMatch::Strict
}
}

impl From<SQL_ATTR_CP_MATCH> for SQLPOINTER {
fn from(source: SQL_ATTR_CP_MATCH) -> SQLPOINTER {
source as u32 as SQLPOINTER
impl From<AttrCpMatch> for Pointer {
fn from(source: AttrCpMatch) -> Pointer {
source as u32 as Pointer
}
}
9 changes: 9 additions & 0 deletions src/bulk_operation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// Supported `BulkOperation` operations
#[repr(u16)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum BulkOperation {
Add = 4,
UpdateByBookmark = 5,
DeleteByBookmark = 6,
FetchByBookmark = 7,
}
91 changes: 45 additions & 46 deletions src/c_data_type.rs
Original file line number Diff line number Diff line change
@@ -1,75 +1,74 @@
/// Extended C Types range 4000 and above. Range of -100 thru 200 is reserved by Driver Manager.
pub const SQL_C_TYPES_EXTENDED: i16 = 0x04000;
/// `SQL_C_TYPES_EXTENDED`.
pub const C_TYPES_EXTENDED: i16 = 0x04000;

/// The C data type is specified in the SQLBindCol and SQLGetData functions with the TargetType
/// argument and in the SQLBindParameter function with the ValueType argument.
#[repr(i16)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum SqlCDataType {
SQL_C_UTINYINT = -28,
SQL_C_UBIGINT = -27,
SQL_C_STINYINT = -26,
SQL_C_SBIGINT = -25,
pub enum CDataType {
UTinyInty = -28,
UBigInt = -27,
STinyInt = -26,
SBigInt = -25,

SQL_C_ULONG = -18,
SQL_C_USHORT = -17,
SQL_C_SLONG = -16,
SQL_C_SSHORT = -15,
ULong = -18,
UShort = -17,
SLong = -16,
SShort = -15,

#[cfg(feature = "odbc_version_3_50")]
SQL_C_GUID = -11,
Guid = -11,

SQL_C_WCHAR = -8,
WChar = -8,

SQL_C_BIT = -7,
Bit = -7,
// deprecated
// SQL_C_TINYINT = -6,
SQL_C_BINARY = -2,
Binary = -2,
/// `SQLCHAR` - CHAR, VARCHAR, DECIMAL, NUMERIC
SQL_C_CHAR = 1,
SQL_C_NUMERIC = 2,
Char = 1,
Numeric = 2,

// deprecated
// SQL_C_LONG = 4,
// SQL_C_SHORT = 5,
SQL_C_FLOAT = 7,
SQL_C_DOUBLE = 8,
SQL_C_DATE = 9,
SQL_C_TIME = 10,
SQL_C_TIMESTAMP = 11,
Float = 7,
Double = 8,
Date = 9,
Time = 10,
TimeStamp = 11,

SQL_C_TYPE_DATE = 91,
SQL_C_TYPE_TIME = 92,
SQL_C_TYPE_TIMESTAMP = 93,
TypeDate = 91,
TypeTime = 92,
TypeTimestamp = 93,
#[cfg(feature = "odbc_version_4")]
SQL_C_TYPE_TIME_WITH_TIMEZONE = 94,
TypeTimeWithTimezone = 94,
#[cfg(feature = "odbc_version_4")]
SQL_C_TYPE_TIMESTAMP_WITH_TIMEZONE = 95,
TypeTimestampWithTimzone = 95,

SQL_C_DEFAULT = 99,
Default = 99,

SQL_C_INTERVAL_YEAR = 101,
SQL_C_INTERVAL_MONTH = 102,
SQL_C_INTERVAL_DAY = 103,
SQL_C_INTERVAL_HOUR = 104,
SQL_C_INTERVAL_MINUTE = 105,
SQL_C_INTERVAL_SECOND = 106,
SQL_C_INTERVAL_YEAR_TO_MONTH = 107,
SQL_C_INTERVAL_DAY_TO_HOUR = 108,
SQL_C_INTERVAL_DAY_TO_MINUTE = 109,
SQL_C_INTERVAL_DAY_TO_SECOND = 110,
SQL_C_INTERVAL_HOUR_TO_MINUTE = 111,
SQL_C_INTERVAL_HOUR_TO_SECOND = 112,
SQL_C_INTERVAL_MINUTE_TO_SECOND = 113,
IntervalYear = 101,
IntervalMonth = 102,
IntervalDay = 103,
IntervalHour = 104,
IntervalMinute = 105,
IntervalSecond = 106,
IntervalYearToMonth = 107,
IntervalDayToHour = 108,
IntervalDayToMinute = 109,
IntervalDayToSecond = 110,
IntervalHourToMinute = 111,
IntervalHourToSecond = 112,
IntervalMinuteToSecond = 113,

SQL_C_SS_TIME2 = SQL_C_TYPES_EXTENDED + 0,
SQL_C_SS_TIMESTAMPOFFSET = SQL_C_TYPES_EXTENDED + 1,
SsTime2 = C_TYPES_EXTENDED + 0,
SsTimestampOffset = C_TYPES_EXTENDED + 1,
}

pub use self::SqlCDataType::*;

#[cfg(windows)]
pub use SQL_C_ULONG as SQL_C_UBIGINT;
pub use CDataType::ULong as UBigInt;
#[cfg(not(windows))]
pub use SQL_C_ULONG as SQL_C_BOOKMARK;
pub use CDataType::ULong as Bookmark;
20 changes: 9 additions & 11 deletions src/fetch_orientation.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/// Codes used for FetchOrientation in `SQLFetchScroll`, `SQLDataSources` and in `SQLDrivers`
#[repr(u16)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum FetchOrientation {
SQL_FETCH_NEXT = 1,
SQL_FETCH_FIRST = 2,
Next = 1,
First = 2,
// Other codes used for FetchOrientation in SQLFetchScroll()
SQL_FETCH_LAST = 3,
SQL_FETCH_PRIOR = 4,
SQL_FETCH_ABSOLUTE = 5,
SQL_FETCH_RELATIVE = 6,
Last = 3,
Prior = 4,
Absolute = 5,
Relative = 6,
// additional SQLDataSources fetch directions
SQL_FETCH_FIRST_USER = 31,
SQL_FETCH_FIRST_SYSTEM = 32,
}
pub use self::FetchOrientation::*;
FirstUser = 31,
FirstSystem = 32,
}
Loading

0 comments on commit 6af05a5

Please sign in to comment.