processone / ejabberd

Robust, Ubiquitous and Massively Scalable Messaging Platform (XMPP, MQTT, SIP Server)
https://www.process-one.net/en/ejabberd/
Other
6.01k stars 1.5k forks source link

I try to write query with in_array_string and get error #4081

Closed relbraun closed 11 months ago

relbraun commented 11 months ago

I have created a module that tries to run this query: ejabberd_sql:sql_query_t(?SQL("update some_table set col=%(Val)s where jid=%(LJid)s and username in (%(ItemIds)ls)")). The ItemIds variable is a list of binary.

I get the following error: function_clause.

What wrong with that syntax?

Environment

prefiks commented 11 months ago

Maybe try update some_table set col=%(Val)s where jid=%(LJid)s and username in %(ItemIds)ls (without embeding that in ())

relbraun commented 11 months ago

@prefiks I have just tried it and it doesn't help. The same error.

prefiks commented 11 months ago

Do you have -include("ejabberd_sql_pt.hrl"). in that file?

relbraun commented 11 months ago

@prefiks Yes.

prefiks commented 11 months ago

So for testing i used ejabberd_sql:sql_query(Host, ?SQL("update last set seconds=%(Val)s where username in %(ItemIds)ls") and it worked when called with [<<"user1">>, <<"user2">>] as itemsids.

Do you get full stacktrace with that error?

relbraun commented 11 months ago

@prefiks you were right. There was another problem in my code syntax. Thank you for assistance.

licaon-kter commented 11 months ago

@relbraun what? what's the fix? :shrug:

relbraun commented 11 months ago

@licaon-kter the fix is that you have to use this syntax: ejabberd_sql:sql_query(Host, ?SQL("update last set seconds=%(Val)s where username in %(ItemIds)ls"). And it will work properly .