Click here to Skip to main content
15,884,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using the following code to insert the values into the MYSQL database. In this CString SqlStr4 is accepting and taking values up to sqlstr3 assumption, after that it is not taking the other values. What is the problem in this?? help me.

CString SqlStr4;
SqlStr4 = "INSERT INTO log SET grab_date= '";
SqlStr4 +=strDateTime;
SqlStr4 += "',ip_address='";
SqlStr4 +=SqlStr3;
SqlStr4 += "',image='";
SqlStr4 += StrByte;
SqlStr4 +="';";
Posted
Updated 4-May-11 2:45am
v4

Check that SqlStr3 is a valid string.
For example a common way to "break" a CString object is to use its GetBuffer method, modify the string, and forget to call ReleaseBuffer...

I don't understand what might be wrong. Try to comment a few lines to know exactly which one raises the problem. For example:
C++
CString SqlStr4;
SqlStr4 = "INSERT INTO log SET grab_date= '";
SqlStr4 +=strDateTime;
SqlStr4 += "',ip_address='";
//SqlStr4 +=SqlStr3;
SqlStr4 += "',image='";
SqlStr4 += StrByte;
SqlStr4 +="';";


Once you found which lines (it might be several ones) causes the problem, do the same thing with that string. For example, if you found out that only SqlStr3 causes the problem, then look carefully how SqlStr3 is built. Try to build it a different way...
 
Share this answer
 
v2
Comments
Gokulnath007 4-May-11 8:31am    
Am not using GetBuffer method, all the variables having the correct values but it is not being taken into the Sqlstr4. I mean copying.
Olivier Levrey 4-May-11 8:38am    
So there is something else you are not telling or showing in your code because I don't see any reason why the concatenation would fail here.
Are your using threads? Is SqlStr3 a shared variable?...
Gokulnath007 4-May-11 8:40am    
No, SqlStr3 just stores the value 6. Am not using any thread.
Chuck O'Toole 4-May-11 21:48pm    
Having looked at your shown output, "6" is terrible as an IP address so I don't think you're pulling the IP field out of the record set correctly. Have you looked at the varient variable with the debugger?
Chuck O'Toole 4-May-11 9:01am    
Please show us values of strDateTime, SqlStr3, and StrByte as well as the final content of SqlStr4 so we can have a clue. And don't just say "stores the value 6", show the actual string value, it may not contain what you think it does.
What do you mean by 'does not accept'? Do you mean you get a runtime error while building SqlStr4, or does your database complain about the string you pass? If the latter, is ip_address actually a string type? maybe you should skip the quotes on this field?
 
Share this answer
 
This is just a hunch, but is there any chance that SqlStr3 is a unicode string? The reason I ask is that it appears that your other strings are not unicode and perhaps that is causing your problem.

Just a thought.
 
Share this answer
 
Comments
Chuck O'Toole 4-May-11 21:43pm    
Yes, it seems there's a NULL character (\0) in SqlStr3. I'm not sure how it got there, UNICODE would be one way, the other is this loop he used "for(int i=0;iGetLength();i++)". His post did not show the relationship for the terminating condition but it could also pick up a NULL if it's anything other then "<".
You have to use the mysql_escape_string function to make a valid call.
So you have to escape your strings strDateTime, SqlStr3, StrByte.
Regards.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900