http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h b/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h new file mode 100644 index 0000000..6636ca4 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/common_types.h @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_COMMON_TYPES +#define _IGNITE_ODBC_COMMON_TYPES + +#include <stdint.h> + +namespace ignite +{ + namespace odbc + { + +#ifdef _WIN64 + typedef long long SqlLen; +#else + typedef long SqlLen; +#endif + + /** + * SQL result. + */ + enum SqlResult + { + /** Success. */ + SQL_RESULT_SUCCESS, + + /** Success with info. */ + SQL_RESULT_SUCCESS_WITH_INFO, + + /** Error. */ + SQL_RESULT_ERROR, + + /** No more data. */ + SQL_RESULT_NO_DATA + }; + + /** + * Provides detailed information about the cause of a warning or error. + */ + enum SqlState + { + /** Undefined state. Internal, should never be exposed to user. */ + SQL_STATE_UNKNOWN, + + /** Output data has been truncated. */ + SQL_STATE_01004_DATA_TRUNCATED, + + /** Error in row. */ + SQL_STATE_01S01_ERROR_IN_ROW, + + /** + * The driver did not support the specified value and + * substituted a similar value. + */ + SQL_STATE_01S02_OPTION_VALUE_CHANGED, + + /** Invalid cursor state. */ + SQL_STATE_24000_INVALID_CURSOR_STATE, + + /** + * The driver was unable to establish a connection with the data + * source. + */ + SQL_STATE_08001_CANNOT_CONNECT, + + /** + * The specified ConnectionHandle had already been used + * to establish a connection with a data source, and the connection + * was still open. + */ + SQL_STATE_08002_ALREADY_CONNECTED, + + /** The connection specified was not open. */ + SQL_STATE_08003_NOT_CONNECTED, + + /** + * An error occurred for which there was no specific SQLSTATE + * and for which no implementation-specific SQLSTATE was defined. + */ + SQL_STATE_HY000_GENERAL_ERROR, + + /** + * The driver was unable to allocate memory for the specified + * handle. + */ + SQL_STATE_HY001_MEMORY_ALLOCATION, + + /** Function sequence error. */ + SQL_STATE_HY010_SEQUENCE_ERROR, + + /** Column type out of range. */ + SQL_STATE_HY097_COLUMN_TYPE_OUT_OF_RANGE, + + /** + * The driver does not support the feature of ODBC behavior that + * the application requested. + */ + SQL_STATE_HYC00_OPTIONAL_FEATURE_NOT_IMPLEMENTED, + + /** + * The connection timeout period expired before the data source + * responded to the request. + */ + SQL_STATE_HYT01_CONNECTIOIN_TIMEOUT + }; + + /** + * Diagnostic field type. + */ + enum DiagnosticField + { + /** Field type is unknown to the driver. */ + IGNITE_SQL_DIAG_UNKNOWN, + + /** Header record field: Count of rows in the cursor. */ + IGNITE_SQL_DIAG_HEADER_CURSOR_ROW_COUNT, + + /** + * Header record field: String that describes the SQL statement + * that the underlying function executed. + */ + IGNITE_SQL_DIAG_HEADER_DYNAMIC_FUNCTION, + + /** + * Header record field: Numeric code that describes the SQL + * statement that was executed by the underlying function. + */ + IGNITE_SQL_DIAG_HEADER_DYNAMIC_FUNCTION_CODE, + + /** Header record field: Number of status records. */ + IGNITE_SQL_DIAG_HEADER_NUMBER, + + /** Header record field: Last operation return code. */ + IGNITE_SQL_DIAG_HEADER_RETURNCODE, + + /** Header record field: Row count. */ + IGNITE_SQL_DIAG_HEADER_ROW_COUNT, + + /** Status record field: Class origin. */ + IGNITE_SQL_DIAG_STATUS_CLASS_ORIGIN, + + /** Status record field: Column number. */ + IGNITE_SQL_DIAG_STATUS_COLUMN_NUMBER, + + /** Status record field: Connection name. */ + IGNITE_SQL_DIAG_STATUS_CONNECTION_NAME, + + /** Status record field: Message text. */ + IGNITE_SQL_DIAG_STATUS_MESSAGE_TEXT, + + /** Status record field: Native result code. */ + IGNITE_SQL_DIAG_STATUS_NATIVE, + + /** Status record field: Row number. */ + IGNITE_SQL_DIAG_STATUS_ROW_NUMBER, + + /** Status record field: Server name. */ + IGNITE_SQL_DIAG_STATUS_SERVER_NAME, + + /** Status record field: SQLSTATE. */ + IGNITE_SQL_DIAG_STATUS_SQLSTATE, + + /** Status record field: Subclass origin. */ + IGNITE_SQL_DIAG_STATUS_SUBCLASS_ORIGIN + }; + + /** + * Environment attribute. + */ + enum EnvironmentAttribute + { + /** ODBC attribute is unknown to the driver. */ + IGNITE_SQL_ENV_ATTR_UNKNOWN, + + /** ODBC version. */ + IGNITE_SQL_ENV_ATTR_ODBC_VERSION, + + /** Null-termination of strings. */ + IGNITE_SQL_ENV_ATTR_OUTPUT_NTS + }; + + /** + * Convert internal Ignite type into ODBC SQL return code. + * + * @param result Internal result type. + * @return ODBC result type. + */ + int SqlResultToReturnCode(SqlResult result); + + /** + * Convert ODBC field type to internal DiagnosticField type value. + * + * @param field ODBC field type. + * @return Internal DiagnosticField type value. + */ + DiagnosticField DiagnosticFieldToInternal(int16_t field); + + /** + * Convert environment attribute to internal EnvironmentAttribute type value. + * + * @param attr Environment attribute. + * @return Internal EnvironmentAttribute type value. + */ + EnvironmentAttribute EnvironmentAttributeToInternal(int32_t attr); + + + } +} + +#endif //_IGNITE_ODBC_COMMON_TYPES \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h b/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h new file mode 100644 index 0000000..d6d7944 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/config/configuration.h @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_CONFIG_CONFIGURATION +#define _IGNITE_ODBC_CONFIG_CONFIGURATION + +#include <stdint.h> +#include <string> +#include <map> + +#include <ignite/common/common.h> + +namespace ignite +{ + namespace odbc + { + namespace config + { + /** + * ODBC configuration abstraction. + */ + class Configuration + { + public: + /** + * Default constructor. + */ + Configuration(); + + /** + * Destructor. + */ + ~Configuration(); + + /** + * Fill configuration data using connection string. + * + * @param str Pointer to string data. + * @param len String length. + */ + void FillFromConnectString(const char* str, size_t len); + + /** + * Fill configuration data using connection string. + * + * @param str Connect string. + */ + void FillFromConnectString(const std::string& str); + + /** + * Convert configure to connect string. + * + * @return Connect string. + */ + std::string ToConnectString() const; + + /** + * Fill configuration data using config attributes string. + * + * @param str Pointer to list of zero-terminated strings. + * Terminated by two zero bytes. + */ + void FillFromConfigAttributes(const char* attributes); + + /** + * Get server port. + * + * @return Server port. + */ + uint16_t GetPort() const + { + return port; + } + + /** + * Get DSN. + * + * @return Data Source Name. + */ + const std::string& GetDsn() const + { + return dsn; + } + + /** + * Get Driver. + * + * @return Driver name. + */ + const std::string& GetDriver() const + { + return driver; + } + + /** + * Get server host. + * + * @return Server host. + */ + const std::string& GetHost() const + { + return host; + } + + /** + * Get cache. + * + * @return Cache name. + */ + const std::string& GetCache() const + { + return cache; + } + + private: + IGNITE_NO_COPY_ASSIGNMENT(Configuration); + + /** Map containing connect arguments. */ + typedef std::map<std::string, std::string> ArgumentMap; + + /** + * Parse connect string into key-value storage. + * + * @param str String to parse. + * @param len String length. + * @param params Parsing result. + */ + void ParseAttributeList(const char* str, size_t len, char delimeter, ArgumentMap& args) const; + + /** Data Source Name. */ + std::string dsn; + + /** Driver name. */ + std::string driver; + + /** Server hostname. */ + std::string host; + + /** Port of the server. */ + uint16_t port; + + /** Cache name. */ + std::string cache; + }; + } + + } +} + +#endif //_IGNITE_ODBC_CONFIG_CONFIGURATION \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/config/connection_info.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/config/connection_info.h b/modules/platforms/cpp/odbc/include/ignite/odbc/config/connection_info.h new file mode 100644 index 0000000..e0ed152 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/config/connection_info.h @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_CONFIG_CONNECTION_INFO +#define _IGNITE_ODBC_CONFIG_CONNECTION_INFO + +#include <stdint.h> + +#include <map> + +#include <ignite/common/common.h> +#include <ignite/odbc/common_types.h> + +namespace ignite +{ + namespace odbc + { + namespace config + { + /** + * Connection info. + */ + class ConnectionInfo + { + public: + /** Info type. */ + typedef unsigned short InfoType; + +#ifdef ODBC_DEBUG + /** + * Convert type to string containing its name. + * Debug function. + * @param type Info type. + * @return Null-terminated string containing types name. + */ + static const char* InfoTypeToString(InfoType type); +#endif + + /** + * Constructor. + */ + ConnectionInfo(); + + /** + * Destructor. + */ + ~ConnectionInfo(); + + /** + * Get info of any type. + * @param type Info type. + * @param buf Result buffer pointer. + * @param buflen Result buffer length. + * @param reslen Result value length pointer. + * @return True on success. + */ + SqlResult GetInfo(InfoType type, void* buf, short buflen, short* reslen) const; + + private: + IGNITE_NO_COPY_ASSIGNMENT(ConnectionInfo); + + /** Associative array of string parameters. */ + typedef std::map<InfoType, std::string> StringInfoMap; + + /** Associative array of unsigned integer parameters. */ + typedef std::map<InfoType, unsigned int> UintInfoMap; + + /** Associative array of unsigned short parameters. */ + typedef std::map<InfoType, unsigned short> UshortInfoMap; + + /** String parameters. */ + StringInfoMap strParams; + + /** Integer parameters. */ + UintInfoMap intParams; + + /** Short parameters. */ + UshortInfoMap shortParams; + }; + } + } +} + +#endif //_IGNITE_ODBC_CONFIG_CONNECTION_INFO \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h new file mode 100644 index 0000000..10ceb19 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/connection.h @@ -0,0 +1,281 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_CONNECTION +#define _IGNITE_ODBC_CONNECTION + +#include <stdint.h> + +#include <vector> + +#include "ignite/odbc/parser.h" +#include "ignite/odbc/system/socket_client.h" +#include "ignite/odbc/config/connection_info.h" +#include "ignite/odbc/diagnostic/diagnosable_adapter.h" + +namespace ignite +{ + namespace odbc + { + class Statement; + + /** + * ODBC node connection. + */ + class Connection : public diagnostic::DiagnosableAdapter + { + friend class Environment; + public: + /** ODBC communication protocol version. */ + enum { PROTOCOL_VERSION = 1 }; + + /** + * Apache Ignite version when the current ODBC communication + * protocol version has been introduced. + */ + static const std::string PROTOCOL_VERSION_SINCE; + + /** + * Destructor. + */ + ~Connection(); + + /** + * Get connection info. + * + * @return Connection info. + */ + const config::ConnectionInfo& GetInfo() const; + + /** + * Get info of any type. + * + * @param type Info type. + * @param buf Result buffer pointer. + * @param buflen Result buffer length. + * @param reslen Result value length pointer. + */ + void GetInfo(config::ConnectionInfo::InfoType type, void* buf, short buflen, short* reslen); + + /** + * Establish connection to ODBC server. + * + * @param server Server (DSN). + */ + void Establish(const std::string& server); + + /** + * Establish connection to ODBC server. + * + * @param host Host. + * @param port Port. + * @param cache Cache name to connect to. + */ + void Establish(const std::string& host, uint16_t port, const std::string& cache); + + /** + * Release established connection. + * + * @return Operation result. + */ + void Release(); + + /** + * Create statement associated with the connection. + * + * @return Pointer to valid instance on success and NULL on failure. + */ + Statement* CreateStatement(); + + /** + * Send data by established connection. + * + * @param data Data buffer. + * @param len Data length. + */ + void Send(const int8_t* data, size_t len); + + /** + * Receive next message. + * + * @param msg Buffer for message. + */ + void Receive(std::vector<int8_t>& msg); + + /** + * Get name of the assotiated cache. + * + * @return Cache name. + */ + const std::string& GetCache() const; + + /** + * Create diagnostic record associated with the Connection instance. + * + * @param sqlState SQL state. + * @param message Message. + * @param rowNum Associated row number. + * @param columnNum Associated column number. + * @return DiagnosticRecord associated with the instance. + */ + diagnostic::DiagnosticRecord CreateStatusRecord(SqlState sqlState, + const std::string& message, int32_t rowNum = 0, int32_t columnNum = 0) const; + + /** + * Synchronously send request message and receive response. + * + * @param req Request message. + * @param rsp Response message. + */ + template<typename ReqT, typename RspT> + void SyncMessage(const ReqT& req, RspT& rsp) + { + std::vector<int8_t> tempBuffer; + + parser.Encode(req, tempBuffer); + + Send(tempBuffer.data(), tempBuffer.size()); + + Receive(tempBuffer); + + parser.Decode(rsp, tempBuffer); + } + + /** + * Perform transaction commit. + */ + void TransactionCommit(); + + /** + * Perform transaction rollback. + */ + void TransactionRollback(); + + private: + IGNITE_NO_COPY_ASSIGNMENT(Connection); + + /** + * Establish connection to ODBC server. + * Internal call. + * + * @param server Server (DNS). + * @return Operation result. + */ + SqlResult InternalEstablish(const std::string& server); + + /** + * Establish connection to ODBC server. + * Internal call. + * + * @param host Host. + * @param port Port. + * @param cache Cache name to connect to. + * @return Operation result. + */ + SqlResult InternalEstablish(const std::string& host, uint16_t port, const std::string& cache); + + /** + * Release established connection. + * Internal call. + * + * @return Operation result. + */ + SqlResult InternalRelease(); + + /** + * Get info of any type. + * Internal call. + * + * @param type Info type. + * @param buf Result buffer pointer. + * @param buflen Result buffer length. + * @param reslen Result value length pointer. + * @return Operation result. + */ + SqlResult InternalGetInfo(config::ConnectionInfo::InfoType type, void* buf, short buflen, short* reslen); + + /** + * Create statement associated with the connection. + * Internal call. + * + * @param Pointer to valid instance on success and NULL on failure. + * @return Operation result. + */ + SqlResult InternalCreateStatement(Statement*& statement); + + /** + * Perform transaction commit on all the associated connections. + * Internal call. + * + * @return Operation result. + */ + SqlResult InternalTransactionCommit(); + + /** + * Perform transaction rollback on all the associated connections. + * Internal call. + * + * @return Operation result. + */ + SqlResult InternalTransactionRollback(); + + /** + * Receive specified number of bytes. + * + * @param dst Buffer for data. + * @param len Number of bytes to receive. + * @return Number of successfully received bytes. + */ + size_t ReceiveAll(void* dst, size_t len); + + /** + * Send specified number of bytes. + * + * @param data Data buffer. + * @param len Data length. + * @return Number of successfully sent bytes. + */ + size_t SendAll(const int8_t* data, size_t len); + + /** + * Perform handshake request. + * + * @return Operation result. + */ + SqlResult MakeRequestHandshake(); + + /** + * Constructor. + */ + Connection(); + + /** Socket. */ + tcp::SocketClient socket; + + /** State flag. */ + bool connected; + + /** Cache name. */ + std::string cache; + + /** Message parser. */ + Parser parser; + }; + } +} + +#endif //_IGNITE_ODBC_CONNECTION \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h b/modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h new file mode 100644 index 0000000..fa6de30 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/cursor.h @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_CURSOR +#define _IGNITE_ODBC_CURSOR + +#include <stdint.h> + +#include <map> +#include <memory> + +#include "ignite/odbc/result_page.h" +#include "ignite/odbc/common_types.h" +#include "ignite/odbc/row.h" + +namespace ignite +{ + namespace odbc + { + /** + * Query result cursor. + */ + class Cursor + { + public: + /** + * Constructor. + * @param queryId ID of the executed query. + */ + Cursor(int64_t queryId); + + /** + * Destructor. + */ + ~Cursor(); + + /** + * Move cursor to the next result row. + * + * @return False if data update required or no more data. + */ + bool Increment(); + + /** + * Check if the cursor needs data update. + * + * @return True if the cursor needs data update. + */ + bool NeedDataUpdate() const; + + /** + * Check if the cursor has data. + * + * @return True if the cursor has data. + */ + bool HasData() const; + + /** + * Get query ID. + * + * @return Query ID. + */ + int64_t GetQueryId() const + { + return queryId; + } + + /** + * Update current cursor page data. + * + * @param newPage New result page. + */ + void UpdateData(std::auto_ptr<ResultPage>& newPage); + + /** + * Get current row. + * + * @return Current row. Returns zero if cursor needs data update or has no more data. + */ + Row* GetRow(); + + private: + IGNITE_NO_COPY_ASSIGNMENT(Cursor); + + /** Cursor id. */ + int64_t queryId; + + /** Current page. */ + std::auto_ptr<ResultPage> currentPage; + + /** Row position in current page. */ + int32_t currentPagePos; + + /** Current row. */ + std::auto_ptr<Row> currentRow; + }; + } +} + +#endif //_IGNITE_ODBC_CURSOR http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/decimal.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/decimal.h b/modules/platforms/cpp/odbc/include/ignite/odbc/decimal.h new file mode 100644 index 0000000..8f7932a --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/decimal.h @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_DECIMAL +#define _IGNITE_ODBC_DECIMAL + +#include <stdint.h> + +namespace ignite +{ + + /** + * Big decimal number implementation. + * @todo Move to binary or common library. + */ + class Decimal + { + friend void swap(Decimal& first, Decimal& second); + public: + /** + * Default constructor. + */ + Decimal(); + + /** + * Constructor. + * + * @param scale Scale. + * @param mag Magnitude. Value is copied. + * @param len Magnitude length in bytes. + */ + Decimal(int32_t scale, const int8_t* mag, int32_t len); + + /** + * Copy constructor. + * + * @param other Other instance. + */ + Decimal(const Decimal& other); + + /** + * Destructor. + */ + ~Decimal(); + + /** + * Copy operator. + * + * @param other Other instance. + * @return This. + */ + Decimal& operator=(const Decimal& other); + + /** + * Convert to double. + */ + operator double() const; + + /** + * Get scale. + * + * @return Scale. + */ + int32_t GetScale() const; + + /** + * Get sign. + * + * @return Sign: -1 if negative and 1 if positive. + */ + int32_t GetSign() const; + + /** + * Check if the value is negative. + * + * @return True if negative and false otherwise. + */ + bool IsNegative() const; + + /** + * Get magnitude length in bytes. + * + * @return Magnitude length in bytes. + */ + int32_t GetLength() const; + + /** + * Get number of significant bits of the magnitude. + * + * @return Number of significant bits of the magnitude. + */ + int32_t BitLength() const; + + /** + * Get magnitude pointer. + * + * @return Magnitude pointer. + */ + const int8_t* GetMagnitude() const; + + private: + /** Scale. */ + int32_t scale; + + /** Magnitude lenght. */ + int32_t len; + + /** Magnitude. */ + int8_t* magnitude; + }; + + /** + * Swap function for the Decimal type. + * + * @param first First instance. + * @param second Second instance. + */ + void swap(Decimal& first, Decimal& second); +} + + + +#endif //_IGNITE_ODBC_DECIMAL \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable.h b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable.h new file mode 100644 index 0000000..909fe01 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable.h @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSABLE +#define _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSABLE + +#include "ignite/odbc/diagnostic/diagnostic_record_storage.h" + +namespace ignite +{ + namespace odbc + { + namespace diagnostic + { + /** + * Diagnosable interface. + */ + class Diagnosable + { + public: + /** + * Destructor. + */ + virtual ~Diagnosable() + { + // No-op. + } + + /** + * Get diagnostic record. + * + * @return Diagnostic record. + */ + virtual const diagnostic::DiagnosticRecordStorage& GetDiagnosticRecords() const = 0; + + /** + * Add new status record. + * + * @param sqlState SQL state. + * @param message Message. + * @param rowNum Associated row number. + * @param columnNum Associated column number. + */ + virtual void AddStatusRecord(SqlState sqlState, const std::string& message, + int32_t rowNum, int32_t columnNum) = 0; + + /** + * Add new status record. + * + * @param sqlState SQL state. + * @param message Message. + */ + virtual void AddStatusRecord(SqlState sqlState, const std::string& message) = 0; + + protected: + /** + * Default constructor. + */ + Diagnosable() + { + // No-op. + } + }; + } + } +} + +#endif //_IGNITE_ODBC_DIAGNOSTIC_DIAGNOSABLE \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable_adapter.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable_adapter.h b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable_adapter.h new file mode 100644 index 0000000..63d26ca --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnosable_adapter.h @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSABLE_ADAPTER +#define _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSABLE_ADAPTER + +#include "ignite/odbc/diagnostic/diagnosable.h" + +#define IGNITE_ODBC_API_CALL(...) \ + diagnosticRecords.Reset(); \ + SqlResult result = (__VA_ARGS__); \ + diagnosticRecords.SetHeaderRecord(result) + +#define IGNITE_ODBC_API_CALL_ALWAYS_SUCCESS \ + diagnosticRecords.Reset(); \ + diagnosticRecords.SetHeaderRecord(SQL_RESULT_SUCCESS) + +namespace ignite +{ + namespace odbc + { + class Connection; + + namespace diagnostic + { + /** + * Diagnosable interface. + */ + class DiagnosableAdapter : public Diagnosable + { + public: + /** + * Destructor. + */ + virtual ~DiagnosableAdapter() + { + // No-op. + } + + /** + * Get diagnostic record. + * + * @return Diagnostic record. + */ + virtual const diagnostic::DiagnosticRecordStorage& GetDiagnosticRecords() const + { + return diagnosticRecords; + } + + /** + * Add new status record. + * + * @param sqlState SQL state. + * @param message Message. + * @param rowNum Associated row number. + * @param columnNum Associated column number. + */ + virtual void AddStatusRecord(SqlState sqlState, const std::string& message, + int32_t rowNum, int32_t columnNum); + + /** + * Add new status record. + * + * @param sqlState SQL state. + * @param message Message. + */ + virtual void AddStatusRecord(SqlState sqlState, const std::string& message); + + protected: + /** + * Constructor. + * + * @param connection Pointer to connection. Used to create + * diagnostic records with connection info. + */ + DiagnosableAdapter(const Connection* connection = 0) : + connection(connection) + { + // No-op. + } + + /** Diagnostic records. */ + diagnostic::DiagnosticRecordStorage diagnosticRecords; + + private: + /** Connection. */ + const Connection* connection; + }; + } + } +} + +#endif //_IGNITE_ODBC_DIAGNOSTIC_DIAGNOSABLE_ADAPTER \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h new file mode 100644 index 0000000..bfb4f4c --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record.h @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD +#define _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD + +#include <stdint.h> + +#include <vector> + +#include <ignite/common/common.h> +#include "ignite/odbc/common_types.h" +#include "ignite/odbc/app/application_data_buffer.h" + +namespace ignite +{ + namespace odbc + { + namespace diagnostic + { + /** + * Status diagnostic record. + */ + class DiagnosticRecord + { + public: + /** + * Default constructor. + */ + DiagnosticRecord(); + + /** + * Constructor. + * + * @param sqlState SQL state code. + * @param message Message. + * @param connectionName Connection name. + * @param serverName Server name. + * @param rowNum Associated row number. + * @param columnNum Associated column number. + */ + DiagnosticRecord(SqlState sqlState, const std::string& message, + const std::string& connectionName, const std::string& serverName, + int32_t rowNum = 0, int32_t columnNum = 0); + + /** + * Destructor. + */ + ~DiagnosticRecord(); + + /** + * Get class origin. + * + * @return A string that indicates the document that defines the + * class portion of the SQLSTATE value in this record. + */ + const std::string& GetClassOrigin() const; + + /** + * Get subclass origin. + * + * @return A string with the same format and valid values as origin, + * that identifies the defining portion of the subclass + * portion of the SQLSTATE code. + */ + const std::string& GetSubclassOrigin() const; + + /** + * Get record message text. + * + * @return An informational message on the error or warning. + */ + const std::string& GetMessage() const; + + /** + * Get connection name. + * + * @return A string that indicates the name of the connection that + * the diagnostic record relates to. + */ + const std::string& GetConnectionName() const; + + /** + * Get server name. + * + * @return A string that indicates the server name that the + * diagnostic record relates to. + */ + const std::string& GetServerName() const; + + /** + * Get SQL state of the record. + * + * @return A five-character SQLSTATE diagnostic code. + */ + const std::string& GetSqlState() const; + + /** + * Get row number. + * + * @return The row number in the rowset, or the parameter number in + * the set of parameters, with which the status record is + * associated. + */ + int32_t GetRowNumber() const; + + /** + * Get column number. + * + * @return Contains the value that represents the column number + * in the result set or the parameter number in the set + * of parameters. + */ + int32_t GetColumnNumber() const; + + private: + /** SQL state diagnostic code. */ + SqlState sqlState; + + /** An informational message on the error or warning. */ + std::string message; + + /** + * A string that indicates the name of the connection that + * the diagnostic record relates to. + */ + std::string connectionName; + + /** + * A string that indicates the server name that the + * diagnostic record relates to. + */ + std::string serverName; + + /** + * The row number in the rowset, or the parameter number in the + * set of parameters, with which the status record is associated. + */ + int32_t rowNum; + + /** + * Contains the value that represents the column number in the + * result set or the parameter number in the set of parameters. + */ + int32_t columnNum; + }; + } + } +} + +#endif //_IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record_storage.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record_storage.h b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record_storage.h new file mode 100644 index 0000000..4cc3576 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/diagnostic/diagnostic_record_storage.h @@ -0,0 +1,198 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD_STORAGE +#define _IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD_STORAGE + +#include <stdint.h> + +#include <vector> + +#include <ignite/common/common.h> +#include "ignite/odbc/common_types.h" +#include "ignite/odbc/app/application_data_buffer.h" +#include "ignite/odbc/diagnostic/diagnostic_record.h" + +namespace ignite +{ + namespace odbc + { + namespace diagnostic + { + /** + * Diagnostic record. + * + * Associated with each environment, connection, statement, and + * descriptor handle are diagnostic records. These records contain + * diagnostic information about the last function called that used + * a particular handle. The records are replaced only when another + * function is called using that handle. There is no limit to the + * number of diagnostic records that can be stored at any one time. + * + * This class provides interface for interaction with all handle + * diagnostic records. That means both header and status records. + */ + class DiagnosticRecordStorage + { + public: + /** + * Default constructor. + */ + DiagnosticRecordStorage(); + + /** + * Destructor. + */ + ~DiagnosticRecordStorage(); + + /** + * Set header record values. + * + * @param retCode Operation return code. + */ + void SetHeaderRecord(SqlResult result); + + /** + * Add status record to diagnostic records. + * + * @param record Status record. + */ + void AddStatusRecord(const DiagnosticRecord& record); + + /** + * Reset diagnostic records state. + */ + void Reset(); + + /** + * Get result of the last operation. + * + * @return Result of the last operation. + */ + SqlResult GetOperaionResult() const; + + /** + * Get return code of the last operation. + * + * @return Return code of the last operation. + */ + int GetReturnCode() const; + + /** + * Get row count. + * + * @return Count of rows in cursor. + */ + int64_t GetRowCount() const; + + /** + * Get dynamic function. + * + * @return String that describes the SQL statement + * that the underlying function executed. + */ + const std::string& GetDynamicFunction() const; + + /** + * Get dynamic function code. + * + * @return Numeric code that describes the + * SQL statement that was executed. + */ + int32_t GetDynamicFunctionCode() const; + + /** + * Get number of rows affected. + * + * @return The number of rows affected by an insert, + * delete, or update performed by the last operation. + */ + int32_t GetRowsAffected() const; + + /** + * Get status records number. + * + * @return Number of status records. + */ + int32_t GetStatusRecordsNumber() const; + + /** + * Get specified status record. + * + * @param idx Status record index. + * @return Status record instance reference. + */ + const DiagnosticRecord& GetStatusRecord(int32_t idx) const; + + /** + * Check if the record is in the success state. + * + * @return True if the record is in the success state. + */ + bool IsSuccessful() const; + + /** + * Get value of the field and put it in buffer. + * + * @param recNum Diagnostic record number. + * @param field Record field. + * @param buffer Buffer to put data to. + * @return Operation result. + */ + SqlResult GetField(int32_t recNum, DiagnosticField field, app::ApplicationDataBuffer& buffer) const; + + private: + IGNITE_NO_COPY_ASSIGNMENT(DiagnosticRecordStorage); + + /** + * Header record field. This field contains the count of rows + * in the cursor. + */ + int64_t rowCount; + + /** + * Header record field. String that describes the SQL statement + * that the underlying function executed. + */ + std::string dynamicFunction; + + /** + * Header record field. Numeric code that describes the + * SQL statement that was executed. + */ + int32_t dynamicFunctionCode; + + /** + * Operation result. This field is mapped to "Return code" header + * record field. + */ + SqlResult result; + + /** + * Header record field. The number of rows affected by an insert, + * delete, or update performed by the last operation. + */ + int32_t rowsAffected; + + /** Status records. */ + std::vector<DiagnosticRecord> statusRecords; + }; + } + } +} + +#endif //_IGNITE_ODBC_DIAGNOSTIC_DIAGNOSTIC_RECORD_STORAGE \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/environment.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/environment.h b/modules/platforms/cpp/odbc/include/ignite/odbc/environment.h new file mode 100644 index 0000000..0c8af64 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/environment.h @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_ENVIRONMENT +#define _IGNITE_ODBC_ENVIRONMENT + +#include "ignite/odbc/diagnostic/diagnosable_adapter.h" + +namespace ignite +{ + namespace odbc + { + class Connection; + + /** + * ODBC environment. + */ + class Environment : public diagnostic::DiagnosableAdapter + { + public: + /** + * Constructor. + */ + Environment(); + + /** + * Destructor. + */ + ~Environment(); + + /** + * Create connection associated with the environment. + * + * @return Pointer to valid instance on success or NULL on failure. + */ + Connection* CreateConnection(); + + /** + * Perform transaction commit on all the associated connections. + */ + void TransactionCommit(); + + /** + * Perform transaction rollback on all the associated connections. + */ + void TransactionRollback(); + + /** + * Set attribute. + * + * @param attr Attribute to set. + * @param value Value. + * @param len Value length if the attribute is of string type. + */ + void SetAttribute(int32_t attr, void* value, int32_t len); + + /** + * Get attribute. + * + * @param attr Attribute to set. + * @param buffer Buffer to put value to. + */ + void GetAttribute(int32_t attr, app::ApplicationDataBuffer& buffer); + + private: + IGNITE_NO_COPY_ASSIGNMENT(Environment); + + /** + * Create connection associated with the environment. + * Internal call. + * + * @return Pointer to valid instance on success or NULL on failure. + * @return Operation result. + */ + SqlResult InternalCreateConnection(Connection*& connection); + + /** + * Perform transaction commit on all the associated connections. + * Internal call. + * + * @return Operation result. + */ + SqlResult InternalTransactionCommit(); + + /** + * Perform transaction rollback on all the associated connections. + * Internal call. + * + * @return Operation result. + */ + SqlResult InternalTransactionRollback(); + + /** + * Set attribute. + * Internal call. + * + * @param attr Attribute to set. + * @param value Value. + * @param len Value length if the attribute is of string type. + * @return Operation result. + */ + SqlResult InternalSetAttribute(int32_t attr, void* value, int32_t len); + + /** + * Get attribute. + * Internal call. + * + * @param attr Attribute to set. + * @param buffer Buffer to put value to. + * @return Operation result. + */ + SqlResult InternalGetAttribute(int32_t attr, app::ApplicationDataBuffer& buffer); + + /** ODBC version. */ + int32_t odbcVersion; + + /** ODBC null-termintaion of string behaviour. */ + int32_t odbcNts; + }; + } +} + +#endif //_IGNITE_ODBC_ENVIRONMENT \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/message.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/message.h b/modules/platforms/cpp/odbc/include/ignite/odbc/message.h new file mode 100644 index 0000000..f0b40e2 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/message.h @@ -0,0 +1,751 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_MESSAGE +#define _IGNITE_ODBC_MESSAGE + +#include <stdint.h> +#include <string> + +#include "ignite/impl/binary/binary_writer_impl.h" +#include "ignite/impl/binary/binary_reader_impl.h" + +#include "ignite/odbc/utility.h" +#include "ignite/odbc/result_page.h" +#include "ignite/odbc/meta/column_meta.h" +#include "ignite/odbc/meta/table_meta.h" +#include "ignite/odbc/app/parameter.h" + +namespace ignite +{ + namespace odbc + { + enum RequestType + { + REQUEST_TYPE_HANDSHAKE = 1, + + REQUEST_TYPE_EXECUTE_SQL_QUERY = 2, + + REQUEST_TYPE_FETCH_SQL_QUERY = 3, + + REQUEST_TYPE_CLOSE_SQL_QUERY = 4, + + REQUEST_TYPE_GET_COLUMNS_METADATA = 5, + + REQUEST_TYPE_GET_TABLES_METADATA = 6 + }; + + enum ResponseStatus + { + RESPONSE_STATUS_SUCCESS = 0, + + RESPONSE_STATUS_FAILED = 1 + }; + + /** + * Handshake request. + */ + class HandshakeRequest + { + public: + /** + * Constructor. + * + * @param version Protocol version. + */ + HandshakeRequest(int64_t version) : version(version) + { + // No-op. + } + + /** + * Destructor. + */ + ~HandshakeRequest() + { + // No-op. + } + + /** + * Write request using provided writer. + * @param writer Writer. + */ + void Write(ignite::impl::binary::BinaryWriterImpl& writer) const + { + writer.WriteInt8(REQUEST_TYPE_HANDSHAKE); + + writer.WriteInt64(version); + } + + private: + /** Protocol version. */ + int64_t version; + }; + + /** + * Query execute request. + */ + class QueryExecuteRequest + { + public: + /** + * Constructor. + * + * @param cache Cache name. + * @param sql SQL query. + * @param argsNum Number of arguments. + */ + QueryExecuteRequest(const std::string& cache, const std::string& sql, + const app::ParameterBindingMap& params) : + cache(cache), sql(sql), params(params) + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryExecuteRequest() + { + // No-op. + } + + /** + * Write request using provided writer. + * @param writer Writer. + */ + void Write(ignite::impl::binary::BinaryWriterImpl& writer) const + { + writer.WriteInt8(REQUEST_TYPE_EXECUTE_SQL_QUERY); + utility::WriteString(writer, cache); + utility::WriteString(writer, sql); + + writer.WriteInt32(static_cast<int32_t>(params.size())); + + app::ParameterBindingMap::const_iterator i; + + for (i = params.begin(); i != params.end(); ++i) + i->second.Write(writer); + } + + private: + /** Cache name. */ + std::string cache; + + /** SQL query. */ + std::string sql; + + /** Parameters bindings. */ + const app::ParameterBindingMap& params; + }; + + /** + * Query close request. + */ + class QueryCloseRequest + { + public: + /** + * Constructor. + * + * @param queryId Query ID. + */ + QueryCloseRequest(int64_t queryId) : queryId(queryId) + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryCloseRequest() + { + // No-op. + } + + /** + * Write request using provided writer. + * @param writer Writer. + */ + void Write(ignite::impl::binary::BinaryWriterImpl& writer) const + { + writer.WriteInt8(REQUEST_TYPE_CLOSE_SQL_QUERY); + writer.WriteInt64(queryId); + } + + private: + /** Query ID. */ + int64_t queryId; + }; + + /** + * Query fetch request. + */ + class QueryFetchRequest + { + public: + /** + * Constructor. + * + * @param queryId Query ID. + * @param pageSize Required page size. + */ + QueryFetchRequest(int64_t queryId, int32_t pageSize) : + queryId(queryId), pageSize(pageSize) + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryFetchRequest() + { + // No-op. + } + + /** + * Write request using provided writer. + * @param writer Writer. + */ + void Write(ignite::impl::binary::BinaryWriterImpl& writer) const + { + writer.WriteInt8(REQUEST_TYPE_FETCH_SQL_QUERY); + writer.WriteInt64(queryId); + writer.WriteInt32(pageSize); + } + + private: + /** Query ID. */ + int64_t queryId; + + /** SQL query. */ + int32_t pageSize; + }; + + /** + * Query get columns metadata request. + */ + class QueryGetColumnsMetaRequest + { + public: + /** + * Constructor. + * + * @param schema Schema name. + * @param table Table name. + * @param column Column name. + */ + QueryGetColumnsMetaRequest(const std::string& schema, const std::string& table, const std::string& column) : + schema(schema), table(table), column(column) + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryGetColumnsMetaRequest() + { + // No-op. + } + + /** + * Write request using provided writer. + * @param writer Writer. + */ + void Write(ignite::impl::binary::BinaryWriterImpl& writer) const + { + writer.WriteInt8(REQUEST_TYPE_GET_COLUMNS_METADATA); + + utility::WriteString(writer, schema); + utility::WriteString(writer, table); + utility::WriteString(writer, column); + } + + private: + /** Schema search pattern. */ + std::string schema; + + /** Table search pattern. */ + std::string table; + + /** Column search pattern. */ + std::string column; + }; + + /** + * Query get tables metadata request. + */ + class QueryGetTablesMetaRequest + { + public: + /** + * Constructor. + * + * @param catalog Catalog search pattern. + * @param schema Schema search pattern. + * @param table Table search pattern. + * @param tableTypes Table types search pattern. + */ + QueryGetTablesMetaRequest(const std::string& catalog, const std::string& schema, + const std::string& table, const std::string& tableTypes) : + catalog(catalog), schema(schema), table(table), tableTypes(tableTypes) + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryGetTablesMetaRequest() + { + // No-op. + } + + /** + * Write request using provided writer. + * @param writer Writer. + */ + void Write(ignite::impl::binary::BinaryWriterImpl& writer) const + { + writer.WriteInt8(REQUEST_TYPE_GET_TABLES_METADATA); + + utility::WriteString(writer, catalog); + utility::WriteString(writer, schema); + utility::WriteString(writer, table); + utility::WriteString(writer, tableTypes); + } + + private: + /** Column search pattern. */ + std::string catalog; + + /** Schema search pattern. */ + std::string schema; + + /** Table search pattern. */ + std::string table; + + /** Column search pattern. */ + std::string tableTypes; + }; + + /** + * Query close response. + */ + class QueryResponse + { + public: + /** + * Constructor. + */ + QueryResponse() : status(RESPONSE_STATUS_FAILED), error() + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryResponse() + { + // No-op. + } + + /** + * Read response using provided reader. + * @param reader Reader. + */ + void Read(ignite::impl::binary::BinaryReaderImpl& reader) + { + status = reader.ReadInt8(); + + if (status == RESPONSE_STATUS_SUCCESS) + { + ReadOnSuccess(reader); + } + else + { + int32_t errorLen = reader.ReadString(0, 0); + error.resize(errorLen); + + reader.ReadString(&error[0], static_cast<int32_t>(error.size())); + } + } + + /** + * Get request processing status. + * @return Status. + */ + int8_t GetStatus() const + { + return status; + } + + /** + * Get resulting error. + * @return Error. + */ + const std::string& GetError() const + { + return error; + } + + protected: + /** + * Read data if response status is RESPONSE_STATUS_SUCCESS. + */ + virtual void ReadOnSuccess(ignite::impl::binary::BinaryReaderImpl&) + { + // No-op. + } + + private: + /** Request processing status. */ + int8_t status; + + /** Error message. */ + std::string error; + }; + + /** + * Handshake response. + */ + class HandshakeResponse : public QueryResponse + { + public: + /** + * Constructor. + */ + HandshakeResponse() : + accepted(false), + protoVerSince(), + currentVer() + { + // No-op. + } + + /** + * Destructor. + */ + ~HandshakeResponse() + { + // No-op. + } + + /** + * Check if the handshake has been accepted. + * @return True if the handshake has been accepted. + */ + bool IsAccepted() const + { + return accepted; + } + + /** + * Get host Apache Ignite version when protocol version has been introduced. + * @return Host Apache Ignite version when protocol version has been introduced. + */ + const std::string& ProtoVerSince() const + { + return protoVerSince; + } + + /** + * Current host Apache Ignite version. + * @return Current host Apache Ignite version. + */ + const std::string& CurrentVer() const + { + return currentVer; + } + + private: + /** + * Read response using provided reader. + * @param reader Reader. + */ + virtual void ReadOnSuccess(ignite::impl::binary::BinaryReaderImpl& reader) + { + accepted = reader.ReadBool(); + + if (!accepted) + { + utility::ReadString(reader, protoVerSince); + utility::ReadString(reader, currentVer); + } + } + + /** Handshake accepted. */ + bool accepted; + + /** Host Apache Ignite version when protocol version has been introduced. */ + std::string protoVerSince; + + /** Current host Apache Ignite version. */ + std::string currentVer; + }; + + /** + * Query close response. + */ + class QueryCloseResponse : public QueryResponse + { + public: + /** + * Constructor. + */ + QueryCloseResponse() : queryId(0) + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryCloseResponse() + { + // No-op. + } + + /** + * Get query ID. + * @return Query ID. + */ + int64_t GetQueryId() const + { + return queryId; + } + + private: + /** + * Read response using provided reader. + * @param reader Reader. + */ + virtual void ReadOnSuccess(ignite::impl::binary::BinaryReaderImpl& reader) + { + queryId = reader.ReadInt64(); + } + + /** Query ID. */ + int64_t queryId; + }; + + /** + * Query execute response. + */ + class QueryExecuteResponse : public QueryResponse + { + public: + /** + * Constructor. + */ + QueryExecuteResponse() : queryId(0), meta() + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryExecuteResponse() + { + // No-op. + } + + /** + * Get query ID. + * @return Query ID. + */ + int64_t GetQueryId() const + { + return queryId; + } + + /** + * Get column metadata. + * @return Column metadata. + */ + const meta::ColumnMetaVector& GetMeta() const + { + return meta; + } + + private: + /** + * Read response using provided reader. + * @param reader Reader. + */ + virtual void ReadOnSuccess(ignite::impl::binary::BinaryReaderImpl& reader) + { + queryId = reader.ReadInt64(); + + meta::ReadColumnMetaVector(reader, meta); + } + + /** Query ID. */ + int64_t queryId; + + /** Columns metadata. */ + meta::ColumnMetaVector meta; + }; + + /** + * Query fetch response. + */ + class QueryFetchResponse : public QueryResponse + { + public: + /** + * Constructor. + * @param resultPage Result page. + */ + QueryFetchResponse(ResultPage& resultPage) : queryId(0), resultPage(resultPage) + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryFetchResponse() + { + // No-op. + } + + /** + * Get query ID. + * @return Query ID. + */ + int64_t GetQueryId() const + { + return queryId; + } + + private: + /** + * Read response using provided reader. + * @param reader Reader. + */ + virtual void ReadOnSuccess(ignite::impl::binary::BinaryReaderImpl& reader) + { + queryId = reader.ReadInt64(); + + resultPage.Read(reader); + } + + /** Query ID. */ + int64_t queryId; + + /** Result page. */ + ResultPage& resultPage; + }; + + /** + * Query get column metadata response. + */ + class QueryGetColumnsMetaResponse : public QueryResponse + { + public: + /** + * Constructor. + */ + QueryGetColumnsMetaResponse() + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryGetColumnsMetaResponse() + { + // No-op. + } + + /** + * Get column metadata. + * @return Column metadata. + */ + const meta::ColumnMetaVector& GetMeta() const + { + return meta; + } + + private: + /** + * Read response using provided reader. + * @param reader Reader. + */ + virtual void ReadOnSuccess(ignite::impl::binary::BinaryReaderImpl& reader) + { + meta::ReadColumnMetaVector(reader, meta); + } + + /** Columns metadata. */ + meta::ColumnMetaVector meta; + }; + + /** + * Query get table metadata response. + */ + class QueryGetTablesMetaResponse : public QueryResponse + { + public: + /** + * Constructor. + */ + QueryGetTablesMetaResponse() + { + // No-op. + } + + /** + * Destructor. + */ + ~QueryGetTablesMetaResponse() + { + // No-op. + } + + /** + * Get column metadata. + * @return Column metadata. + */ + const meta::TableMetaVector& GetMeta() const + { + return meta; + } + + private: + /** + * Read response using provided reader. + * @param reader Reader. + */ + virtual void ReadOnSuccess(ignite::impl::binary::BinaryReaderImpl& reader) + { + meta::ReadTableMetaVector(reader, meta); + } + + /** Columns metadata. */ + meta::TableMetaVector meta; + }; + } +} + +#endif //_IGNITE_ODBC_MESSAGE \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/764c97b9/modules/platforms/cpp/odbc/include/ignite/odbc/meta/column_meta.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc/include/ignite/odbc/meta/column_meta.h b/modules/platforms/cpp/odbc/include/ignite/odbc/meta/column_meta.h new file mode 100644 index 0000000..5ffff03 --- /dev/null +++ b/modules/platforms/cpp/odbc/include/ignite/odbc/meta/column_meta.h @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_ODBC_META_COLUMN_META +#define _IGNITE_ODBC_META_COLUMN_META + +#include <stdint.h> +#include <string> + +#include "ignite/impl/binary/binary_reader_impl.h" + +#include "ignite/odbc/common_types.h" +#include "ignite/odbc/utility.h" + +namespace ignite +{ + namespace odbc + { + namespace meta + { + /** + * Column metadata. + */ + class ColumnMeta + { + public: +#ifdef ODBC_DEBUG + /** + * Convert attribute ID to string containing its name. + * Debug function. + * @param type Attribute ID. + * @return Null-terminated string containing attribute name. + */ + static const char* AttrIdToString(uint16_t id); +#endif + + /** + * Default constructor. + */ + ColumnMeta() + { + // No-op. + } + + /** + * Constructor. + * + * @param schemaName Schema name. + * @param tableName Table name. + * @param columnName Column name. + * @param typeName Type name. + * @param dataType Data type. + */ + ColumnMeta(const std::string& schemaName, const std::string& tableName, + const std::string& columnName, int8_t dataType) : + schemaName(schemaName), tableName(tableName), columnName(columnName), dataType(dataType) + { + // No-op. + } + + /** + * Destructor. + */ + ~ColumnMeta() + { + // No-op. + } + + /** + * Copy constructor. + */ + ColumnMeta(const ColumnMeta& other) : + schemaName(other.schemaName), + tableName(other.tableName), + columnName(other.columnName), + dataType(other.dataType) + { + // No-op. + } + + /** + * Copy operator. + */ + ColumnMeta& operator=(const ColumnMeta& other) + { + schemaName = other.schemaName; + tableName = other.tableName; + columnName = other.columnName; + dataType = other.dataType; + + return *this; + } + + /** + * Read using reader. + * @param reader Reader. + */ + void Read(ignite::impl::binary::BinaryReaderImpl& reader); + + /** + * Get schema name. + * @return Schema name. + */ + const std::string& GetSchemaName() const + { + return schemaName; + } + + /** + * Get table name. + * @return Table name. + */ + const std::string& GetTableName() const + { + return tableName; + } + + /** + * Get column name. + * @return Column name. + */ + const std::string& GetColumnName() const + { + return columnName; + } + + /** + * Get data type. + * @return Data type. + */ + int8_t GetDataType() const + { + return dataType; + } + + /** + * Try to get attribute of a string type. + * + * @param fieldId Field ID. + * @param value Output attribute value. + * @return True if the attribute supported and false otherwise. + */ + bool GetAttribute(uint16_t fieldId, std::string& value) const; + + /** + * Try to get attribute of a integer type. + * + * @param fieldId Field ID. + * @param value Output attribute value. + * @return True if the attribute supported and false otherwise. + */ + bool GetAttribute(uint16_t fieldId, SqlLen& value) const; + + private: + /** Schema name. */ + std::string schemaName; + + /** Table name. */ + std::string tableName; + + /** Column name. */ + std::string columnName; + + /** Data type. */ + int8_t dataType; + }; + + /** Column metadata vector alias. */ + typedef std::vector<ColumnMeta> ColumnMetaVector; + + /** + * Read columns metadata collection. + * @param reader Reader. + * @param meta Collection. + */ + void ReadColumnMetaVector(ignite::impl::binary::BinaryReaderImpl& reader, ColumnMetaVector& meta); + } + } +} + +#endif //_IGNITE_ODBC_META_COLUMN_META \ No newline at end of file
