QStringList KexiMigrateReportData::fieldNames() const
{
    KexiDB::QueryColumnInfo::Vector flds;
    QStringList names;

    if (d->schema) {
        flds = d->schema->columns();

        for (int i = 0; i < flds.size() ; ++i) {
            names << flds[i]->field->name();
        }
    }
    return names;
}
int KexiMigrateReportData::fieldNumber(const QString &fld) const
{
    KexiDB::QueryColumnInfo::Vector flds;

    uint x = -1;

    if (d->schema) {
        flds = d->schema->columns();

        for (int i = 0; i < flds.size() ; ++i) {
            if (fld.toLower() == flds[i]->aliasOrName().toLower()) {
                x = i;
            }
        }
    }
    return x;
}
Example #3
0
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());
}
Example #4
0
/*! 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;
	}
}
Example #5
0
/*! Copy PostgreSQL table to KexiDB database */
bool PqxxMigrate::drv_copyTable(const QString& srcTable, KexiDB::Connection *destConn,
                                KexiDB::TableSchema* dstTable)
{
    std::vector<std::string> R;

    pqxx::work T(*m_conn, "PqxxMigrate::drv_copyTable");

    pqxx::tablereader stream(T, (srcTable.toLatin1().constData()));

    //Loop round each row, reading into a vector of strings
    const KexiDB::QueryColumnInfo::Vector fieldsExpanded(dstTable->query()->fieldsExpanded());
    for (int n = 0; (stream >> R); ++n) {
        QList<QVariant> vals;
        std::vector<std::string>::const_iterator i, end(R.end());
        int index = 0;
        for (i = R.begin(); i != end; ++i, index++) {
            if (fieldsExpanded.at(index)->field->type() == KexiDB::Field::BLOB
                    || fieldsExpanded.at(index)->field->type() == KexiDB::Field::LongText) {
                vals.append(KexiDB::pgsqlByteaToByteArray((*i).c_str(), (*i).size()));
            } else if (fieldsExpanded.at(index)->field->type() == KexiDB::Field::Boolean) {
                vals.append(QString((*i).c_str()).toLower() == "t" ? QVariant(true) : QVariant(false));
            } else
                vals.append(KexiDB::cstringToVariant((*i).c_str(),
                                                     fieldsExpanded.at(index)->field, (*i).size()));
        }
        if (!destConn->insertRecord(*dstTable, vals))
            return false;
        updateProgress();
        R.clear();
    }

    //This does not work in <libpqxx 2.2
    //stream.complete();

    return true;
}