[Qt-interest] Adding Boolean to QSqlDriver?

Jason H scorp1us at yahoo.com
Tue Aug 2 21:09:36 CEST 2011


SqlLite only knows strings, but can parse them to be numbers or other data types.
PostgreSQL stores it as a character, with {T,t,1,Y,y} = true and {F,f,0,N,n} = false, so you can use "= true" in a query and it'll treat it as a boolean. And I think there is your problem. If you treat it as a bool, then it has to be handled that way at the SQL level otherwise people will write bad queries.


What about a bit type like in SqlServer?

I think the best best is defining a const char dbTrue and dBFalse ('1', '0') respectively and just using bindValue("mybool", chkBox.isChecked() ?dbTrue : dbFalse); // works for select, insert, update, and delete


chkBox.setChecked(row[0].toBool()); // QVariant returns true always except when lower case content is empty, "0" or "false";

Bools don't have to be hard, just consistent.


________________________________
From: "3dw4rd at verizon.net" <3dw4rd at verizon.net>
To: qt-interest at qt.nokia.com
Sent: Tuesday, August 2, 2011 2:43 PM
Subject: [Qt-interest] Adding Boolean to QSqlDriver?

Greetings,

I have an application that supports SQLite, Postgres, and Oracle.  I have a database schema that uses boolean for Postgres and Oracle but uses integer for SQLite because the latter does not have boolean.

If I had a QSqlDriver::Boolean it would be easy to test if the current driver had boolean in my delegate.  Then for SQLite I could maybe show false/true instead of 0/1.  I could use a QCheckBox or a QComboBox (which is the default for drivers which support boolean) instead of a QSpinBox with no checking.

I know I could just but a check for SQLite but I think this is more general.  Is SQLite te only one with a missing Boolean?  What If I want to use MySQL.  It would be nice to have a high level library solution.

How do other people feel about this?  Is there any chance of this happening?

Ed

_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110802/383879d1/attachment.html 


More information about the Qt-interest-old mailing list