void KexiFieldListView::setSchema(KexiDB::TableOrQuerySchema* schema) { if (schema && m_schema == schema) return; m_allColumnsItem = 0; clear(); delete m_schema; m_schema = schema; if (!m_schema) return; int order=0; bool hasPKeys = true; //t->hasPrimaryKeys(); KListViewItem *item = 0; KexiDB::QueryColumnInfo::Vector columns = m_schema->columns(true /*unique*/); const int count = columns.count(); for(int i=-1; i < count; i++) { KexiDB::QueryColumnInfo *colinfo = 0; if (i==-1) { if (! (m_options & ShowAsterisk)) continue; item = new KListViewItem(this, item, i18n("* (All Columns)")); m_allColumnsItem = item; } else { colinfo = columns[i]; item = new KListViewItem(this, item, colinfo->aliasOrName()); if (m_options & ShowDataTypes) item->setText(1, colinfo->field->typeName()); } if(colinfo && (colinfo->field->isPrimaryKey() || colinfo->field->isUniqueKey())) item->setPixmap(0, m_keyIcon); else if (hasPKeys) { item->setPixmap(0, m_noIcon); } order++; } setCurrentItem(firstChild()); }
/*! Copy MySQL table to KexiDB database */ bool MySQLMigrate::drv_copyTable(const QString& srcTable, KexiDB::Connection *destConn, KexiDB::TableSchema* dstTable) { if(d->executeSQL("SELECT * FROM `" + drv_escapeIdentifier(srcTable)) + "`") { MYSQL_RES *res = mysql_use_result(d->mysql); if (res != NULL) { MYSQL_ROW row; const KexiDB::QueryColumnInfo::Vector fieldsExpanded( dstTable->query()->fieldsExpanded() ); while ((row = mysql_fetch_row(res)) != NULL) { const int numFields = QMIN((int)fieldsExpanded.count(), (int)mysql_num_fields(res)); QValueList<QVariant> vals; unsigned long *lengths = mysql_fetch_lengths(res); if (!lengths) { mysql_free_result(res); return false; } for(int i = 0; i < numFields; i++) vals.append( KexiDB::cstringToVariant(row[i], fieldsExpanded.at(i)->field, (int)lengths[i]) ); if (!destConn->insertRecord(*dstTable, vals)) { mysql_free_result(res); return false; } updateProgress(); } if (!row && mysql_errno(d->mysql)) { mysql_free_result(res); return false; } /*! @todo Check that wasn't an error, rather than end of result set */ mysql_free_result(res); } else { kdDebug() << "MySQLMigrate::drv_copyTable: null result" << endl; } return true; } else { return false; } }