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; }
//================================================================================== //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; }