c++ - sqlite3_step() doesn't seem to work -
I have this C ++ function that works to determine if a given name exists or not . But every time it is mentioned even when a name is already present. Where am I wrong?
bool database :: hereditary (std :: string repoName) {string sql = "select * from store WHERE NAME = '" ;; Sql + = repoName + "'"; Sqlite3_stmt * selectStmt = nullptr; Sqlite3_prepare_v2 (connection, sql.c_str (), sql.size (), and selectStmt, NULL); Int result = sqlite3_step (selectStmt); Sqlite3_finalize (selectStmt); If (result == SQLITE_ROW) return true; Second false return; }
You should check the return value of all the functions, which return the error signal You can. For example, sqlite3_prepare_v2
will return an error code if there is a syntax error in the statement.
He may have told you that the statement given by you is wrong (if any).
You can use sqlite3_errmsg
and sqlite3_errstr
to create more readable error messages. It is never good to throw specific information about the error, for example only by returning false, especially during debugging
Comments
Post a Comment