| 673 | } |
| 674 | |
| 675 | QStringList SQLiteDriver::tables(QSql::TableType type) const |
| 676 | { |
| 677 | QStringList res; |
| 678 | if (!isOpen()) |
| 679 | return res; |
| 680 | |
| 681 | QSqlQuery q(createResult()); |
| 682 | q.setForwardOnly(true); |
| 683 | |
| 684 | QString sql = QLatin1String("SELECT name FROM sqlite_master WHERE %1 " |
| 685 | "UNION ALL SELECT name FROM sqlite_temp_master WHERE %1"); |
| 686 | if ((type & QSql::Tables) && (type & QSql::Views)) |
| 687 | sql = sql.arg(QLatin1String("type='table' OR type='view'")); |
| 688 | else if (type & QSql::Tables) |
| 689 | sql = sql.arg(QLatin1String("type='table'")); |
| 690 | else if (type & QSql::Views) |
| 691 | sql = sql.arg(QLatin1String("type='view'")); |
| 692 | else |
| 693 | sql.clear(); |
| 694 | |
| 695 | if (!sql.isEmpty() && q.exec(sql)) { |
| 696 | while (q.next()) |
| 697 | res.append(q.value(0).toString()); |
| 698 | } |
| 699 | |
| 700 | if (type & QSql::SystemTables) { |
| 701 | // there are no internal tables beside this one: |
| 702 | res.append(QLatin1String("sqlite_master")); |
| 703 | } |
| 704 | |
| 705 | return res; |
| 706 | } |
| 707 | |
| 708 | static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool onlyPIndex = false) |
| 709 | { |