0

below is part of my code,

 ...
 char hashvalue[]="somehash"; // or i can use std::string

 SQLCHAR* query = (SQLCHAR*)"SELECT username FROM users WHERE hash = ..." ;
 SQLExecDirectA( hStmt, query, SQL_NTS );
 ...

In the code above I have no idea how to insert into query hashvalue to execute my query like this:

 SQLCHAR* query = (SQLCHAR*)"SELECT username FROM users WHERE hash = "somehash"" ;

I 'm very new to sql, thanks in advance for help.

1
  • 2
    Use std::string and bask in the glory of overloaded operators. Commented Jun 16, 2014 at 21:20

1 Answer 1

2

Use std::string

std::string query_string = "SELECT username FROM users WHERE hash = ";
query_string += hashvalue;
SQLExecDirectA(hStmt, query_string.c_str(), SQL_NTS);

Another method:

char query_buffer[1024];
snprintf(query_buffer,
         "SELECT username FROM users WHERE hash = %s",
         hashValue);
SQLExecDirectA(hStmt, query_buffer, SQL_NTS);

Basically, your question is how to create a formatted string and has nothing to do with SQL.

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

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.