I have a Pervasive database with which I connect to C ++. All my queries are still parameterized, i.e. "SELECT USER.NAME FROM USER WHERE USER.ID = ?" and it works great. But in the search query, I use LIKE in the WHERE clause, and it seems like I cannot use parameters and wildcards (%).
My query looks something like this: "SELECT * FROM DOG WHERE DOG.NAME LIKE '%?%'" , And since there are two "around the? -Mark parameter, this fails, he searched for dogs with? -mark in their name. In SQL Server, this will probably be solved by concatenating a string like "SELECT * FROM DOG WHERE DOG.NAME LIKE '%' + ? + '%'" , But this is not valid syntax in Pervasive (see Bottom of this page: http: / /ww1.pervasive.com/library/docs/psql/950/sqlref/sqlref-04-55.html ).
I also tried adding% -signs to the parameter itself, but this does not work either.
Does anyone know about this solution?
EDIT1: C ++ Code Example:
CString sqlCommand = "SELECT * FROM DOG WHERE DOG.NAME LIKE ?;"; m_pAdoCommand->CommandText = _bstr_t(sqlCommand); m_pAdoCommand->Parameters->Append( m_pAdoCommand->CreateParameter("p0", adVarChar, adParamInput, 25, _bstr_t("'%bob%'")) ); m_pAdoRecordset = m_pAdoCommand->Execute(NULL,NULL,adCmdText);
( m_pAdoCommand is _CommandPtr and m_pAdoRecordset is _RecordsetPtr . I changed the name of the SQL tables in this example to make them feel here.)
The above code will return a line with a dog that has the name '%bob%' , but I would like it to return all dogs that have a bob in their name.
source share