コード例 #1
0
ファイル: txtmigrate.cpp プロジェクト: crayonink/calligra-2
bool TxtMigrate::drv_readTableSchema(const QString& originalName, KexiDB::TableSchema& tableSchema)
{
  if (drv_readFromTable(originalName))
  {
    for (uint i = 0; i < (uint)m_FieldNames.count(); ++i)
    {
      tableSchema.addField( new KexiDB::Field(m_FieldNames[i], KexiDB::Field::Text) );
    }
    tableSchema.setName(originalName);
    return true;
  }
  return false;
}
コード例 #2
0
ファイル: utils.cpp プロジェクト: JeremiasE/KFormula
int KexiDB::rowCount(const KexiDB::TableSchema& tableSchema)
{
//! @todo does not work with non-SQL data sources
    if (!tableSchema.connection()) {
        KexiDBWarn << "KexiDB::rowsCount(const KexiDB::TableSchema&): no tableSchema.connection() !";
        return -1;
    }
    int count = -1; //will be changed only on success of querySingleNumber()
    tableSchema.connection()->querySingleNumber(
        QString::fromLatin1("SELECT COUNT(*) FROM ")
        + tableSchema.connection()->driver()->escapeIdentifier(tableSchema.name()),
        count
    );
    return count;
}
コード例 #3
0
//==================================================================================
//This is probably going to be quite complex...need to get the types for all columns
//any any other attributes required by kexi
//helped by reading the 'tables' test program
bool PqxxMigrate::drv_readTableSchema(
    const QString& originalName, KexiDB::TableSchema& tableSchema)
{
//    m_table = new KexiDB::TableSchema(table);

    //TODO IDEA: ask for user input for captions
//moved    m_table->setCaption(table + " table");

    //Perform a query on the table to get some data
    kDebug();
    tableSchema.setName(originalName);
    if (!query("select * from " + drv_escapeIdentifier(originalName) + " limit 1"))
        return false;
    //Loop round the fields
    for (uint i = 0; i < (uint)m_res->columns(); i++) {
        QString fldName(m_res->column_name(i));
        KexiDB::Field::Type fldType = type(m_res->column_type(i), fldName);
        QString fldID(KexiUtils::string2Identifier(fldName));
        const pqxx::oid toid = tableOid(originalName);
        if (toid == 0)
            return false;
        KexiDB::Field *f = new KexiDB::Field(fldID, fldType);
        f->setCaption(fldName);
        f->setPrimaryKey(primaryKey(toid, i));
        f->setUniqueKey(uniqueKey(toid, i));
        f->setAutoIncrement(autoInc(toid, i));//This should be safe for all field types
        tableSchema.addField(f);

        // Do this for var/char types
        //m_f->setLength(m_res->at(0)[i].size());

        // Do this for numeric type
        /*m_f->setScale(0);
        m_f->setPrecision(0);*/

        kDebug() << "Added field [" << f->name() << "] type [" << f->typeName()
        << ']';
    }
    return true;
}
コード例 #4
0
KexiTableEdit* KexiCellEditorFactory::createEditor(KexiTableViewColumn &column, QWidget* parent)
{
    KexiDB::Field *realField;
    if (column.visibleLookupColumnInfo()) {
        realField = column.visibleLookupColumnInfo()->field;
    } else {
        realField = column.field();
    }

    KexiCellEditorFactoryItem *item = 0;

    if (hasEnumType(column)) {
        //--we need to create combo box because of relationship:
        item = KexiCellEditorFactory::item(KexiDB::Field::Enum);
    } else {
        item = KexiCellEditorFactory::item(realField->type(), realField->subType());
    }

#if 0 //js: TODO LATER
    //--check if we need to create combo box because of relationship:
    //WARNING: it's assumed that indices are one-field long
    KexiDB::TableSchema *table = f.table();
    if (table) {
        //find index that contain this field
        KexiDB::IndexSchema::ListIterator it = table->indicesIterator();
        for (;it.current();++it) {
            KexiDB::IndexSchema *idx = it.current();
            if (idx->fields()->contains(&f)) {
                //find details-side rel. for this index
                KexiDB::Relationship *rel = idx->detailsRelationships()->first();
                if (rel) {

                }
            }
        }
    }
#endif

    return item->createEditor(column, parent);
}
コード例 #5
0
ファイル: keximigrate.cpp プロジェクト: JeremiasE/KFormula
    // -- read table schemas and create them in memory (only for non-KexiDB-compat tables)
    foreach(const QString& tableCaption, tables) {
        if (destDriver->isSystemObjectName(tableCaption)   //"kexi__objects", etc.
                || tableCaption.toLower().startsWith("kexi__")) //tables at KexiProject level, e.g. "kexi__blobs"
            continue;
        // this is a non-KexiDB table: generate schema from native data source
        const QString tableIdentifier(KexiUtils::string2Identifier(tableCaption));
        KexiDB::TableSchema *tableSchema = new KexiDB::TableSchema(tableIdentifier);
        tableSchema->setCaption(tableCaption);   //caption is equal to the original name

        if (!drv_readTableSchema(tableCaption, *tableSchema)) {
            delete tableSchema;
            if (result)
                result->setStatus(
                    i18n(
                        "Could not import project from data source \"%1\". Error reading table \"%2\".",
                        m_migrateData->source->serverInfoString(), tableCaption), "");
            return false;
        }
        //yeah, got a table
        //Add it to list of tables which we will create if all goes well
        m_tableSchemas.append(tableSchema);
    }
