MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / onTrigger

Method onTrigger

extensions/sqlite/ExecuteSQL.cpp:69–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69void ExecuteSQL::onTrigger(const std::shared_ptr<core::ProcessContext> &context,
70 const std::shared_ptr<core::ProcessSession> &session) {
71 auto flow_file = session->get();
72
73 try {
74 // Use an existing context, if one is available
75 std::shared_ptr<minifi::sqlite::SQLiteConnection> db;
76
77 if (conn_q_.try_dequeue(db)) {
78 logger_->log_debug("Using available SQLite connection");
79 }
80
81 if (!db) {
82 logger_->log_info("Creating new SQLite connection");
83 if (db_url_.substr(0, 9) == "sqlite://") {
84 db = std::make_shared<minifi::sqlite::SQLiteConnection>(db_url_.substr(9));
85 } else {
86 std::stringstream err_msg;
87 err_msg << "Connection URL '" << db_url_ << "' is unsupported";
88 logger_->log_error(err_msg.str().c_str());
89 throw std::runtime_error("Connection Error");
90 }
91 }
92
93 auto dynamic_sql = std::make_shared<std::string>();
94
95 if (flow_file) {
96 if (sql_.empty()) {
97 // SQL is not defined as a property, so get SQL from the file content
98 SQLReadCallback cb(dynamic_sql);
99 session->read(flow_file, &cb);
100 } else {
101 // SQL is defined as a property, so get the property dynamically w/ EL support
102 context->getProperty(SQLStatement, *dynamic_sql, flow_file);
103 }
104 }
105
106 auto stmt = flow_file
107 ? db->prepare(*dynamic_sql)
108 : db->prepare(sql_);
109
110 if (flow_file) {
111 for (int i = 1; i < INT_MAX; i++) {
112 std::string val;
113 std::stringstream val_key;
114 val_key << "sql.args." << i << ".value";
115
116 if (!flow_file->getAttribute(val_key.str(), val)) {
117 break;
118 }
119
120 stmt.bind_text(i, val);
121 }
122 }
123
124 stmt.step();
125
126 if (!stmt.is_ok()) {

Callers

nothing calls this directly

Calls 15

log_debugMethod · 0.80
log_infoMethod · 0.80
log_errorMethod · 0.80
c_strMethod · 0.80
prepareMethod · 0.80
bind_textMethod · 0.80
stepMethod · 0.80
is_okMethod · 0.80
errormsgMethod · 0.80
column_countMethod · 0.80
column_nameMethod · 0.80
is_doneMethod · 0.80

Tested by

no test coverage detected