Solved

Mysql where clause in visual c++

Posted on 2004-09-29
2
368 Views
Last Modified: 2012-05-05
Hi,
I have a program in visual c++ .net that connects to a remote Mysql server.
Everything works just fine, I only have a problem when I execute a Mysql query to retrive data:

if I use the following it works just fine

            format = _T("SELECT * FROM clienti WHERE Client_code LIKE '%s'");

            sql.Format(format,m_searchString);

if I try to use this:

            format = _T("SELECT * FROM clienti WHERE Client_code  LIKE '%s' || Name LIKE '%s'");

            sql.Format(format,m_searchString);

where I only added "OR" to wide the search, either gives no result at all or only gives results of the first where clause "Client_code  LIKE '%s' "

I wonder if I need a special syntax to implement "OR" and "AND" statement in visual c++ .net and libmySQL.

Do you have any ideas??

thanks rik

0
Comment
Question by:rcinformatica
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
mnashadka earned 500 total points
ID: 12178792
If you change || to OR, it should give you the proper results:
format = _T("SELECT * FROM clienti WHERE Client_code  LIKE '%s' OR Name LIKE '%s'");
Plus, there's a problem with your Format call. You're only giving it one variable to match one %s; you need a variable for each %s.
sql.Format(format,m_searchString, m_searchString);

Hope this helps.
0
 

Author Comment

by:rcinformatica
ID: 12179101
exactly what I needed thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question