#i105825# throw exception when database was written by newer version

This commit is contained in:
Ocke Janssen 2009-10-13 06:40:52 +00:00
parent 4b3b7e709b
commit ad7c9894af
4 changed files with 50 additions and 0 deletions

View file

@ -55,6 +55,7 @@
#include <connectivity/dbexception.hxx>
#include <comphelper/namedvaluecollection.hxx>
#include <unotools/confignode.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include "resource/hsqldb_res.hrc"
#include "resource/sharedresources.hxx"
@ -70,6 +71,8 @@ namespace connectivity
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::embed;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::task;
using namespace ::com::sun::star::reflection;
namespace hsqldb
@ -260,6 +263,46 @@ namespace connectivity
);
aProperties.put( "SystemProperties", Sequence< NamedValue >( &aPermittedClasses, 1 ) );
::rtl::OUString sProperties( RTL_CONSTASCII_USTRINGPARAM( "properties" ) );
try
{
if ( !bIsNewDatabase && xStorage->isStreamElement(sProperties) )
{
Reference<XStream > xStream = xStorage->openStreamElement(sProperties,ElementModes::READ);
if ( xStream.is() )
{
::std::auto_ptr<SvStream> pStream( ::utl::UcbStreamHelper::CreateStream(xStream) );
if ( pStream.get() )
{
ByteString sLine;
while ( pStream->ReadLine(sLine) )
{
if ( sLine.Equals("version=",0,sizeof("version=")-1) )
{
sLine = sLine.GetToken(1,'=');
const sal_Int32 nMajor = sLine.GetToken(0,'.').ToInt32();
const sal_Int32 nMinor = sLine.GetToken(1,'.').ToInt32();
const sal_Int32 nMicro = sLine.GetToken(2,'.').ToInt32();
if ( nMajor > 1
|| ( nMajor == 1 && nMinor > 8 )
|| ( nMajor == 1 && nMinor == 8 && nMicro > 0 ) )
{
::connectivity::SharedResources aResources;
const ::rtl::OUString sMessage = aResources.getResourceString(STR_ERROR_NEW_VERSION);
::dbtools::throwGenericSQLException(sMessage ,*this);
}
break;
}
}
}
} // if ( xStream.is() )
::comphelper::disposeComponent(xStream);
}
}
catch(Exception&)
{
}
// readonly?
Reference<XPropertySet> xProp(xStorage,UNO_QUERY);
if ( xProp.is() )

View file

@ -102,6 +102,7 @@ SHL1STDLIBS=\
$(DBTOOLSLIB) \
$(JVMFWKLIB) \
$(COMPHELPERLIB) \
$(TOOLSLIB) \
$(UNOTOOLSLIB)

View file

@ -44,6 +44,7 @@
#define STR_NO_TABLE_EDITOR_DIALOG ( STR_HSQLDB_BASE + 3 )
#define STR_NO_TABLENAME ( STR_HSQLDB_BASE + 4 )
#define STR_NO_DOCUMENTUI ( STR_HSQLDB_BASE + 5 )
#define STR_ERROR_NEW_VERSION ( STR_HSQLDB_BASE + 6 )
#endif // CONNECTIVITY_RESOURCE_HSQLDB_HRC

View file

@ -645,3 +645,8 @@ String STR_NO_DOCUMENTUI
{
Text [ en-US ] = "The provided DocumentUI is not allowed to be NULL.";
};
String STR_ERROR_NEW_VERSION
{
Text = "The connection could not be established. The database was created by a newer version of %PRODUCTNAME.";
};