当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlIndex::contains方法代码示例

本文整理汇总了C++中QSqlIndex::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlIndex::contains方法的具体用法?C++ QSqlIndex::contains怎么用?C++ QSqlIndex::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSqlIndex的用法示例。


在下文中一共展示了QSqlIndex::contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: LoadTableColumns

void ODBC_Connection::LoadTableColumns(QTreeWidgetItem *item)
{
	for (int i = 0, count = item->childCount(); i < count; i++)
		item->removeChild(item->child(0));
		
	QString sTableName = item->text(0);

	if (m_db.isOpen())
	{
		if (!m_db.tables().contains(sTableName)) // if it isnt a table, return
			return;

		// set wait cursor
		QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
		QApplication::processEvents();
		Logging::getInstance()->WriteLog(INFORMATION, QString("Retrieving tableinfo for table \"%1\" of connection \"%2\"...").arg(sTableName, m_sConnectionName));
		bool bTableWarningShown = false;
		QSqlRecord records = m_db.record(sTableName);
		QSqlField field;
		QSqlIndex index = m_db.primaryIndex(sTableName);
		QString sName;
		QSqlQuery query;
		QString sTypeName;
		QString sLength;
		QString sNullable;
		for (int i = 0, count = records.count(); i < count; i++)
		{
			field = records.field(i);
			sName = field.name();
			query = m_db.exec(QString("SELECT DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = '%1' AND TABLE_NAME = '%2'").arg(sName, sTableName));
			if (query.next())
			{
				sTypeName = query.value(0).toString();
				sLength = query.value(1).toString() != "0" ? query.value(1).toString() : query.value(2).toString();
				sNullable = query.value(3).toString();
				query.finish();
			}
			else
			{
				if (!bTableWarningShown)
				{	
					Logging::getInstance()->WriteLog(WARNING, QString("Couldn't retrieve fieldinfo for table \"%1\" of connection \"%2\", database INFORMATION_SCHEMA.COLUMNS doesn't exist, starting fallback to manual type detection").arg(sTableName, m_sConnectionName));
					#ifdef _DEBUG
					qDebug() << QString("Couldn't retrieve fieldinfo for table \"%1\" of connection \"%2\", database INFORMATION_SCHEMA.COLUMNS doesn't exist, starting fallback to manual type detection").arg(sTableName, m_sConnectionName);
					#endif
					bTableWarningShown = true;
				}
				sTypeName = QVariant::typeToName(field.type());
				sLength = QString().setNum(field.length());
				sNullable = (field.requiredStatus() == 1 ? "YES" : "NO");
			}
			bool isPrimaryKey = index.contains(sName) ? true : false;
			QTreeWidgetItem *pItem = new QTreeWidgetItem();
			if (isPrimaryKey)
			{
				pItem->setText(0, QString("%1 (PS, %2(%3), %4)").arg(sName, sTypeName, sLength, (sNullable == "YES" ? "NULL" : "NOT NULL")));
				pItem->setIcon(0, QIcon(":/ODBC_Query/Resources/primary_key.png"));
			}
			else
			{
				pItem->setText(0, QString("%1 (%2(%3), %4)").arg(sName, sTypeName, sLength, (sNullable == "YES" ? "NULL" : "NOT NULL")));
				pItem->setIcon(0, QIcon(":/ODBC_Query/Resources/row.png"));
			}
			item->addChild(pItem);
		}
		m_ui.TableTreeWidget->expandItem(item);
		Logging::getInstance()->WriteLog(INFORMATION, QString("Tableinfo for table \"%1\" of connection \"%2\" retrieved").arg(sTableName, m_sConnectionName));
	}
	else
	{
		Logging::getInstance()->WriteLog(ERR, QString("Couldn't retrieve tableinfo for table \"%1\" of connection \"%2\", connection isn't open").arg(sTableName, m_sConnectionName));
		#ifdef _DEBUG
		qDebug() << QString("Couldn't retrieve tableinfo for table \"%1\" of connection \"%2\", connection isn't open").arg(sTableName, m_sConnectionName);
		#endif
	}
	// set back to arrow cursor
	QApplication::restoreOverrideCursor();
}
开发者ID:Edder,项目名称:odbc-query,代码行数:78,代码来源:ODBC_Connection.cpp


注:本文中的QSqlIndex::contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。