J
J
Julia Kovalenko2017-03-30 19:08:59
MySQL
Julia Kovalenko, 2017-03-30 19:08:59

Query to SphinxSearch on Go?

Hello!
I make a request to the sphincus, I just concatenate the query string with the necessary parameters

rows, err := sphinx.Query("SELECT id " +
        "FROM my_index" +
        " WHERE MATCH('(@first_name " + name + ") (@city " + city + ")')" +
        " AND bdate = " + fmt.Sprintf("%d", Bdate) +
        " AND bmonth = " + fmt.Sprintf("%d", Bmonth) + " AND byear IN (" + fmt.Sprintf("%d", Byear) + ", 0)")

Everything works fine, but it's not safe.
I'm trying to do this:
rows, err := sphinx.Query("SELECT id FROM my_index" +
         " WHERE MATCH('(@first_name ?) (@city ?)') AND bdate = ?" +
         " AND bmonth = ? AND byear IN (?, 0)", 
         name, city, fmt.Sprintf("%d", Bdate), fmt.Sprintf("%d", Bmonth), fmt.Sprintf("%d", Byear))

Gives an error Error 1047: unknown command (code=22)
What could be wrong?
I use import "database/sql"
sphinx, err := sql.Open("mysql", "tcp(127.0.0.1:9306)/my_database")

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav, 2017-08-06
@ghostiam

Sphinx doesn't work with prepare statements, ran into this problem myself. As a solution, escape the characters yourself.
Here is how escaping is done in sphinx api for php
https://github.com/sphinxsearch/sphinx/blob/6adceb...

D
Dimonchik, 2017-03-30
@dimonchik2013

in xs what connector, the sphinx does not work with everyone, for example, not so good with native Muscular (now Oracle)
trace what sends to the sphinx itself ,
but what about unsafe - how is it? think, it will turn out to stir up a sklinection with an index ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question