From: Eli Zaretskii Date: Thu, 2 Feb 2023 19:45:44 +0000 (+0200) Subject: Minor improvements in sqlite.c X-Git-Tag: emacs-29.0.90~535 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=20454128b8be9fb3b525ac43f7e5dfa9cc639db0;p=emacs.git Minor improvements in sqlite.c * src/sqlite.c (Fsqlite_next): Doc fix. Return nil if SQLITE_DONE was once seen for this statement. (Bug#61151) (row_to_value): Cons the value in reverse, to avoid the Fnreverse call. Patch by Helmut Eller . (Bug#61165) --- diff --git a/src/sqlite.c b/src/sqlite.c index c96841e63f9..0361514766a 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -399,7 +399,7 @@ row_to_value (sqlite3_stmt *stmt) int len = sqlite3_column_count (stmt); Lisp_Object values = Qnil; - for (int i = 0; i < len; ++i) + for (int i = len - 1; i >= 0; i--) { Lisp_Object v = Qnil; @@ -434,7 +434,7 @@ row_to_value (sqlite3_stmt *stmt) values = Fcons (v, values); } - return Fnreverse (values); + return values; } static Lisp_Object @@ -718,11 +718,15 @@ Only modules on Emacs' list of allowed modules can be loaded. */) #endif /* HAVE_SQLITE3_LOAD_EXTENSION */ DEFUN ("sqlite-next", Fsqlite_next, Ssqlite_next, 1, 1, 0, - doc: /* Return the next result set from SET. */) + doc: /* Return the next result set from SET. +Return nil when the statement has finished executing successfully. */) (Lisp_Object set) { check_sqlite (set, true); + if (XSQLITE (set)->eof) + return Qnil; + int ret = sqlite3_step (XSQLITE (set)->stmt); if (ret != SQLITE_ROW && ret != SQLITE_OK && ret != SQLITE_DONE) xsignal1 (Qsqlite_error, build_string (sqlite3_errmsg (XSQLITE (set)->db)));