branch: elpa/emacsql commit dc2afbbc1f37e296311a020e8e6eb3bee55098cb Author: Christopher Wellons <well...@nullprogram.com> Commit: Christopher Wellons <well...@nullprogram.com>
Adjust the Emacsql wire protocol. --- emacsql.el | 18 ++++-------------- sqlite/emacsql.c | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/emacsql.el b/emacsql.el index d2fab3ba60..c1148e5d6a 100644 --- a/emacsql.el +++ b/emacsql.el @@ -173,25 +173,15 @@ Subclasses should override this method in order to provide more specific error conditions." (signal 'emacsql-syntax (list code message))) -(defmethod emacsql-check-error ((connection emacsql-protocol-mixin)) - "Signal the error message from CONNECTION, or return nil." - (with-current-buffer (emacsql-buffer connection) - (let ((standard-input (current-buffer))) - (setf (point) (point-min)) - (when (eql (read) 'error) - (emacsql-handle connection (read) (read)))))) - (defmethod emacsql-parse ((connection emacsql-protocol-mixin)) "Parse well-formed output into an s-expression." - (emacsql-check-error connection) (with-current-buffer (emacsql-buffer connection) (setf (point) (point-min)) (let* ((standard-input (current-buffer)) - (num-columns (read))) - (forward-char 1) - (cl-loop until (looking-at "#") - collect (cl-loop repeat num-columns collect (read)) - and do (forward-char 1))))) + (value (read))) + (if (eql value 'error) + (emacsql-handle connection (read) (read)) + value)))) (provide 'emacsql) ; end of generic function declarations diff --git a/sqlite/emacsql.c b/sqlite/emacsql.c index 3a65f540eb..bef407e68b 100644 --- a/sqlite/emacsql.c +++ b/sqlite/emacsql.c @@ -102,33 +102,42 @@ int main(int argc, char **argv) { } /* Print out rows. */ - int ncolumns = sqlite3_column_count(stmt); - printf("%d\n", ncolumns); + int first = TRUE, ncolumns = sqlite3_column_count(stmt); + printf("("); while (sqlite3_step(stmt) == SQLITE_ROW) { + if (first) { + printf("("); + first = FALSE; + } else { + printf("\n ("); + } for (int i = 0; i < ncolumns; i++) { + if (i > 0) { + printf(" "); + } int type = sqlite3_column_type(stmt, i); switch (type) { case SQLITE_INTEGER: - printf(" %llu", sqlite3_column_int64(stmt, i)); + printf("%lld", sqlite3_column_int64(stmt, i)); break; case SQLITE_FLOAT: - printf(" %f", sqlite3_column_double(stmt, i)); + printf("%f", sqlite3_column_double(stmt, i)); break; case SQLITE_NULL: - printf(" nil"); + printf("nil"); break; case SQLITE_TEXT: - fputc(' ', stdout); fwrite(sqlite3_column_text(stmt, i), 1, sqlite3_column_bytes(stmt, i), stdout); break; case SQLITE_BLOB: - printf(" nil"); + printf("nil"); break; } } - printf("\n"); + printf(")"); } + printf(")\n"); if (sqlite3_finalize(stmt) != SQLITE_OK) { fprintf(stderr, "error %d: %s\n", sqlite3_errcode(db), sqlite3_errmsg(db));