ストアド プロシージャへのパラメーターとして 'search_string' を使用してこのクエリを実行しようとすると、MySQL データベースで 'field list' の Unknown column 'search_string'エラー メッセージが表示されます。
DROP PROCEDURE IF EXISTS select_title_from_book_table_like;
CREATE PROCEDURE select_title_from_book_table_like(IN IN_TITLE VARCHAR(255))
BEGIN
PREPARE stmt FROM
"SELECT b.book_id,
LEFT(b.title, 36) AS title,
b.edition,
GROUP_CONCAT(CONCAT_WS(' ', a.last_name,
a.first_name,
a.patronymic)
ORDER BY a.last_name
SEPARATOR ', ') AS authors,
YEAR(b.published) AS published,
LEFT(b.pages, 8) AS pages,
b.isbn,
s.subject,
l.language,
p.publisher
FROM (SELECT * FROM book WHERE title LIKE '%?%') AS b
LEFT JOIN book_author AS ba
ON b.book_id = ba.book_id
LEFT JOIN author AS a
ON ba.author_id = a.author_id
LEFT JOIN language AS l
ON b.language_id = l.language_id
LEFT JOIN subject AS s
ON b.subject_id = s.subject_id
LEFT JOIN publisher AS p
ON b.publisher_id = p.publisher_id
GROUP BY b.book_id
ORDER BY b.title ASC";
SET @param1 = IN_TITLE;
EXECUTE stmt USING @param1;
DEALLOCATE PREPARE stmt;
END$$
これは、プロシージャを呼び出すコードです。
ShowStringGrid(StringGrid,
'CALL select_title_from_book_table_like(' + Trim(SearchBox.Text) + ')');