/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// we need to create the sql stmt with column names // otherwise it is possible that names don't match const OUString sQuote = m_xMetaData->getIdentifierQuoteString();
Sequence< OUString > aColumnNames = getColumnNames(); for (sal_Int32 i = 0; i < aColumnNames.getLength(); ++i)
{ if (i > 0)
aSQL.append(", ");
aSQL.append(::dbtools::quoteName(sQuote, aColumnNames[i]));
}
aSQL.append( " FROM " + ::dbtools::composeTableNameForSelect( m_xConnection, m_xObject ) );
void NamedTableCopySource::copyUISettingsTo( const Reference< XPropertySet >& /*_rxObject*/ ) const
{ // not supported: we do not have UI settings to copy
}
sal_Int32 nColCount( xStatementMeta->getColumnCount() ); for ( sal_Int32 i = 1; i <= nColCount; ++i )
{
OFieldDescription aDesc;
aDesc.SetName( xStatementMeta->getColumnName( i ) );
aDesc.SetHelpText( xStatementMeta->getColumnLabel( i ) );
aDesc.SetTypeValue( xStatementMeta->getColumnType( i ) );
aDesc.SetTypeName( xStatementMeta->getColumnTypeName( i ) );
aDesc.SetPrecision( xStatementMeta->getPrecision( i ) );
aDesc.SetScale( xStatementMeta->getScale( i ) );
aDesc.SetIsNullable( xStatementMeta->isNullable( i ) );
aDesc.SetCurrency( xStatementMeta->isCurrency( i ) );
aDesc.SetAutoIncrement( xStatementMeta->isAutoIncrement( i ) );
OUString DummyCopySource::getQualifiedObjectName() const
{
SAL_WARN("dbaccess.ui", "DummyCopySource::getQualifiedObjectName: not to be called!" ); return OUString();
}
bool DummyCopySource::isView() const
{
SAL_WARN("dbaccess.ui", "DummyCopySource::isView: not to be called!" ); returnfalse;
}
void DummyCopySource::copyUISettingsTo( const Reference< XPropertySet >& /*_rxObject*/ ) const
{ // no support
}
Sequence< OUString > DummyCopySource::getPrimaryKeyColumnNames() const
{
SAL_WARN("dbaccess.ui", "DummyCopySource::getPrimaryKeyColumnNames: not to be called!" ); return Sequence< OUString >();
}
OFieldDescription* DummyCopySource::createFieldDescription( const OUString& /*_rColumnName*/ ) const
{
SAL_WARN("dbaccess.ui", "DummyCopySource::createFieldDescription: not to be called!" ); return nullptr;
}
OUString DummyCopySource::getSelectStatement() const
{
SAL_WARN("dbaccess.ui", "DummyCopySource::getSelectStatement: not to be called!" ); return OUString();
}
::utl::SharedUNOComponent< XPreparedStatement > DummyCopySource::getPreparedSelectStatement() const
{
SAL_WARN("dbaccess.ui", "DummyCopySource::getPreparedSelectStatement: not to be called!" ); return ::utl::SharedUNOComponent< XPreparedStatement >();
}
bool bAllowViews = true; // if the source is a, don't allow creating views if ( m_rSourceObject.isView() )
bAllowViews = false; // no views if the target connection does not support creating them if ( !lcl_canCreateViewFor_nothrow( m_xDestConnection ) )
bAllowViews = false; // no views if we're copying to a different database if ( !lcl_sameConnection_throw( _xSourceConnection, m_xDestConnection ) )
bAllowViews = false;
if (!m_vDestColumns.empty()) // source is a html or rtf table
m_xAssistant->change_default_widget(nullptr, m_xNextPage.get()); else
m_xAssistant->change_default_widget(nullptr, m_xFinish.get());
OSL_ENSURE( m_xDestConnection.is(), "OCopyTableWizard::CheckColumns: No connection!"); // If database is able to process PrimaryKeys, set PrimaryKey if ( m_xDestConnection.is() )
{ bool bPKeyAllowed = supportsPrimaryKey();
bool bContainsColumns = !m_vDestColumns.empty();
if ( bPKeyAllowed && shouldCreatePrimaryKey() )
{ // add extra column for the primary key
TOTypeInfoSP pTypeInfo = queryPrimaryKeyType(m_aDestTypeInfo); if ( pTypeInfo )
{ if ( m_bAddPKFirstTime )
{ // tdf#114955: since we chose to create a primary key // be sure all other columns won't be in primary key for (autoconst& elem : m_vDestColumns)
elem.second->SetPrimaryKey(false);
OFieldDescription* pField = new OFieldDescription();
pField->SetName(m_aKeyName);
pField->FillFromTypeInfo(pTypeInfo,true,true);
pField->SetAutoIncrement(pTypeInfo->bAutoIncrement);
pField->SetPrimaryKey(true);
m_bAddPKFirstTime = false;
insertColumn(0,pField);
}
m_vColumnPositions.emplace_back(1,1);
m_vColumnTypes.push_back(pTypeInfo->nType);
}
}
if ( bContainsColumns )
{ // we have dest columns so look for the matching column for (autoconst& elemSource : m_vSourceVec)
{
ODatabaseExport::TColumns::const_iterator aDestIter = m_vDestColumns.find(m_mNameMapping[elemSource->first]);
void OCopyTableWizard::CheckButtons()
{ if(GetCurLevel() == 0) // the first page has no back button
{ if(m_nPageCount > 1)
m_xNextPage->set_sensitive(true); else
m_xNextPage->set_sensitive(false);
m_xPrevPage->set_sensitive(false);
} elseif(GetCurLevel() == m_nPageCount-1) // the last page has no next button
{
m_xNextPage->set_sensitive(false);
m_xPrevPage->set_sensitive(true);
} else
{
m_xPrevPage->set_sensitive(true); // next already has its state
}
}
void OCopyTableWizard::replaceColumn(sal_Int32 _nPos,OFieldDescription* _pField,const OUString& _sOldName)
{
OSL_ENSURE(_pField,"FieldDescrioption is null!"); if ( _pField )
{
m_vDestColumns.erase(_sOldName);
OSL_ENSURE( m_vDestColumns.find(_pField->GetName()) == m_vDestColumns.end(),"Column with that name already exist!");
OFieldDescription* pActFieldDescr = nullptr; static constexpr OUStringLiteral sCreateParam(u"x"); // ReadOnly-Flag // On drop no line must be editable. // On add only empty lines must be editable. // On Add and Drop all lines can be edited. for (auto& column : _rSourceObject.getColumnNames())
{ // get the properties of the column
pActFieldDescr = _rSourceObject.createFieldDescription(column);
OSL_ENSURE( pActFieldDescr, "OCopyTableWizard::loadData: illegal field description!" ); if ( !pActFieldDescr ) continue;
xAppend->appendByDescriptor(xColumn);
xColumn = nullptr; // now only the settings are missing if(xColumns->hasByName(pField->GetName()))
{
xColumn.set(xColumns->getByName(pField->GetName()),UNO_QUERY);
OSL_ENSURE(xColumn.is(),"OCopyTableWizard::appendColumns: Column is NULL!"); if ( xColumn.is() )
pField->copyColumnSettingsTo(xColumn);
} else
{
SAL_WARN("dbaccess.ui", "OCopyTableWizard::appendColumns: invalid field name!");
}
Reference< XPropertySet > OCopyTableWizard::createView() const
{
OUString sCommand( m_rSourceObject.getSelectStatement() );
OSL_ENSURE( !sCommand.isEmpty(), "OCopyTableWizard::createView: no statement in the source object!" ); // there are legitimate cases in which getSelectStatement does not provide a statement, // but in all those cases, this method here should never be called. return ::dbaui::createView( m_sName, m_xDestConnection, sCommand );
}
if ( sSchema.isEmpty() && xMetaData->supportsSchemasInTableDefinitions() )
{ // query of current schema is quite inconsistent. In case of some // DBMS's each user has their own schema.
sSchema = xMetaData->getUserName(); // In case of mysql it is not that simple if(xMetaData->getDatabaseProductName() == "MySQL")
{
Reference< XStatement > xSelect = m_xDestConnection->createStatement();
Reference< XResultSet > xRs = xSelect->executeQuery(u"select database()"_ustr);
(void)xRs->next(); // first and only result
Reference< XRow > xRow( xRs, UNO_QUERY_THROW );
sSchema = xRow->getString(1);
}
}
while(_rCmpFunctor(sName))
{
sName = sAlias + OUString::number(++nPos);
}
sAlias = sName; // we have to check again, it could happen that the name is already too long
} while(_nMaxNameLen && sAlias.getLength() > _nMaxNameLen);
}
OSL_ENSURE(m_mNameMapping.find(_sColumnName) == m_mNameMapping.end(),"name doubled!");
m_mNameMapping[_sColumnName] = sAlias; return sAlias;
}
TOTypeInfoSP OCopyTableWizard::convertType(const TOTypeInfoSP& _pType, bool& _bNotConvert)
{ if ( !m_bInterConnectionCopy ) // no need to convert if the source and destination connection are the same return _pType;
bool bForce;
TOTypeInfoSP pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,_pType->nType,_pType->aTypeName,_pType->aCreateParams,_pType->nPrecision,_pType->nMaximumScale,_pType->bAutoIncrement,bForce); if ( !pType || bForce )
{ // no type found so we have to find the correct one ourself
sal_Int32 nDefaultType = DataType::VARCHAR; switch(_pType->nType)
{ case DataType::TINYINT: if(supportsType(DataType::SMALLINT,nDefaultType)) break;
[[fallthrough]]; case DataType::SMALLINT: if(supportsType(DataType::INTEGER,nDefaultType)) break;
[[fallthrough]]; case DataType::INTEGER: if(supportsType(DataType::FLOAT,nDefaultType)) break;
[[fallthrough]]; case DataType::FLOAT: if(supportsType(DataType::REAL,nDefaultType)) break;
[[fallthrough]]; case DataType::DATE: case DataType::TIME: if( DataType::DATE == _pType->nType || DataType::TIME == _pType->nType )
{ if(supportsType(DataType::TIMESTAMP,nDefaultType)) break;
}
[[fallthrough]]; case DataType::TIMESTAMP: case DataType::REAL: case DataType::BIGINT: if ( supportsType(DataType::DOUBLE,nDefaultType) ) break;
[[fallthrough]]; case DataType::DOUBLE: if ( supportsType(DataType::NUMERIC,nDefaultType) ) break;
[[fallthrough]]; case DataType::NUMERIC:
supportsType(DataType::DECIMAL,nDefaultType); break; case DataType::DECIMAL: if ( supportsType(DataType::NUMERIC,nDefaultType) ) break; if ( supportsType(DataType::DOUBLE,nDefaultType) ) break; break; case DataType::VARCHAR: if ( supportsType(DataType::LONGVARCHAR,nDefaultType) ) break; break; case DataType::LONGVARCHAR: if ( supportsType(DataType::CLOB,nDefaultType) ) break; break; case DataType::BINARY: if ( supportsType(DataType::VARBINARY,nDefaultType) ) break; break; case DataType::VARBINARY: if ( supportsType(DataType::LONGVARBINARY,nDefaultType) ) break; break; case DataType::LONGVARBINARY: if ( supportsType(DataType::BLOB,nDefaultType) ) break; if ( supportsType(DataType::LONGVARCHAR,nDefaultType) ) break; if ( supportsType(DataType::CLOB,nDefaultType) ) break; break; default:
nDefaultType = DataType::VARCHAR;
}
pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,nDefaultType,_pType->aTypeName,_pType->aCreateParams,_pType->nPrecision,_pType->nMaximumScale,_pType->bAutoIncrement,bForce); if ( !pType )
{
_bNotConvert = false;
pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,DataType::VARCHAR,_pType->aTypeName,u"x"_ustr,50,0,false,bForce); if ( !pType )
pType = m_pTypeInfo;
} elseif ( bForce )
_bNotConvert = false;
} return pType;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.24Bemerkung:
(vorverarbeitet am 2026-06-07)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.