Recent

Author Topic: [ZeosDBO/TZQuery] Passing a parameter that is a list of integer for MariaDB  (Read 470 times)

rdxdt

  • New member
  • *
  • Posts: 8
Hello, i'm porting an application and i have to do the following query
Code: SQL  [Select][+][-]
  1. SELECT
  2.     venda_pagamento.id,
  3.     venda_pagamento.pagamento_id,
  4.     SUM(venda_pagamento.valor) AS valor_total,
  5.     forma_pagamento.tipo
  6. FROM
  7.     venda_pagamento
  8. INNER JOIN forma_pagamento ON venda_pagamento.pagamento_id = forma_pagamento.id
  9. WHERE
  10.     venda_pagamento.venda_id IN (:venda_ids)
  11. GROUP BY
  12.     venda_pagamento.pagamento_id, venda_pagamento.id, forma_pagamento.tipo
  13.  
How can i set the parameter :venda_ids to be a list of integers for that query on MariaDB
The SQL Syntax would be like
Code: SQL  [Select][+][-]
  1. venda_pagamento.venda_id IN (1,3,4,6,8,9,11,12,19)

zeljko

  • Hero Member
  • *****
  • Posts: 1770
    • http://wiki.lazarus.freepascal.org/User:Zeljan
YourParam
  • .AsString := YourStringList.CommaText ? (contains numbers in TStringList)

rdxdt

  • New member
  • *
  • Posts: 8
If the parameter type is ftString then it will have this result
Code: SQL  [Select][+][-]
  1. venda_pagamento.venda_id IN ('1,3,4,6,8,9,11,12,19')
, which would not work.
The prepared query should look like
Code: SQL  [Select][+][-]
  1. venda_pagamento.venda_id IN (1,3,4,6,8,9,11,12,19)
It would work if ZeosDBO supported Macro, then a raw macro would work perfectly, but from testing does not seem like it supports.

zeljko

  • Hero Member
  • *****
  • Posts: 1770
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Then use Format() ... Format('WHERE myitems in (%s) ',[AItemsCommaSeparated]);

rdxdt

  • New member
  • *
  • Posts: 8
My previous reply still applies, once Zeos parse the parameter as ftString it will encapsulate it's content in single quotes.
But nevermind, i made the query in another way that won't require this anymore.

 

TinyPortal © 2005-2018