Solved Sqlite3 Select statment return no result
-
Are you also inserting data in your database through Qt ?
-
@SGaist yep using QDateEdit and it insert it as arabic digits , but for this table i'm using normal number ( didn't input from Qt )
-
Did you create that database using another sqlite application ?
I'd test again with a database created completely with Qt.
-
@SGaist I think u got lost there :D , and my english isn't that good anyway i will try explain more :
east numbers ( west numbers ) : ٠ (0) , ١ (1), ٢ (2), ٣ (3), ٤ (4), ٥ (5), ٦ (6), ٧ (7), ٨ (8) , ٩ (9) .QDateEdit uses east numbers by default i think that cuz my computer is arabic ! , even if i change the QDateEdit prototype to english the numbers are changed to english but when insert to db it gives in east numbers ( as u can see the video above ) .
QString can recognize tha east numbers
so if u write :QString test = "٢٠١٧"; // output will be 2017
so here we put east numbers in QString but when try to print with qDebug() or anything else it will give us the numbers in west form , but if u try to insert the value of test in db it will insert the real value ! the east form .
Sqlite3 can't recognize the east numbers , it will treat it as some char's no more !the table i'm work on it now it uses different method to insert the date it's not uses any QDateEdit ...etc .
but when i want to read i want the user insert the date from QDateEdit , but QDateEdit will use the east numbers and in the table the date column it uses west numbers ! -
What type is
date
in your database? -
@VRonin Text
-
so build it as text...
QLocale arabLocal(QLocale::Arabic); const QString dateText = arabLocal.Tostring(ui->deMonth->date().month()) + '/' + arabLocal.Tostring(ui->deMonth->date().year());
or
QLocale englLocal(QLocale::English); const QString dateText = englLocal.Tostring(ui->deMonth->date().month()) + '/' + englLocal.Tostring(ui->deMonth->date().year());
Depending on whether you want the numbers in arabic or western format
P.S.
never, ever build your queries concatenating unescaped user input. see https://www.w3schools.com/sql/sql_injection.asp -
@VRonin that's didn't work , also the output is :
"1/2,022" // the date was 01/2022
-
@MrLibya My bad:
QLocale englLocal(QLocale::English); englLocal.setNumberOptions(QLocale::OmitGroupSeparator | englLocal.numberOptions()); QString dateText = englLocal.Tostring(ui->deMonth->date().month()); if(dateText.size()==1) dateText.prepend('0'); dateText += '/' + englLocal.Tostring(ui->deMonth->date().year());
-
@VRonin Thanks too much :)
-
Actually scrap that, it's much easier, don't know what I was thinking...
const QString dateText = QLocale(QLocale::English).toString(ui->deMonth->date(),QStringLiteral("MM/yyyy"));