Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Receiving an error message on data type:
warning C4244: 'initializing' : conversion from 'my_ulonglong' to 'unsigned int', possible loss of data


int main()
   {
	MYSQL_RES *res_set;
	MYSQL* conn;
	MYSQL_ROW row;
   conn = mysql_init(NULL);
     if (mysql_real_connect(conn,"urlock.db.5513143.hostedresource.com","VendorCheck","Reader1234","urlock",0,NULL,0) !=0)
	 {
		mysql_query(conn,"SELECT * FROM tblURL WHERE '192.168.1.1'");
		unsigned int i = 0;
		res_set = mysql_store_result(conn);
		unsigned int numrows = mysql_num_rows(res_set);
		while ((row = mysql_fetch_row(res_set)) != NULL){
		printf("%s\n",row[i] != NULL ?
        row[i] : "NULL");
		}
		mysql_free_result(res_set);
		mysql_close(conn);
		system("PAUSE"); 
	 }
	 else
	 {
		 cout << "Conn Failed!" <<endl;
     system("PAUSE"); 
     return 0;
	 }
}
Posted
Updated 10-May-11 17:27pm
v3
Comments
Member 7766180 10-May-11 22:50pm    
Am I going from a string to an integer? If so how to correct?
DS

1 solution

One of the mysql() calls is probably returning type my_ulonglong, usually a type "long long" integer is a 64-bit integer, so the compiler's telling you that you may lose data when placing the value of a "long long" integer to a regular 32-bit integer. If you don't expect the result to ever exceed the maximum value of a 32-bit integer, then just do an explicit cast to keep the warning from coming up, otherwise, pass the value onto a 64-bit integer instead.

Explicit Cast:
unsigned int val = (unsigned int) mysqlblah();


Or set your return int to a 64-bit int (two alternatives):
unsigned long long val = mysqlblah();
unsigned __int64 val = mysqlblah();


Here's a reference page:
http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx[^]
 
Share this answer
 
v2
Comments
Hans Dietrich 10-May-11 23:26pm    
Accurate, complete answer. My 5.
Stefan_Lang 11-May-11 4:49am    
Very good answer, but I'd put a heavy emphasis on "don't expect the result to _ever_ exceed". The history of the software industry, short as it is, is full of diastrous consequences of programmers believing a value would never exceed a certain limit, e. g.: "no one will ever need more than 640 KB memory", or: "two digits are enough to store a year".

Better be safe than sorry!
Albert Holguin 11-May-11 9:24am    
its impossible to design with every single circumstance in mind, even now there's limitations ("...ever need more than 640...")... with that said, its up to everyone to make their own decisions
Member 7766180 11-May-11 10:50am    
Thank you Albert! Great informative answer as usual! You are the best! You have helped and taught me several things in short period of time! You are true the spirit of this site! Onward! Where would I look in MySql() to find the 64bit call and what would it look like?
Thanks
DS
Albert Holguin 11-May-11 10:53am    
thanks :) ... look at the function prototypes, the return type is the first portion of the prototype, a lot of libraries will make their own type names, but the definition would also be in the header with the rest of the prototypes.

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



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