| 245 | } |
| 246 | |
| 247 | Status SaveNodeInputs() { |
| 248 | const char* sql = R"sql( |
| 249 | INSERT INTO NodeInputs ( |
| 250 | graph_id, |
| 251 | node_id, |
| 252 | idx, |
| 253 | input_node_id, |
| 254 | input_node_idx, |
| 255 | is_control |
| 256 | ) VALUES (?, ?, ?, ?, ?, ?) |
| 257 | )sql"; |
| 258 | SqliteStatement insert; |
| 259 | TF_RETURN_IF_ERROR(db_->Prepare(sql, &insert)); |
| 260 | for (int node_id = 0; node_id < graph_->node_size(); ++node_id) { |
| 261 | const NodeDef& node = graph_->node(node_id); |
| 262 | for (int idx = 0; idx < node.input_size(); ++idx) { |
| 263 | StringPiece name = node.input(idx); |
| 264 | int64 input_node_id; |
| 265 | int64 input_node_idx = 0; |
| 266 | int64 is_control = 0; |
| 267 | size_t i = name.rfind(':'); |
| 268 | if (i != StringPiece::npos) { |
| 269 | if (!strings::safe_strto64(name.substr(i + 1, name.size() - i - 1), |
| 270 | &input_node_idx)) { |
| 271 | return errors::DataLoss("Bad NodeDef.input: ", name); |
| 272 | } |
| 273 | name.remove_suffix(name.size() - i); |
| 274 | } |
| 275 | if (!name.empty() && name[0] == '^') { |
| 276 | name.remove_prefix(1); |
| 277 | is_control = 1; |
| 278 | } |
| 279 | auto e = name_to_node_id_.find(name); |
| 280 | if (e == name_to_node_id_.end()) { |
| 281 | return errors::DataLoss("Could not find node: ", name); |
| 282 | } |
| 283 | input_node_id = e->second; |
| 284 | insert.BindInt(1, graph_id_); |
| 285 | insert.BindInt(2, node_id); |
| 286 | insert.BindInt(3, idx); |
| 287 | insert.BindInt(4, input_node_id); |
| 288 | insert.BindInt(5, input_node_idx); |
| 289 | insert.BindInt(6, is_control); |
| 290 | unflushed_bytes_ += insert.size(); |
| 291 | TF_RETURN_WITH_CONTEXT_IF_ERROR(insert.StepAndReset(), node.name(), |
| 292 | " -> ", name); |
| 293 | TF_RETURN_IF_ERROR(MaybeFlush()); |
| 294 | } |
| 295 | } |
| 296 | return Status::OK(); |
| 297 | } |
| 298 | |
| 299 | Status SaveNodes() { |
| 300 | const char* sql = R"sql( |
no test coverage detected