|
Hi,
I have been looking at connecting to MySQL databases for the past few hours and have it all working fine. However I am trying to retrieve information from my ini file that I have for my program and that works fine but when I try to put it into my MySQL Select command it causes an error and crashes the program. This is most likley a simple mistake on my behalf but could you please point me in the right direction. I am using the mysql++ library by the way. My code is as follows:
char szAuth[_MAX_PATH];
GetPrivateProfileString("Auth", "Key", "", szAuth, sizeof(szAuth),
"D:\\Programs\\Microsoft Visual Studio\\MyProjects\\Project12\\Debug\\IniDemo.ini");
std::cout << szAuth << "\n";
pConnection = mysql_init(NULL);
if(!pConnection) //error, quit the program
return 0;
printf("Attempting to connect\n");
if(mysql_real_connect(pConnection,"localhost","username","password","test",0,NULL,0) == NULL) //error, quit the program
return 0;
printf("Connected to the database\n");
mysql_query(pConnection,"SELECT * FROM auth WHERE auth=szAuth"); //query the database
pResult = mysql_store_result(pConnection);
printf("The Number of rows in the table: %d\n", mysql_num_rows(pResult));
mysql_free_result(pResult);
mysql_close(pConnection);
printf("Connection Terminated\n");
return 0;
|
|
|
|
|
If you're querying on a string in SQL, you need to wrap it in single quotes 'like this'.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
That was the first thing I tried but it just searches for szAuth in the database and not what the actuall value of szAuth is from the ini file.
|
|
|
|
|
MySQL is not going to pull values out of your ini file, you need to get the value and pass it, with quotes, to the database.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thats what I am trying to do. The value from the ini is not pulled through the MySQL statement. I used 'GetPrivateProfileString' to get the value from the ini file before the MySQL string and called that value szAuth and I know it works because I printed szAuth to the screen its just when I try to put szAuth into the MySQL statement that it just tries to find szAuth and not the actuall value of szAuth.
|
|
|
|
|
*sigh* If you have a variable called szAuth, and you want to build an SQL search string for it, the search string needs the VALUE of szAuth in quotes. Like this:
"SELECT * from books where Author='" + szAuth + "'"
NOT
"SELECT * from books where Author=" + "szAuth"
and not
"SELECT * from books where Author=" + szAuth
either
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Oh right, sorry I did not quite understand what you meant. I have changed that but now I am getting an error about "cannot add two pointers." I am looking on google for what this is but if you could help that would be great. At the moment I understand its something to do with using the + but im not exactly sure what.
|
|
|
|
|
Use a class like string or CString to hold your query, because otherwise, you're trying to add two char*, and you can't do that. you could use strcat, but there's no reason not to use C++
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ok, thankyou for all of your help.
|
|
|
|
|
Hello,
I have a web service un C# and a client in C++ that uses this web service without problems. Right now the aplication in VC++ is a simple console aplication and I need to modify it to make it a DLL. I have followed the basic steps to do this and also created another aplication (a console application also in VC++) that calls a function exported by my DLL to use the webservice but now when I try to run it I get the following error:
ATLSOAP: CSoapRootHandler::InitializeSOAP -- failed to get SAXXMLReader.
I don't get any errors when I compile my solition.
Unfortunately I haven't found any reference to this problem and I don't know what I am doing wrong.
Thank you so much for any help.
Yas
PS. I am using visal studio .net and .NET framework 1.1.
|
|
|
|
|
I created a c++ program that creates a dictionary file. the problem is that it won't go any larger than 4Gb. Is there any way around this limit?
|
|
|
|
|
I assume we are talking about NTFS here. Doesn't that system have a maximum volume size of 4GB? If not, then you are probably being plagued by the API you are using. The maximum size of an unsigned int is 4GB.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
If it does then how can I get around that max size? Is a way to create another file once that limit is reached?
|
|
|
|
|
Andrew Admire wrote:
If it does then how can I get around that max size?
Use a type that can store values larger than 232, perhaps.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Is there a way to generate files in C++? So I can get around the file limit size?
|
|
|
|
|
Technically, no. C++ knows nothing of file I/O. You can, however, use things like:
CFile
fopen()
CreateFile()
ostream But those will not get you any further than you already are.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Would I be able to limit the file that prog creates then write a line that states if you reach x size then create another file and contine?
|
|
|
|
|
I don't see why not.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I am new to all of this. Could you point me in the right direction?
|
|
|
|
|
What method are you currently employing to create the file?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
ofstream outClientFile ("diction.txt", ios::out);
|
|
|
|
|
Ok, so what methods of the ofstream class are you using to write to the file? How are you verifying that the file has maxed out at 4GB? Perhaps you could put together a small program, similar to what Rick did except use ofstream , that exhibits the problem.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
According to the MSDN website, the max size for a file on FAT32 is 4GB and under NTFS it is 16TB. I just tried a little experiment here and was able to write a file of 5GB on a system using NTFS. I used fopen to create the file and fprintf to write to it. FWIW, it took 163.2 seconds to write the file with some diagnostics output occuring. I would attempt bigger files but I didn't want to spend the time.
|
|
|
|
|
Rick York wrote:
FWIW, it took 163.2 seconds to write the file...
Nothing wrong with that. I wonder how long it would take the SetFilePointer() /SetEndOfFile() pair to do something similar.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
The book I'm using does not have those commands in it. Would you be kind enough to send me a sample code using those two commands?
|
|
|
|