Deleting row from MySQL database
-
Hi
I am inserting a integer number using qlineedit like this
"int contact_no = ui->lineEdit_3->text().toInt();
query->addBindValue(contact_no);" now my problem is it is accepting only 9 digit numbers only not more than that 10 ,11,etc .please tell which data type i need to use if want give more than 9 digits number ...... -
int in MySQL goes from -2147483648 to 2147483647 (or from 0 to 4294967295 if unsigned) (ref: https://dev.mysql.com/doc/refman/5.7/en/integer-types.html) and same goes for a c++ int variable in most environments so it's only natural you can't use the majority of numbers with 10 digits.
Use a BIGINT (qint64 in C++) to go to 18 digits or just use a string
-
@veera Can you show the CREATE TABLE query you're using for the table where you're trying to insert int > 9digits?
-
@jsulm
Here is my table
CREATE TABLE entry (id INT,name NVARCHAR(200),contact_no INT,lastname NVARCHAR(200),emailid NVARCHAR(200)); -
int in MySQL goes from -2147483648 to 2147483647 (or from 0 to 4294967295 if unsigned) (ref: https://dev.mysql.com/doc/refman/5.7/en/integer-types.html) and same goes for a c++ int variable in most environments so it's only natural you can't use the majority of numbers with 10 digits.
Use a BIGINT (qint64 in C++) to go to 18 digits or just use a string
-
@VRonin
I am using MSSQL on ubuntu 16.04 LTS 64 bit
after using qint64 instead of int in qtcreator application..... also samething is coming i.e 0 if i am inserting more than 10 digits.... -
i want to store the mobile No is 10 digits so after declaring qint64 also same issue is coming ....
@veera
Hi
int contact_no = ui->lineEdit_3->text().toInt();This is still int and limit in range
So you are looking at something like
bool ok;
QString input=ui->lineEdit_3->text();// take text
qint64 contact_no = input.toLongLong(&ok); // convert
if (!ok) {
error("invalid value");
return;
}
..
Convert was ok, use.