Beispiel #1
0
        SqlResult Connection::InternalTransactionRollback()
        {
            AddStatusRecord(SQL_STATE_HYC00_OPTIONAL_FEATURE_NOT_IMPLEMENTED,
                "Rollback operation is not supported.");

            return SQL_RESULT_ERROR;
        }
Beispiel #2
0
        SqlResult Environment::InternalGetAttribute(int32_t attr, app::ApplicationDataBuffer& buffer)
        {
            EnvironmentAttribute attribute = EnvironmentAttributeToInternal(attr);

            switch (attribute)
            {
                case IGNITE_SQL_ENV_ATTR_ODBC_VERSION:
                {
                    buffer.PutInt32(odbcVersion);

                    return SQL_RESULT_SUCCESS;
                }

                case IGNITE_SQL_ENV_ATTR_OUTPUT_NTS:
                {
                    buffer.PutInt32(odbcNts);

                    return SQL_RESULT_SUCCESS;
                }

                case IGNITE_SQL_ENV_ATTR_UNKNOWN:
                default:
                    break;
            }

            AddStatusRecord(SQL_STATE_HYC00_OPTIONAL_FEATURE_NOT_IMPLEMENTED,
                "Attribute is not supported.");

            return SQL_RESULT_ERROR;
        }
Beispiel #3
0
        SqlResult Connection::MakeRequestHandshake()
        {
            HandshakeRequest req(PROTOCOL_VERSION);
            HandshakeResponse rsp;

            try
            {
                SyncMessage(req, rsp);
            }
            catch (const IgniteError& err)
            {
                AddStatusRecord(SQL_STATE_HYT01_CONNECTIOIN_TIMEOUT, err.GetText());

                return SQL_RESULT_ERROR;
            }

            if (rsp.GetStatus() != RESPONSE_STATUS_SUCCESS)
            {
                LOG_MSG("Error: %s\n", rsp.GetError().c_str());

                AddStatusRecord(SQL_STATE_08001_CANNOT_CONNECT, rsp.GetError());

                InternalRelease();

                return SQL_RESULT_ERROR;
            }

            if (!rsp.IsAccepted())
            {
                LOG_MSG("Hanshake message has been rejected.\n");

                std::stringstream constructor;

                constructor << "Node rejected handshake message. "
                    << "Current node Apache Ignite version: " << rsp.CurrentVer() << ", "
                    << "node protocol version introduced in version: " << rsp.ProtoVerSince() << ", "
                    << "driver protocol version introduced in version: " << PROTOCOL_VERSION_SINCE << ".";

                AddStatusRecord(SQL_STATE_08001_CANNOT_CONNECT, constructor.str());

                InternalRelease();

                return SQL_RESULT_ERROR;
            }

            return SQL_RESULT_SUCCESS;
        }
Beispiel #4
0
        SqlResult Environment::InternalSetAttribute(int32_t attr, void* value, int32_t len)
        {
            EnvironmentAttribute attribute = EnvironmentAttributeToInternal(attr);

            switch (attribute)
            {
                case IGNITE_SQL_ENV_ATTR_ODBC_VERSION:
                {
                    int32_t version = static_cast<int32_t>(reinterpret_cast<intptr_t>(value));

                    if (version != odbcVersion)
                    {
                        AddStatusRecord(SQL_STATE_01S02_OPTION_VALUE_CHANGED,
                            "ODBC version is not supported.");

                        return SQL_RESULT_SUCCESS_WITH_INFO;
                    }

                    return SQL_RESULT_SUCCESS;
                }

                case IGNITE_SQL_ENV_ATTR_OUTPUT_NTS:
                {
                    int32_t nts = static_cast<int32_t>(reinterpret_cast<intptr_t>(value));

                    if (nts != odbcNts)
                    {
                        AddStatusRecord(SQL_STATE_01S02_OPTION_VALUE_CHANGED,
                            "Only null-termination of strings is supported.");

                        return SQL_RESULT_SUCCESS_WITH_INFO;
                    }

                    return SQL_RESULT_SUCCESS;
                }

                case IGNITE_SQL_ENV_ATTR_UNKNOWN:
                default:
                    break;
            }

            AddStatusRecord(SQL_STATE_HYC00_OPTIONAL_FEATURE_NOT_IMPLEMENTED,
                "Attribute is not supported.");

            return SQL_RESULT_ERROR;
        }
Beispiel #5
0
        SqlResult Connection::InternalGetInfo(config::ConnectionInfo::InfoType type, void* buf, short buflen, short* reslen)
        {
            const config::ConnectionInfo& info = GetInfo();

            SqlResult res = info.GetInfo(type, buf, buflen, reslen);

            if (res != SQL_RESULT_SUCCESS)
                AddStatusRecord(SQL_STATE_HYC00_OPTIONAL_FEATURE_NOT_IMPLEMENTED, "Not implemented.");

            return res;
        }
Beispiel #6
0
        SqlResult Connection::InternalCreateStatement(Statement*& statement)
        {
            statement = new Statement(*this);

            if (!statement)
            {
                AddStatusRecord(SQL_STATE_HY001_MEMORY_ALLOCATION, "Not enough memory.");

                return SQL_RESULT_ERROR;
            }

            return SQL_RESULT_SUCCESS;
        }
