Deleting row from MySQL database
-
wrote on 28 Feb 2017, 07:43 last edited by VRonin
Hi All,
I am fetching the existing table from the mssql server using qtcreator now i want to delete data of specific row such as ID i am using this apiquery->prepare("DELETE FROM entry where id = 'id' ");
can any one tell me why it is not deleting specific row......
forked from here to new thread. please do not resurrect 10 months old threads with not really related questions ~ VRonin
-
wrote on 28 Feb 2017, 08:21 last edited by VRonin
this: query->prepare("DELETE FROM entry where id = 'id' "); does not even compileWhat you want to achieve is explained in the docs: http://doc.qt.io/qt-5/qsqlquery.html#approaches-to-binding-values (they use INSERT instead of DELETE but it's exacly the same mechanic)
-
wrote on 28 Feb 2017, 13:07 last edited by
Hi VRonin,
It was successfully compiled and if i pass ID number it will be deleting entire row using push button i want it in a generic way instead of hardcoding...... -
Hi VRonin,
It was successfully compiled and if i pass ID number it will be deleting entire row using push button i want it in a generic way instead of hardcoding...... -
wrote on 2 Mar 2017, 07:47 last edited by
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 ...... -
wrote on 2 Mar 2017, 08:01 last edited by
what type is
id
in your database? -
wrote on 3 Mar 2017, 08:13 last edited by
int type
-
@veera Can you show the CREATE TABLE query you're using for the table where you're trying to insert int > 9digits?
-
wrote on 3 Mar 2017, 10:31 last edited by VRonin 3 Mar 2017, 11:12
@VRonin said in Deleting row from MySQL database:
what type is
id
in your database?int type only......
-
wrote on 3 Mar 2017, 11:19 last edited by
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.... -
wrote on 4 Mar 2017, 10:45 last edited by veera 3 Apr 2017, 10:46
i want to store the mobile No is 10 digits so after declaring qint64 also same issue is coming ....
-
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.
1/16