|
|
|
@ -523,43 +523,40 @@ tristate PqxxMigrate::drv_fetchRecordFromSQL(const TQString& sqlStatement,
|
|
|
|
|
bool PqxxMigrate::drv_copyTable(const TQString& 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.latin1()));
|
|
|
|
|
|
|
|
|
|
//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)
|
|
|
|
|
if (query(TQString("SELECT * FROM ") + srcTable.latin1()))
|
|
|
|
|
{
|
|
|
|
|
TQValueList<TQVariant> 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()).lower() == "t" ? TQVariant(true) : TQVariant(false));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vals.append( KexiDB::cstringToVariant((*i).c_str(),
|
|
|
|
|
fieldsExpanded.at(index)->field, (*i).size()) );
|
|
|
|
|
}
|
|
|
|
|
pqxx::work T(*m_conn, "PqxxMigrate::drv_copyTable");
|
|
|
|
|
|
|
|
|
|
//Loop round each row, reading into a vector of strings
|
|
|
|
|
const KexiDB::QueryColumnInfo::Vector fieldsExpanded( dstTable->query()->fieldsExpanded() );
|
|
|
|
|
for (pqxx::result::const_iterator rowIt = m_res->begin(); rowIt != m_res->end(); ++rowIt)
|
|
|
|
|
{
|
|
|
|
|
TQValueList<TQVariant> vals;
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (int i = 0; i < rowIt.size(); ++i, index++)
|
|
|
|
|
{
|
|
|
|
|
if (fieldsExpanded.at(index)->field->type()==KexiDB::Field::BLOB ||
|
|
|
|
|
fieldsExpanded.at(index)->field->type()==KexiDB::Field::LongText)
|
|
|
|
|
{
|
|
|
|
|
vals.append(KexiDB::pgsqlByteaToByteArray(rowIt.at(i).c_str(), rowIt.at(i).size()));
|
|
|
|
|
}
|
|
|
|
|
else if (fieldsExpanded.at(index)->field->type()==KexiDB::Field::Boolean)
|
|
|
|
|
{
|
|
|
|
|
vals.append(TQString(rowIt.at(i).c_str()).lower() == "t" ? TQVariant(true) : TQVariant(false));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vals.append(KexiDB::cstringToVariant(rowIt.at(i).c_str(), fieldsExpanded.at(index)->field, rowIt.at(i).size()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!destConn->insertRecord(*dstTable, vals))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
updateProgress();
|
|
|
|
|
}
|
|
|
|
|
if (!destConn->insertRecord(*dstTable, vals))
|
|
|
|
|
return false;
|
|
|
|
|
updateProgress();
|
|
|
|
|
R.clear();
|
|
|
|
|
m_res->clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//This does not work in <libpqxx 2.2
|
|
|
|
|
//stream.complete();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|