Beispiel #7
0
        SqlResult Connection::InternalEstablish(const config::Configuration cfg)
        {
            config = cfg;

            if (connected)
            {
                AddStatusRecord(SQL_STATE_08002_ALREADY_CONNECTED, "Already connected.");

                return SQL_RESULT_ERROR;
            }

            connected = socket.Connect(cfg.GetHost().c_str(), cfg.GetTcpPort());

            if (!connected)
            {
                AddStatusRecord(SQL_STATE_08001_CANNOT_CONNECT, "Failed to establish connection with the host.");

                return SQL_RESULT_ERROR;
            }

            return MakeRequestHandshake();
        }
Beispiel #8
0
        SqlResult Environment::InternalCreateConnection(Connection*& connection)
        {
            connection = new Connection;

            if (!connection)
            {
                AddStatusRecord(SQL_STATE_HY001_MEMORY_ALLOCATION, "Not enough memory.");

                return SQL_RESULT_ERROR;
            }

            return SQL_RESULT_SUCCESS;
        }
Beispiel #9
0
        SqlResult Connection::InternalEstablish(const std::string& server)
        {
            config::Configuration config;

            if (server != config.GetDsn())
            {
                AddStatusRecord(SQL_STATE_HY000_GENERAL_ERROR, "Unknown server.");

                return SQL_RESULT_ERROR;
            }

            return InternalEstablish(config.GetHost(), config.GetPort(), config.GetCache());
        }
Beispiel #10
0
        SqlResult Connection::InternalEstablish(const std::string & host, uint16_t port, const std::string & cache)
        {
            if (connected)
            {
                AddStatusRecord(SQL_STATE_08002_ALREADY_CONNECTED, "Already connected.");

                return SQL_RESULT_ERROR;
            }

            this->cache = cache;

            connected = socket.Connect(host.c_str(), port);

            if (!connected)
            {
                AddStatusRecord(SQL_STATE_08001_CANNOT_CONNECT, "Failed to establish connection with the host.");

                return SQL_RESULT_ERROR;
            }

            return MakeRequestHandshake();
        }
Beispiel #11
0
        SqlResult Connection::InternalRelease()
        {
            if (!connected)
            {
                AddStatusRecord(SQL_STATE_08003_NOT_CONNECTED, "Connection is not open.");

                return SQL_RESULT_ERROR;
            }

            socket.Close();

            connected = false;

            return SQL_RESULT_SUCCESS;
        }
Beispiel #12
0
        SqlResult Connection::InternalEstablish(const std::string& connectStr)
        {
            config::Configuration config;

            try
            {
                config.FillFromConnectString(connectStr);
            }
            catch (IgniteError& e)
            {
                AddStatusRecord(SQL_STATE_HY000_GENERAL_ERROR, e.GetText());

                return SQL_RESULT_ERROR;
            }

            return InternalEstablish(config);
        }
            void DiagnosableAdapter::AddStatusRecord(const OdbcError& err)
            {
                LOG_MSG("Adding new record: " << err.GetErrorMessage());

                AddStatusRecord(err.GetStatus(), err.GetErrorMessage(), 0, 0);
            }
            void DiagnosableAdapter::AddStatusRecord(SqlState::Type  sqlState, const std::string& message)
            {
                LOG_MSG("Adding new record: " << message);

                AddStatusRecord(sqlState, message, 0, 0);
            }
Beispiel #15
0
        SqlResult Connection::MakeRequestHandshake()
        {
            bool distributedJoins = false;
            bool enforceJoinOrder = false;
            int64_t protocolVersion = 0;

            try
            {
                distributedJoins = config.IsDistributedJoins();
                enforceJoinOrder = config.IsEnforceJoinOrder();
                protocolVersion = config.GetProtocolVersion().GetIntValue();
            }
            catch (const IgniteError& err)
            {
                AddStatusRecord(SQL_STATE_01S00_INVALID_CONNECTION_STRING_ATTRIBUTE, err.GetText());

                return SQL_RESULT_ERROR;
            }

            HandshakeRequest req(protocolVersion, distributedJoins, enforceJoinOrder);
            HandshakeResponse rsp;

            try
            {
                SyncMessage(req, rsp);
            }
            catch (const IgniteError& err)
            {
                AddStatusRecord(SQL_STATE_HYT01_CONNECTIOIN_TIMEOUT, err.GetText());

                return SQL_RESULT_ERROR;
            }

            if (rsp.GetStatus() != RESPONSE_STATUS_SUCCESS)
            {
                LOG_MSG("Error: %s\n", rsp.GetError().c_str());

                AddStatusRecord(SQL_STATE_08001_CANNOT_CONNECT, rsp.GetError());

                InternalRelease();

                return SQL_RESULT_ERROR;
            }

            if (!rsp.IsAccepted())
            {
                LOG_MSG("Hanshake message has been rejected.\n");

                std::stringstream constructor;

                constructor << "Node rejected handshake message. "
                    << "Current node Apache Ignite version: " << rsp.CurrentVer() << ", "
                    << "node protocol version introduced in version: " << rsp.ProtoVerSince() << ", "
                    << "driver protocol version introduced in version: " << config.GetProtocolVersion().ToString() << ".";

                AddStatusRecord(SQL_STATE_08001_CANNOT_CONNECT, constructor.str());

                InternalRelease();

                return SQL_RESULT_ERROR;
            }

            return SQL_RESULT_SUCCESS;
        }