We help IT Professionals succeed at work.

MySQL Search syntax for Binary Strings from VFP

Mike Jacobs
Mike Jacobs asked
on
Medium Priority
45 Views
Last Modified: 2020-03-15
Up to now in my Mysql searches, I've only performed searches for BIGINTs and INTs which behave as I expect. (with the minor quibble I raised a few days ago about why BIGINTs appear as string data not numeric)

Now I'm trying to perform a search for a binary string and I cannot get the syntax right

Sample Code

TARGHASH=HASH_SALTED
&& An SHA256 32 Byte value stored, locally, in a 32 byte VFP CHAR(BINARY) Field and remotely  in a 32 byte Mysql Varbinary column

I prepare a string to encode the SQSTRING I will use in the select statement thus:
success=SQLPREPARE(HND,SQSTRING,'ROWFOUND')

IF NOT CHECK_EXECUTE(SUCCESS,HND)  && a function which checks the syntax and displays any errors or goes on to execute it
      CANCEL
ENDIF
SUSPEND

with and without
CURSORSETPROP("MapBinary",.t.,0)

I have tried the following versions of SQSTRING :

SQSTRING="SELECT HASH_SALTED,ROWNUM FROM HASH_CHAIN WHERE HASH_SALTED="+TARGHASH
*anticipated this would work because the VFP field is CHAR(BINARY) and to the human eye the raw data in the vfp table looks identical to the raw data visible in the Mysql column

SQSTRING="SELECT HASH_SALTED,ROWNUM FROM HASH_CHAIN WHERE HASH_SALTED="+ENCODE(TARGHASH,'HEX')
*ENCODE IS A CALL TO A CHILCRYPT LIBRARY WHICH CONVERTS THE STRING TO HEX

SQSTRING="SELECT HASH_SALTED,ROWNUM FROM HASH_CHAIN WHERE HASH_SALTED=BINARY"+TARGHASH

SQSTRING="SELECT HASH_SALTED,ROWNUM FROM HASH_CHAIN WHERE HASH_SALTED=CONVERT("+TARGHASH+",BINARY)"

all are rejected with the standard mysql error

eg: "Connectivity error: .... check the manual to your mysql server version for the right syntax to use near ïÆÅ9q"¥Á5ºå;?      û#õ”úC

Can someone please put me out of my misery?
Comment
Watch Question

CERTIFIED EXPERT
Commented:
please try

SQSTRING="SELECT HASH_SALTED,ROWNUM FROM HASH_CHAIN WHERE HASH_SALTED=?TARGHASH"

Author

Commented:
excellent. Thankyou.
CERTIFIED EXPERT

Commented:
Glad it worked for you.

Reason it failed was there were no delimiters for your HASH (like double or single quotes), So if you pass it as a parameter it takes care of that problem, It may also work if you add a quote before and after the HASH, but am not 100% sure since your binary value probably has a quote also, so not sure what would happen.

Author

Commented:
yeah, the high probablity of an embedded quote is what threw me off the trail.