diff options
| author | Lars Ingebrigtsen | 2021-12-07 06:00:14 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-12-07 06:00:14 +0100 |
| commit | 2df01b7975d9b8e501cfb2cd3b78fcd3ee3c80e9 (patch) | |
| tree | b41ffe6a5cb984872c29052ef1ad4c547390f9fa /src | |
| parent | 14ad9f59499e37e62779238013d278aad9a2f78b (diff) | |
| download | emacs-2df01b7975d9b8e501cfb2cd3b78fcd3ee3c80e9.tar.gz emacs-2df01b7975d9b8e501cfb2cd3b78fcd3ee3c80e9.zip | |
We don't need to precompute the columns
Diffstat (limited to 'src')
| -rw-r--r-- | src/lisp.h | 1 | ||||
| -rw-r--r-- | src/sqlite.c | 36 |
2 files changed, 17 insertions, 20 deletions
diff --git a/src/lisp.h b/src/lisp.h index c669dbcc908..0ce1b096f15 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -2574,7 +2574,6 @@ xmint_pointer (Lisp_Object a) | |||
| 2574 | struct Lisp_Sqlite | 2574 | struct Lisp_Sqlite |
| 2575 | { | 2575 | { |
| 2576 | union vectorlike_header header; | 2576 | union vectorlike_header header; |
| 2577 | Lisp_Object columns; | ||
| 2578 | void *db; | 2577 | void *db; |
| 2579 | void *stmt; | 2578 | void *stmt; |
| 2580 | void (*finalizer) (void *); | 2579 | void (*finalizer) (void *); |
diff --git a/src/sqlite.c b/src/sqlite.c index 8bc9af27775..cdfc97bb031 100644 --- a/src/sqlite.c +++ b/src/sqlite.c | |||
| @@ -42,15 +42,14 @@ sqlite_free (void *arg) | |||
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | static Lisp_Object | 44 | static Lisp_Object |
| 45 | make_sqlite (bool is_statement, void *db, void *stmt, Lisp_Object columns) | 45 | make_sqlite (bool is_statement, void *db, void *stmt) |
| 46 | { | 46 | { |
| 47 | struct Lisp_Sqlite *ptr | 47 | struct Lisp_Sqlite *ptr |
| 48 | = ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Sqlite, columns, PVEC_SQLITE); | 48 | = ALLOCATE_PLAIN_PSEUDOVECTOR (struct Lisp_Sqlite, PVEC_SQLITE); |
| 49 | ptr->is_statement = is_statement; | 49 | ptr->is_statement = is_statement; |
| 50 | ptr->finalizer = sqlite_free; | 50 | ptr->finalizer = sqlite_free; |
| 51 | ptr->db = db; | 51 | ptr->db = db; |
| 52 | ptr->stmt = stmt; | 52 | ptr->stmt = stmt; |
| 53 | ptr->columns = columns; | ||
| 54 | ptr->eof = false; | 53 | ptr->eof = false; |
| 55 | return make_lisp_ptr (ptr, Lisp_Vectorlike); | 54 | return make_lisp_ptr (ptr, Lisp_Vectorlike); |
| 56 | } | 55 | } |
| @@ -79,7 +78,7 @@ If FILE is nil, an in-memory database will be opened instead. */) | |||
| 79 | if (ret != SQLITE_OK) | 78 | if (ret != SQLITE_OK) |
| 80 | return Qnil; | 79 | return Qnil; |
| 81 | 80 | ||
| 82 | return make_sqlite (false, sdb, NULL, Qnil); | 81 | return make_sqlite (false, sdb, NULL); |
| 83 | } | 82 | } |
| 84 | 83 | ||
| 85 | /* Bind values in a statement like | 84 | /* Bind values in a statement like |
| @@ -261,6 +260,17 @@ row_to_value (sqlite3_stmt *stmt) | |||
| 261 | return Fnreverse (values); | 260 | return Fnreverse (values); |
| 262 | } | 261 | } |
| 263 | 262 | ||
| 263 | static Lisp_Object | ||
| 264 | column_names (sqlite3_stmt *stmt) | ||
| 265 | { | ||
| 266 | Lisp_Object columns = Qnil; | ||
| 267 | int count = sqlite3_column_count (stmt); | ||
| 268 | for (int i = 0; i < count; ++i) | ||
| 269 | columns = Fcons (build_string (sqlite3_column_name (stmt, i)), columns); | ||
| 270 | |||
| 271 | return Fnreverse (columns); | ||
| 272 | } | ||
| 273 | |||
| 264 | DEFUN ("sqlite-select", Fsqlite_select, Ssqlite_select, 2, 4, 0, | 274 | DEFUN ("sqlite-select", Fsqlite_select, Ssqlite_select, 2, 4, 0, |
| 265 | doc: /* Select data from the database DB that matches QUERY. | 275 | doc: /* Select data from the database DB that matches QUERY. |
| 266 | If VALUES is non-nil, they are values that will be interpolated into a | 276 | If VALUES is non-nil, they are values that will be interpolated into a |
| @@ -308,21 +318,9 @@ which means that we return a set object that can be queried with | |||
| 308 | } | 318 | } |
| 309 | } | 319 | } |
| 310 | 320 | ||
| 311 | /* Get the field names. */ | ||
| 312 | Lisp_Object columns = Qnil; | ||
| 313 | if (EQ (return_type, Qset) | ||
| 314 | || EQ (return_type, Qfull)) | ||
| 315 | { | ||
| 316 | int count = sqlite3_column_count (stmt); | ||
| 317 | for (int i = 0; i < count; ++i) | ||
| 318 | columns = Fcons (build_string (sqlite3_column_name (stmt, i)), columns); | ||
| 319 | |||
| 320 | columns = Fnreverse (columns); | ||
| 321 | } | ||
| 322 | |||
| 323 | if (EQ (return_type, Qset)) | 321 | if (EQ (return_type, Qset)) |
| 324 | { | 322 | { |
| 325 | retval = make_sqlite (true, db, stmt, columns); | 323 | retval = make_sqlite (true, db, stmt); |
| 326 | goto exit; | 324 | goto exit; |
| 327 | } | 325 | } |
| 328 | 326 | ||
| @@ -332,7 +330,7 @@ which means that we return a set object that can be queried with | |||
| 332 | data = Fcons (row_to_value (stmt), data); | 330 | data = Fcons (row_to_value (stmt), data); |
| 333 | 331 | ||
| 334 | if (EQ (return_type, Qfull)) | 332 | if (EQ (return_type, Qfull)) |
| 335 | retval = Fcons (columns, Fnreverse (data)); | 333 | retval = Fcons (column_names (stmt), Fnreverse (data)); |
| 336 | else | 334 | else |
| 337 | retval = Fnreverse (data); | 335 | retval = Fnreverse (data); |
| 338 | sqlite3_finalize (stmt); | 336 | sqlite3_finalize (stmt); |
| @@ -423,7 +421,7 @@ DEFUN ("sqlite-columns", Fsqlite_columns, Ssqlite_columns, 1, 1, 0, | |||
| 423 | if (!XSQLITE (set)->is_statement) | 421 | if (!XSQLITE (set)->is_statement) |
| 424 | xsignal1 (Qerror, build_string ("Invalid set object")); | 422 | xsignal1 (Qerror, build_string ("Invalid set object")); |
| 425 | 423 | ||
| 426 | return XSQLITE (set)->columns; | 424 | return column_names (XSQLITE (set)->stmt); |
| 427 | } | 425 | } |
| 428 | 426 | ||
| 429 | DEFUN ("sqlite-more-p", Fsqlite_more_p, Ssqlite_more_p, 1, 1, 0, | 427 | DEFUN ("sqlite-more-p", Fsqlite_more_p, Ssqlite_more_p, 1, 1, 0, |