1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef CONNECTIVITY_MYSQL_TABLE_HXX
29 #define CONNECTIVITY_MYSQL_TABLE_HXX
30 
31 #include "connectivity/TTableHelper.hxx"
32 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
33 #include <comphelper/IdPropArrayHelper.hxx>
34 
35 namespace connectivity
36 {
37 	namespace mysql
38 	{
39 
40         ::rtl::OUString getTypeString(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xColProp);
41 
42 		class OMySQLTable;
43 		typedef ::comphelper::OIdPropertyArrayUsageHelper< OMySQLTable >	OMySQLTable_PROP;
44 		class OMySQLTable :	public OTableHelper
45 							,public OMySQLTable_PROP
46 		{
47 			sal_Int32 m_nPrivileges; // we have to set our privileges by our own
48 
49 			/** executes the statmenmt.
50 				@param	_rStatement
51 					The statement to execute.
52 				*/
53 			void executeStatement(const ::rtl::OUString& _rStatement );
54 		protected:
55 
56 			/** creates the column collection for the table
57 				@param	_rNames
58 					The column names.
59 			*/
60 			virtual sdbcx::OCollection* createColumns(const TStringVector& _rNames);
61 
62 			/** creates the key collection for the table
63 				@param	_rNames
64 					The key names.
65 			*/
66 			virtual sdbcx::OCollection* createKeys(const TStringVector& _rNames);
67 
68 			/** creates the index collection for the table
69 				@param	_rNames
70 					The index names.
71 			*/
72 			virtual sdbcx::OCollection* createIndexes(const TStringVector& _rNames);
73 
74             /** Returns always "RENAME TABLE " even for views.
75             *
76             * \return The start of the rename statement.
77             * @see http://dev.mysql.com/doc/refman/5.1/de/rename-table.html
78             */
79             virtual ::rtl::OUString getRenameStart() const;
80 
81 			/** used to implement the creation of the array helper which is shared amongst all instances of the class.
82 				This method needs to be implemented in derived classes.
83 				<BR>
84 				The method gets called with s_aMutex acquired.
85 				<BR>
86 				as long as IPropertyArrayHelper has no virtual destructor, the implementation of ~OPropertyArrayUsageHelper
87 				assumes that you created an ::cppu::OPropertyArrayHelper when deleting s_pProps.
88 				@return							an pointer to the newly created array helper. Must not be NULL.
89 			*/
90 			virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const;
91 			virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
92 
93 		public:
94 			OMySQLTable(	sdbcx::OCollection* _pTables,
95 							const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection);
96 			OMySQLTable(	sdbcx::OCollection* _pTables,
97 							const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,
98 							const ::rtl::OUString& _Name,
99 							const ::rtl::OUString& _Type,
100 							const ::rtl::OUString& _Description = ::rtl::OUString(),
101 							const ::rtl::OUString& _SchemaName = ::rtl::OUString(),
102 							const ::rtl::OUString& _CatalogName = ::rtl::OUString(),
103 							sal_Int32 _nPrivileges = 0
104 				);
105 
106 			// ODescriptor
107 			virtual void construct();
108 			// com::sun::star::lang::XUnoTunnel
109             virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException);
110             static ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
111 
112 			// XAlterTable
113             virtual void SAL_CALL alterColumnByName( const ::rtl::OUString& colName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& descriptor ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
114 			/** returns the ALTER TABLE XXX statement
115 			*/
116 			::rtl::OUString getAlterTableColumnPart();
117 
118 			// some methods to alter table structures
119 			void alterColumnType(sal_Int32 nNewType,const ::rtl::OUString& _rColName,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDescriptor);
120 			void alterDefaultValue(const ::rtl::OUString& _sNewDefault,const ::rtl::OUString& _rColName);
121 			void dropDefaultValue(const ::rtl::OUString& _sNewDefault);
122 
123             virtual ::rtl::OUString getTypeCreatePattern() const;
124 		};
125 	}
126 }
127 #endif // CONNECTIVITY_MYSQL_TABLE_HXX
128 
129