6

I have a table like :

------------------------------
Test_Id           Test_data
(String)          (blob)
------------------------------

I want a query to retrieve all the Test_Id's for a matching Test_data.

To achieve something like : select * from test_table where Test_data = blobObject;

How can we do above ??

1
  • Can you elaborate more on blobObject that you are comparing Commented Aug 23, 2010 at 10:33

3 Answers 3

8

First: there's no such thing as a string in MySQL. Only char/varchar/text.

Well you could cast it as char for comparison like this:

select * from test_table where Test_data = CAST( blobObject AS CHAR );

what's probably better is to convert your string to a binary string, but this might not give you the right comparison if you expect string comparison behaviour... well best you have a look at the char functions here:

http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html

Sign up to request clarification or add additional context in comments.

1 Comment

How do you know the string's length for a language like C++?
3

You can use a hash function such as MD5

SELECT * FROM example_table WHERE MD5(blob_column) = 'a6a7c0ce5a93f77cf3be0980da5f7da3';

Comments

1

MySQL has data types which can store binary data. Not only char/varchar/text, but also BINARY/VARBINARY/BLOB.

See http://dev.mysql.com/doc/refman/5.5/en/blob.html

And it's usage is as simple as normal string type. But, escaping is required. and query length is must specified because binary data may contain NULL character in their contents.

Before MySQL 3.23 (I guess), There were only mysql_query(), mysql_escape_string(). Those function has no capability specifying query length. after BLOB has been introduced in MySQL, mysql_real_query() and mysql_real_escape_string() supported.

I found some examples for you. May this links help you!

http://zetcode.com/db/mysqlc/ http://bytes.com/topic/c/answers/558973-c-client-load-binary-data-mysql

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.