1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #ifndef TENSORFLOW_CORE_KERNELS_DATA_EXPERIMENTAL_SQL_SQLITE_QUERY_CONNECTION_H_ 16 #define TENSORFLOW_CORE_KERNELS_DATA_EXPERIMENTAL_SQL_SQLITE_QUERY_CONNECTION_H_ 17 18 #include <memory> 19 20 #include "tensorflow/core/kernels/data/experimental/sql/query_connection.h" 21 #include "tensorflow/core/lib/db/sqlite.h" 22 #include "tensorflow/core/platform/types.h" 23 24 namespace tensorflow { 25 namespace data { 26 namespace experimental { 27 namespace sql { 28 29 class SqliteQueryConnection : public QueryConnection { 30 public: 31 SqliteQueryConnection(); 32 ~SqliteQueryConnection() override; 33 Status Open(const string& data_source_name, const string& query, 34 const DataTypeVector& output_types) override; 35 Status Close() override; 36 Status GetNext(IteratorContext* ctx, std::vector<Tensor>* out_tensors, 37 bool* end_of_sequence) override; 38 39 private: 40 // Prepares the query string `query_`. 41 Status PrepareQuery(); 42 // Fills `tensor` with the column_index_th element of the current row of 43 // `stmt_`. 44 void FillTensorWithResultSetEntry(const DataType& data_type, int column_index, 45 Tensor* tensor); 46 Sqlite* db_ = nullptr; 47 SqliteStatement stmt_; 48 int column_count_ = 0; 49 string query_; 50 DataTypeVector output_types_; 51 }; 52 53 } // namespace sql 54 } // namespace experimental 55 } // namespace data 56 } // namespace tensorflow 57 58 #endif // TENSORFLOW_CORE_KERNELS_DATA_EXPERIMENTAL_SQL_SQLITE_QUERY_CONNECTION_H_ 59