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