Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5b3f11b2

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 5b3f11b27bbe59a9e5b2db1b6dc1ba595e268869
  • Vorgänger 829c3e69
  • Nachfolger ed9ffe4a

find constraints

Unterschiede anzeigen:

src/schema/mysqlschema.cpp
}
void MysqlSchema::findConstraints(const QSharedPointer<TableSchema> &ts) {
// QString sql = "SHOW INDEX";
// sql += " FROM " + this->quoteSimpleTableName(table->getFullName());
// QSqlQuery q = this->database->getQuery();
// q.setForwardOnly(true);
// q.exec(sql);
QString sql =
"SELECT table_name, column_name,referenced_table_name,referenced_column_name";
sql += " FROM " + this->quoteTableName("information_schema.key_column_usage");
sql += "WHERE " + this->quoteColumnName("referenced_table_name") +
" is not null";
sql += " AND " + this->quoteColumnName("table_schema") + " = \"" +
this->getDatabase()->getDatabase().databaseName() + "\"";
sql += " AND " + this->quoteColumnName("table_name") + " = \"" + ts->getName() +
"\"";
QSqlQuery q = this->database->getQuery();
q.setForwardOnly(true);
q.exec(sql);
auto foreignKeys = ts->getRelations();
// while (q.next()) {
// bool ok;
// int id = q.value("id").toInt(&ok);
// if (ok) {
// auto rel = new QSqlRelation(q.value("table").toString(),
// q.value("from").toString(),
// q.value("to").toString());
// auto ptr = QSharedPointer<QSqlRelation>(rel);
// foreignKeys.insert(QString::number(id), ptr);
// }
// }
int id = 0;
while (q.next()) {
bool ok;
if (ok) {
auto rel = new QSqlRelation(q.value("referenced_table_name").toString(),
q.value("column_name").toString(),
q.value("referenced_column_name").toString());
auto ptr = QSharedPointer<QSqlRelation>(rel);
foreignKeys.insert(QString::number(id), ptr);
}
id++;
}
ts->setRelations(foreignKeys);
}

Auch abrufbar als: Unified diff