Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Limit not work in sql
$sql = "INSERT INTO test1 (entity_id, test, created)
SELECT entity_id, test, :c_time
FROM test2 AS t
WHERE entity_type = :c_repn
GROUP BY entity_id
LIMIT :c_start, :c_lim
ON DUPLICATE KEY UPDATE test = VALUES(test), created = VALUES(created)";
db_query($sql,$arr);
Comments
Comment #2
yash_khandelwal CreditAttribution: yash_khandelwal as a volunteer and at Iksula commentedTry this example.
I hope, this will help you.
Comment #3
Alexandr.P CreditAttribution: Alexandr.P commentedin your limit no placeholder
Comment #4
Tart0LIMIT tag only accept INT type, ensure your vars contains only integer then retry
Comment #5
Alexandr.P CreditAttribution: Alexandr.P commentedthe problem lies elsewhere LIMIT :c_start, :c_lim == LIMIT '0', '10'
I need to LIMIT 0, 10
Comment #6
Alexandr.P CreditAttribution: Alexandr.P commentedby using db_query_range($sql, $start, $limit, $arg);
out
INSERT INTO test1 (entity_id, test, created)
SELECT entity_id, test, :c_time
FROM test2 AS t
WHERE entity_type = node
GROUP BY entity_id
ON DUPLICATE KEY UPDATE test = VALUES(test), created = VALUES(created)
LIMIT 0,10
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ON DUPLICATE KEY UPDATE
Comment #7
Konstantin Komelin CreditAttribution: Konstantin Komelin commentedI think there is no need to overcomplicate things. Your query is not trivial in fact, so you may want to pass parameters directly.
Just don't forget to sanitize them.
Comment #8
Alexandr.P CreditAttribution: Alexandr.P commentedДобрый день Константин. То есть Вы считаете, что принудительное изменение для лимита типа переменной, этого достаточно? Если да то тогда просто доп проверку перед вставкой в sql. и если не целое, то sql не выполняется.
Comment #9
Konstantin Komelin CreditAttribution: Konstantin Komelin commentedПриветствую, Александр.
(int) - самый дешевый способ перевода из строки в число из мне известных. Кроме того, он гарантирует безопасность поступающих парметров.
В чем ваши сомнения?
Как вам удобно. Я лишь показал простейший способ того, как сделать лимит в вашем SQL запросе.
Пожалуйста, используйте английский язык, так как это правило использования drupal.org. Другие тоже должны понимать о чем идет речь.
---
Hi Alexandr,
(int) is the cheapest approach for converting a string to a number of those I know. Moreover, it guarantees safety of the parameters.
What are your doubts?
I gave a rough idea on how to implement the limit for your query. Feel free to improve the code sample.
By the way, please use English because it's one of the rules of Drupal.org. Others should be able to understand what's going on.
Comment #10
Alexandr.P CreditAttribution: Alexandr.P commentedДа у меня хреново с англицким
Да и пусть учат международный русский язык
Comment #12
apaderno