From 3103b0dc726980a8679000fd2f5050f633954b37 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 31 Jul 2017 23:11:29 +0200 Subject: [PATCH] Escape SQL identifiers in SQLite catalog queries. SQLite supports the backtick escaping for SQL identifiers and we'd rather use it. Fixes #600. --- src/sources/sqlite/sqlite-schema.lisp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sources/sqlite/sqlite-schema.lisp b/src/sources/sqlite/sqlite-schema.lisp index 57b8557..2580ed6 100644 --- a/src/sources/sqlite/sqlite-schema.lisp +++ b/src/sources/sqlite/sqlite-schema.lisp @@ -77,7 +77,7 @@ (defun list-columns (table &key db-has-sequences (db *sqlite-db*) ) "Return the list of columns found in TABLE-NAME." (let* ((table-name (table-source-name table)) - (sql (format nil "PRAGMA table_info(~a)" table-name))) + (sql (format nil "PRAGMA table_info(`~a`)" table-name))) (loop :for (ctid name type nullable default pk-id) :in (sqlite:execute-to-list db sql) :do (let ((field (make-coldef table-name @@ -153,14 +153,14 @@ (defun list-index-cols (index-name &optional (db *sqlite-db*)) "Return the list of columns in INDEX-NAME." - (let ((sql (format nil "PRAGMA index_info(~a)" index-name))) + (let ((sql (format nil "PRAGMA index_info(`~a`)" index-name))) (loop :for (index-pos table-pos col-name) :in (sqlite:execute-to-list db sql) :collect col-name))) (defun list-indexes (table &optional (db *sqlite-db*)) "Return the list of indexes attached to TABLE." (let* ((table-name (table-source-name table)) - (sql (format nil "PRAGMA index_list(~a)" table-name))) + (sql (format nil "PRAGMA index_list(`~a`)" table-name))) (loop :for (seq index-name unique origin partial) :in (sqlite:execute-to-list db sql) :do (let* ((cols (list-index-cols index-name db)) @@ -190,7 +190,7 @@ (defun list-fkeys (table &optional (db *sqlite-db*)) "Return the list of indexes attached to TABLE." (let* ((table-name (table-source-name table)) - (sql (format nil "PRAGMA foreign_key_list(~a)" table-name))) + (sql (format nil "PRAGMA foreign_key_list(`~a`)" table-name))) (loop :with fkey-table := (make-hash-table) :for (id seq ftable-name from to on-update on-delete match)