You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/12/07 06:09:14 UTC

[GitHub] [incubator-doris] yangzhg commented on a change in pull request #5033: [ODBC] Support ODBC Sink for insert into data to ODBC external table

yangzhg commented on a change in pull request #5033:
URL: https://github.com/apache/incubator-doris/pull/5033#discussion_r537253665



##########
File path: be/src/exec/odbc_connecter.cpp
##########
@@ -172,7 +180,175 @@ Status ODBCScanner::get_next_row(bool* eos) {
     return Status::OK();
 }
 
-Status ODBCScanner::error_status(const std::string& prefix, const std::string& error_msg) {
+Status ODBCConnecter::init_to_write() {
+    if (!_is_open) {
+        return Status::InternalError( "Init before open.");
+    }
+
+    // Allocate a statement handle
+    ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, SQLAllocHandle(SQL_HANDLE_STMT, _dbc, &_stmt), "alloc statement");
+
+    return Status::OK();
+}
+
+Status ODBCConnecter::append(const std::string& table_name, RowBatch *batch) {
+    if (batch == nullptr || batch->num_rows() == 0) {
+        return Status::OK();
+    }
+
+    int num_rows = batch->num_rows();
+    for (int i = 0; i < num_rows; ++i) {
+        RETURN_IF_ERROR(insert_row(table_name, batch->get_row(i)));
+    }
+
+    return Status::OK();
+}
+
+Status ODBCConnecter::insert_row(const std::string& table_name, TupleRow *row) {
+    std::stringstream ss;
+
+    // Construct Insert statement of mysql
+    ss << "INSERT INTO " << table_name << " VALUES (";

Review comment:
       if use mysql statement,  table name better to surrounded by ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org