| 70 | } |
| 71 | |
| 72 | void PostgreSQLHandler::run() |
| 73 | { |
| 74 | setThreadName("PostgresHandler"); |
| 75 | ThreadStatus thread_status; |
| 76 | connection_context->makeSessionContext(); |
| 77 | connection_context->getClientInfo().interface = ClientInfo::Interface::POSTGRESQL; |
| 78 | connection_context->setDefaultFormat("PostgreSQLWire"); |
| 79 | |
| 80 | try |
| 81 | { |
| 82 | if (!startup()) |
| 83 | return; |
| 84 | |
| 85 | while (true) |
| 86 | { |
| 87 | message_transport->send(PostgreSQLProtocol::Messaging::ReadyForQuery(), true); |
| 88 | PostgreSQLProtocol::Messaging::FrontMessageType message_type = message_transport->receiveMessageType(); |
| 89 | |
| 90 | switch (message_type) |
| 91 | { |
| 92 | case PostgreSQLProtocol::Messaging::FrontMessageType::QUERY: |
| 93 | processQuery(); |
| 94 | break; |
| 95 | case PostgreSQLProtocol::Messaging::FrontMessageType::TERMINATE: |
| 96 | LOG_DEBUG(log, "Client closed the connection"); |
| 97 | return; |
| 98 | case PostgreSQLProtocol::Messaging::FrontMessageType::PARSE: |
| 99 | case PostgreSQLProtocol::Messaging::FrontMessageType::BIND: |
| 100 | case PostgreSQLProtocol::Messaging::FrontMessageType::DESCRIBE: |
| 101 | case PostgreSQLProtocol::Messaging::FrontMessageType::SYNC: |
| 102 | case PostgreSQLProtocol::Messaging::FrontMessageType::FLUSH: |
| 103 | case PostgreSQLProtocol::Messaging::FrontMessageType::CLOSE: |
| 104 | message_transport->send( |
| 105 | PostgreSQLProtocol::Messaging::ErrorOrNoticeResponse( |
| 106 | PostgreSQLProtocol::Messaging::ErrorOrNoticeResponse::ERROR, |
| 107 | "0A000", |
| 108 | "ClickHouse doesn't support extended query mechanism"), |
| 109 | true); |
| 110 | LOG_ERROR(log, "Client tried to access via extended query protocol"); |
| 111 | message_transport->dropMessage(); |
| 112 | break; |
| 113 | default: |
| 114 | message_transport->send( |
| 115 | PostgreSQLProtocol::Messaging::ErrorOrNoticeResponse( |
| 116 | PostgreSQLProtocol::Messaging::ErrorOrNoticeResponse::ERROR, |
| 117 | "0A000", |
| 118 | "Command is not supported"), |
| 119 | true); |
| 120 | LOG_ERROR(log, Poco::format("Command is not supported. Command code %d", static_cast<Int32>(message_type))); |
| 121 | message_transport->dropMessage(); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | catch (const Poco::Exception &exc) |
| 126 | { |
| 127 | log->log(exc); |
| 128 | } |
| 129 |
nothing calls this directly
no test coverage detected