@@ -19929,19 +19929,19 @@ namespace sqlite_orm::internal {
1992919929 * Calls `DROP VIEW "viewName"`.
1993019930 * More info: https://www.sqlite.org/lang_droptable.html
1993119931 */
19932- void drop_view(const std::string& tableName ) {
19932+ void drop_view(const std::string& viewName ) {
1993319933 auto connection = this->get_connection();
19934- this->drop_view_internal(connection.get(), tableName , false);
19934+ this->drop_view_internal(connection.get(), viewName , false);
1993519935 }
1993619936
1993719937 /**
1993819938 * Drops the view with the specified name if it exists.
1993919939 * Calls `DROP VIEW IF EXISTS "viewName"`.
1994019940 * More info: https://www.sqlite.org/lang_droptable.html
1994119941 */
19942- void drop_view_if_exists(const std::string& tableName ) {
19942+ void drop_view_if_exists(const std::string& viewName ) {
1994319943 auto connection = this->get_connection();
19944- this->drop_view_internal(connection.get(), tableName , true);
19944+ this->drop_view_internal(connection.get(), viewName , true);
1994519945 }
1994619946
1994719947 /**
@@ -19980,58 +19980,24 @@ namespace sqlite_orm::internal {
1998019980 */
1998119981 bool table_exists(const std::string& tableName) {
1998219982 auto connection = this->get_connection();
19983- return this->table_exists (connection.get(), tableName);
19983+ return this->object_exists (connection.get(), "table" , tableName);
1998419984 }
1998519985
1998619986 bool table_exists(sqlite3* db, const std::string& tableName) const {
19987- bool result = false;
19988- std::string sql;
19989- {
19990- std::stringstream ss;
19991- ss << "SELECT COUNT(*) FROM sqlite_master WHERE type = " << quote_string_literal("table")
19992- << " AND name = " << quote_string_literal(tableName) << std::flush;
19993- sql = ss.str();
19994- }
19995- this->executor.perform_exec(
19996- db,
19997- sql,
19998- [](void* userData, int /*argc*/, orm_gsl::zstring* argv, orm_gsl::zstring* /*azColName*/) -> int {
19999- auto& res = *(bool*)userData;
20000- res = !!atoi(argv[0]);
20001- return 0;
20002- },
20003- &result);
20004- return result;
19987+ return this->object_exists(db, "table", tableName);
2000519988 }
2000619989
2000719990 /**
2000819991 * Directly checks the actual database whether the specified view exists, bypassing the library's 'storage' mapping.
2000919992 * @return true if view with the specified name exists in the database, false otherwise.
2001019993 */
20011- bool view_exists(const std::string& tableName ) {
19994+ bool view_exists(const std::string& viewName ) {
2001219995 auto connection = this->get_connection();
20013- return this->view_exists (connection.get(), tableName );
19996+ return this->object_exists (connection.get(), "view", viewName );
2001419997 }
2001519998
20016- bool view_exists(sqlite3* db, const std::string& tableName) const {
20017- bool result = false;
20018- std::string sql;
20019- {
20020- std::stringstream ss;
20021- ss << "SELECT COUNT(*) FROM sqlite_master WHERE type = " << quote_string_literal("view")
20022- << " AND name = " << quote_string_literal(tableName) << std::flush;
20023- sql = ss.str();
20024- }
20025- this->executor.perform_exec(
20026- db,
20027- sql,
20028- [](void* userData, int /*argc*/, orm_gsl::zstring* argv, orm_gsl::zstring* /*azColName*/) -> int {
20029- auto& res = *(bool*)userData;
20030- res = !!atoi(argv[0]);
20031- return 0;
20032- },
20033- &result);
20034- return result;
19999+ bool view_exists(sqlite3* db, const std::string& viewName) const {
20000+ return this->object_exists(db, "view", viewName);
2003520001 }
2003620002
2003720003 void add_generated_cols(std::vector<const table_xinfo*>& columnsToAdd,
@@ -20921,6 +20887,23 @@ namespace sqlite_orm::internal {
2092120887 this->executor.perform_void_exec(db, ss.str().c_str());
2092220888 }
2092320889
20890+ bool object_exists(sqlite3* db, const std::string& type, const std::string& name) const {
20891+ bool result = false;
20892+ std::stringstream ss;
20893+ ss << "SELECT COUNT(*) FROM sqlite_master WHERE type = " << quote_string_literal(type)
20894+ << " AND name = " << quote_string_literal(name) << std::flush;
20895+ this->executor.perform_exec(
20896+ db,
20897+ ss.str(),
20898+ [](void* userData, int /*argc*/, orm_gsl::zstring* argv, orm_gsl::zstring* /*azColName*/) -> int {
20899+ auto& res = *(bool*)userData;
20900+ res = !!atoi(argv[0]);
20901+ return 0;
20902+ },
20903+ &result);
20904+ return result;
20905+ }
20906+
2092420907 std::string retrieve_object_sql(sqlite3* db, const std::string& type, const std::string& name) const {
2092520908 std::string result;
2092620909 std::stringstream ss;
0 commit comments