MCPcopy Create free account
hub / github.com/apache/arrow / Create

Method Create

cpp/src/arrow/flight/sql/example/sqlite_server.cc:777–829  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

775 : impl_(std::move(impl)) {}
776
777arrow::Result<std::shared_ptr<SQLiteFlightSqlServer>> SQLiteFlightSqlServer::Create() {
778 sqlite3* db = nullptr;
779
780 // All sqlite3* instances created from this URI will share data
781 std::string uri = "file:memorydb";
782 uri += std::to_string(kDbCounter++);
783 uri += "?mode=memory&cache=shared";
784 if (sqlite3_open_v2(uri.c_str(), &db,
785 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI,
786 /*zVfs=*/nullptr)) {
787 std::string err_msg = "Can't open database: ";
788 if (db != nullptr) {
789 err_msg += sqlite3_errmsg(db);
790 sqlite3_close(db);
791 } else {
792 err_msg += "Unable to start SQLite. Insufficient memory";
793 }
794
795 return Status::Invalid(err_msg);
796 }
797
798 std::shared_ptr<Impl> impl = std::make_shared<Impl>(db, std::move(uri));
799
800 std::shared_ptr<SQLiteFlightSqlServer> result(
801 new SQLiteFlightSqlServer(std::move(impl)));
802 for (const auto& id_to_result : GetSqlInfoResultMap()) {
803 result->RegisterSqlInfo(id_to_result.first, id_to_result.second);
804 }
805
806 ARROW_RETURN_NOT_OK(result->ExecuteSql(R"(
807 CREATE TABLE foreignTable (
808 id INTEGER PRIMARY KEY AUTOINCREMENT,
809 foreignName varchar(100),
810 value int);
811
812 CREATE TABLE intTable (
813 id INTEGER PRIMARY KEY AUTOINCREMENT,
814 keyName varchar(100),
815 value int,
816 foreignId int references foreignTable(id));
817
818 INSERT INTO foreignTable (foreignName, value) VALUES ('keyOne', 1);
819 INSERT INTO foreignTable (foreignName, value) VALUES ('keyTwo', 0);
820 INSERT INTO foreignTable (foreignName, value) VALUES ('keyThree', -1);
821 INSERT INTO intTable (keyName, value, foreignId) VALUES ('one', 1, 1);
822 INSERT INTO intTable (keyName, value, foreignId) VALUES ('zero', 0, 1);
823 INSERT INTO intTable (keyName, value, foreignId) VALUES ('negative one', -1, 1);
824 INSERT INTO intTable (keyName, value, foreignId) VALUES (NULL, NULL, NULL);
825 INSERT INTO intTable (keyName, value, foreignId) VALUES ('null', NULL, NULL);
826 )"));
827
828 return result;
829}
830
831SQLiteFlightSqlServer::~SQLiteFlightSqlServer() = default;
832

Callers 1

TestFromUriAbfsMethod · 0.45

Calls 5

to_stringFunction · 0.85
GetSqlInfoResultMapFunction · 0.85
RegisterSqlInfoMethod · 0.80
InvalidFunction · 0.50
ExecuteSqlMethod · 0.45

Tested by 1

TestFromUriAbfsMethod · 0.36