Changeset View
Changeset View
Standalone View
Standalone View
src/KDb.cpp
Show First 20 Lines • Show All 593 Lines • ▼ Show 20 Line(s) | 593 | { | |||
---|---|---|---|---|---|
594 | ConnectionTestDialog dlg(data, msgHandler, parent); | 594 | ConnectionTestDialog dlg(data, msgHandler, parent); | ||
595 | const int result = dlg.exec(); | 595 | const int result = dlg.exec(); | ||
596 | if (dlg.wasCanceled()) { | 596 | if (dlg.wasCanceled()) { | ||
597 | return cancelled; | 597 | return cancelled; | ||
598 | } | 598 | } | ||
599 | return result == QDialog::Accepted; | 599 | return result == QDialog::Accepted; | ||
600 | } | 600 | } | ||
601 | 601 | | |||
602 | int KDb::recordCount(KDbConnection* conn, const KDbEscapedString& sql) | | |||
603 | { | | |||
604 | int count = -1; //will be changed only on success of querySingleNumber() | | |||
605 | if (conn) { | | |||
606 | (void)conn->querySingleNumber( | | |||
607 | KDbEscapedString("SELECT COUNT() FROM (") + sql + ") AS kdb__subquery", &count); | | |||
608 | } | | |||
609 | return count; | | |||
610 | } | | |||
611 | | ||||
612 | int KDb::recordCount(const KDbTableSchema& tableSchema) | | |||
613 | { | | |||
614 | //! @todo does not work with non-SQL data sources | | |||
615 | if (!tableSchema.connection()) { | | |||
616 | kdbWarning() << "no tableSchema.connection()"; | | |||
617 | return -1; | | |||
618 | } | | |||
619 | int count = -1; //will be changed only on success of querySingleNumber() | | |||
620 | tableSchema.connection()->querySingleNumber( | | |||
621 | KDbEscapedString("SELECT COUNT(*) FROM ") | | |||
622 | + tableSchema.connection()->escapeIdentifier(tableSchema.name()), | | |||
623 | &count | | |||
624 | ); | | |||
625 | return count; | | |||
626 | } | | |||
627 | | ||||
628 | int KDb::recordCount(KDbQuerySchema* querySchema, const QList<QVariant>& params) | | |||
629 | { | | |||
630 | //! @todo does not work with non-SQL data sources | | |||
631 | if (!querySchema->connection()) { | | |||
632 | kdbWarning() << "no querySchema->connection()"; | | |||
633 | return -1; | | |||
634 | } | | |||
635 | int count = -1; //will be changed only on success of querySingleNumber() | | |||
636 | KDbNativeStatementBuilder builder(querySchema->connection()); | | |||
637 | KDbEscapedString subSql; | | |||
638 | if (!builder.generateSelectStatement(&subSql, querySchema, params)) { | | |||
639 | return -1; | | |||
640 | } | | |||
641 | tristate result = querySchema->connection()->querySingleNumber( | | |||
642 | KDbEscapedString("SELECT COUNT(*) FROM (") + subSql + ") AS kdb__subquery", &count | | |||
643 | ); | | |||
644 | return true == result ? count : -1; | | |||
645 | } | | |||
646 | | ||||
647 | int KDb::recordCount(KDbTableOrQuerySchema* tableOrQuery, const QList<QVariant>& params) | | |||
648 | { | | |||
649 | if (tableOrQuery) { | | |||
650 | if (tableOrQuery->table()) | | |||
651 | return recordCount(*tableOrQuery->table()); | | |||
652 | if (tableOrQuery->query()) | | |||
653 | return recordCount(tableOrQuery->query(), params); | | |||
654 | } | | |||
655 | return -1; | | |||
656 | } | | |||
657 | | ||||
658 | int KDb::fieldCount(KDbTableOrQuerySchema* tableOrQuery) | | |||
659 | { | | |||
660 | if (tableOrQuery) { | | |||
661 | if (tableOrQuery->table()) | | |||
662 | return tableOrQuery->table()->fieldCount(); | | |||
663 | if (tableOrQuery->query()) | | |||
664 | return tableOrQuery->query()->fieldsExpanded().count(); | | |||
665 | } | | |||
666 | return -1; | | |||
667 | } | | |||
668 | | ||||
669 | bool KDb::splitToTableAndFieldParts(const QString& string, | 602 | bool KDb::splitToTableAndFieldParts(const QString& string, | ||
670 | QString *tableName, QString *fieldName, | 603 | QString *tableName, QString *fieldName, | ||
671 | SplitToTableAndFieldPartsOptions option) | 604 | SplitToTableAndFieldPartsOptions option) | ||
672 | { | 605 | { | ||
673 | if (!tableName || !fieldName) { | 606 | if (!tableName || !fieldName) { | ||
674 | return false; | 607 | return false; | ||
675 | } | 608 | } | ||
676 | const int id = string.indexOf(QLatin1Char('.')); | 609 | const int id = string.indexOf(QLatin1Char('.')); | ||
▲ Show 20 Lines • Show All 1620 Lines • Show Last 20 Lines |