Difference between revisions of "Documentation/DevGuide/Database/Connection Service"
m (1 revision(s)) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/Database/XDatabaseMetaData Interface | |NextPage=Documentation/DevGuide/Database/XDatabaseMetaData Interface | ||
}} | }} | ||
− | {{DISPLAYTITLE:Connection Service}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/Database/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:Connection Service}} | ||
<!--<idltopic>com.sun.star.sdbc.Connection</idltopic>--> | <!--<idltopic>com.sun.star.sdbc.Connection</idltopic>--> | ||
The <idl>com.sun.star.sdbc.Connection</idl> is the database client side. It is responsible for the creation of the Statements and the information about the database itself. The service consists of three interfaces that have to be supported: | The <idl>com.sun.star.sdbc.Connection</idl> is the database client side. It is responsible for the creation of the Statements and the information about the database itself. The service consists of three interfaces that have to be supported: | ||
Line 34: | Line 35: | ||
<!--[SOURCE:Database/DriverSkeleton/SDriver.cxx]--> | <!--[SOURCE:Database/DriverSkeleton/SDriver.cxx]--> | ||
− | + | <syntaxhighlight lang="cpp"> | |
Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException) | Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException) | ||
{ | { | ||
Line 42: | Line 43: | ||
// create a statement | // create a statement | ||
// the statement can only be executed once | // the statement can only be executed once | ||
− | + | Reference< XStatement > xReturn = new OStatement(this); | |
m_aStatements.push_back(WeakReferenceHelper(xReturn)); | m_aStatements.push_back(WeakReferenceHelper(xReturn)); | ||
return xReturn; | return xReturn; | ||
Line 65: | Line 66: | ||
// -------------------------------------------------------------------------------- | // -------------------------------------------------------------------------------- | ||
Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& _sSql ) | Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& _sSql ) | ||
− | throw(SQLException, RuntimeException) | + | throw(SQLException, RuntimeException) |
{ | { | ||
::osl::MutexGuard aGuard( m_aMutex ); | ::osl::MutexGuard aGuard( m_aMutex ); | ||
Line 73: | Line 74: | ||
return NULL; | return NULL; | ||
} | } | ||
− | + | </syntaxhighlight> | |
All other methods can be omitted at this stage. For detailed descriptions, refer to the API Reference Manual. | All other methods can be omitted at this stage. For detailed descriptions, refer to the API Reference Manual. | ||
{{PDL1}} | {{PDL1}} | ||
− | [[Category: Database Access]] | + | |
+ | [[Category:Documentation/Developer's Guide/Database Access]] |
Latest revision as of 15:21, 21 December 2020
The com.sun.star.sdbc.Connection is the database client side. It is responsible for the creation of the Statements and the information about the database itself. The service consists of three interfaces that have to be supported:
- The interface com.sun.star.lang.XComponent that is responsible to close the connection when it is disposed.
- The interface com.sun.star.sdbc.XWarningsSupplier that controls the chaining of warnings which may occur on every call.
- The interface com.sun.star.sdbc.XConnection that is the main interface to the database.
The first two interfaces introduce some access and closing mechanisms that can be best described inside the code fragment of the Connection
class. To understand the interface com.sun.star.sdbc.XConnection, we must have a closer look at some methods. The others not described are simple enough to handle them in the code fragment.
First there is the method getMetaData()
that returns an object which implements the interface com.sun.star.sdbc.XDatabaseMetaData. This object has many methods and depends on the capabilities of the database. Most return values are found in the database documentation or in the first step, assuming some values match. The methods, such as getTables()
, getColumns()
and getTypeInfo()
are described in the next chapter.
The following methods are used to create statements. Each of them is a factory method that creates the three different kinds of statements.
Important Methods of com.sun.star.sdbc.XConnection | |
---|---|
createStatement() | Creates a new com.sun.star.sdbc.Statement object for sending SQL statements to the database. SQL statements without parameters are executed using Statement objects. |
prepareStatement(sql) | Creates a com.sun.star.sdbc.PreparedStatement object for sending parameterized SQL statements to the database. |
prepareCall(sql) | Creates a com.sun.star.sdbc.CallableStatement object for calling database stored procedures. |
Reference< XStatement > SAL_CALL OConnection::createStatement( ) throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed);
// create a statement
// the statement can only be executed once
Reference< XStatement > xReturn = new OStatement(this);
m_aStatements.push_back(WeakReferenceHelper(xReturn));
return xReturn;
}
// --------------------------------------------------------------------------------
Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( const ::rtl::OUString& _sSql )
throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed);
// the pre
if(m_aTypeInfo.empty())
buildTypeInfo();
// create a statement
// the statement can only be executed more than once
Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,m_aTypeInfo,_sSql);
m_aStatements.push_back(WeakReferenceHelper(xReturn));
return xReturn;
}
// --------------------------------------------------------------------------------
Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( const ::rtl::OUString& _sSql )
throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed);
// not implemented yet :-) a task to do
return NULL;
}
All other methods can be omitted at this stage. For detailed descriptions, refer to the API Reference Manual.
Content on this page is licensed under the Public Documentation License (PDL). |