1

i'm looking for a way to retrieve real database type name from qtsql model.

Unfortunately

QVariant::typeToName(field.type())

Where field is QSqlField type

gives me already mapped type to some Qt type. Is it possible to get real names using Qt?

floreks
  • 33
  • 3

1 Answers1

0

i found a way to retrieve the real database type with following query:

QSqlQuery query("PRAGMA table_info(tableName)");

As a result you will get:

cid|name                 |type         |notnull |dflt_value |pk
0  |id                   |integer      |0       |           |1
1  |name                 |varchar(45)  |1       |           |0

thanks to this post: Getting the type of a column in SQLite

Hope this helps

Community
  • 1
  • 1
farukg
  • 523
  • 4
  • 12
  • I'm aware of using sqlquery to retrieve data from base but i was trying to get it without actually using SQL. Anyway, I've built my own interface on top of QtSQL to retrieve that information from database, because i needed a way to work with multiple drivers. Every driver has it's own class to get this data. For MySQL it is not that simple as it is in SQLite. Thx for trying ;) – floreks Mar 27 '14 at 12:18
  • Oh I see, my answer was short-sighted because I had the same problem but only for sqlite, I didn't even think of other drivers :) is your solution open-source? ;) – farukg Mar 27 '14 at 22:46
  • 1
    Actually it is part on my Engineering Thesis. Small ORM generating C++ DAO based on existing database. Here: https://github.com/Krycho/Qubic/tree/master/qubic/src/QcUtility/database you can find my solution. For now it's only for 1 driver but can be easly extended. – floreks Mar 28 '14 at 07:06