コード例 #6
0
ファイル: mdbmigrate.cpp プロジェクト: JeremiasE/KFormula
/* ************************************************************************** */
bool MDBMigrate::drv_readTableSchema(const QString& originalName,
                                     KexiDB::TableSchema& tableSchema)
{
    // Get the column meta-data
    MdbTableDef *tableDef = getTableDef(originalName);
    if (!tableDef) {
        kDebug() << "MDBMigrate::drv_getTableDef: couldn't find table "
        << originalName;
        return false;
    }
    mdb_read_columns(tableDef);
    kDebug() << "MDBMigrate::drv_readTableSchema: #cols = "
    << tableDef->num_cols;

    /*! Convert column data to Kexi TableSchema
        Nice mix of terminology here, MDBTools has columns, Kexi has fields. */
    MdbColumn *col;
    for (unsigned int i = 0; i < tableDef->num_cols; i++) {
        col = (MdbColumn*) g_ptr_array_index(tableDef->columns, i);

        // Field name
        QString fldName = QString::fromUtf8(col->name);
        kDebug() << "MDBMigrate::drv_readTableSchema: got column "
        << fldName << "\"" << col->name;

        QString fldID(KexiUtils::string2Identifier(fldName));

        // Field type
        KexiDB::Field *fld =
            new KexiDB::Field(fldID, type(col->col_type));

        kDebug() << "MDBMigrate::drv_readTableSchema: size "
        << col->col_size << " type " << type(col->col_type);
        fld->setCaption(fldName);
        tableSchema.addField(fld);
    }

    getPrimaryKey(&tableSchema, tableDef);

    // Free the column meta-data - as soon as it doesn't seg fault.
    //mdb_free_tabledef(tableDef);

    return true;
}
コード例 #7
0
/*! Get the types and properties for each column. */
bool MySQLMigrate::drv_readTableSchema(
	const QString& originalName, KexiDB::TableSchema& tableSchema)
{
//	m_table = new KexiDB::TableSchema(table);

//	//TODO IDEA: ask for user input for captions
//	tableSchema.setCaption(table + " table");

	//Perform a query on the table to get some data
	QString query = QString("SELECT * FROM `") + drv_escapeIdentifier(originalName) + "` LIMIT 0";
	if(d->executeSQL(query)) {
		MYSQL_RES *res = mysql_store_result(d->mysql);
		if (res != NULL) {
		
			unsigned int numFlds = mysql_num_fields(res);
			MYSQL_FIELD *fields = mysql_fetch_fields(res); 
			
			for(unsigned int i = 0; i < numFlds; i++) {
				QString fldName(fields[i].name);
				QString fldID( KexiUtils::string2Identifier(fldName) );

				KexiDB::Field *fld = 
				  new KexiDB::Field(fldID, type(originalName, &fields[i]));
				
				if(fld->type() == KexiDB::Field::Enum) {
					QStringList values = examineEnumField(originalName, &fields[i]);
				}
				
				fld->setCaption(fldName);
				getConstraints(fields[i].flags, fld);
				getOptions(fields[i].flags, fld);
				tableSchema.addField(fld);
			}
			mysql_free_result(res);
		} else {
			kdDebug() << "MySQLMigrate::drv_tableNames: null result" << endl;
		}
		return true;
	} else {
	  return false;
	}
}
コード例 #8
0
bool OdbMigrate::drv_readTableSchema(
    const QString& originalName, KexiDB::TableSchema& tableSchema)
{
    char* tableName=originalName.toAscii().data();
    jmethodID getTableNames = env->GetMethodID(clsH,"getTableSchema","(Ljava/lang/String;)Ljava/lang/String;");
    jstring returnString = (jstring) env->CallObjectMethod(java_class_object,getTableNames,tableName);
    const char* tablesstring = env->GetStringUTFChars(returnString, NULL);
    QString jsonString(tablesstring);
    QStringList list = jsonString.split(",");

    for(int i=0;i<list.size();i+=2)
    {
        QString fldID(KexiUtils::stringToIdentifier(list.at(i+1)));
        KexiDB::Field *fld =
            new KexiDB::Field(fldID, type(list.at(i+1)));
        fld->setCaption(list.at(i));
        tableSchema.addField(fld);
    }

    return false;
}