Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "ResultSetMetaData.hxx"
21 : #include "Util.hxx"
22 :
23 : #include <com/sun/star/sdbc/ColumnValue.hpp>
24 :
25 : using namespace connectivity::firebird;
26 :
27 : using namespace com::sun::star::lang;
28 : using namespace com::sun::star::sdbc;
29 : using namespace com::sun::star::uno;
30 :
31 8 : OResultSetMetaData::~OResultSetMetaData()
32 : {
33 8 : }
34 :
35 64 : void OResultSetMetaData::verifyValidColumn(sal_Int32 column)
36 : throw(SQLException)
37 : {
38 64 : if (column>getColumnCount() || column < 1)
39 0 : throw SQLException("Invalid column specified", *this, OUString(), 0, Any());
40 64 : }
41 :
42 76 : sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException, std::exception)
43 : {
44 76 : return m_pSqlda->sqld;
45 : }
46 :
47 0 : sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
48 : {
49 0 : verifyValidColumn(column);
50 0 : return 32; // Hard limit for firebird
51 : }
52 :
53 12 : sal_Int32 SAL_CALL OResultSetMetaData::getColumnType(sal_Int32 column)
54 : throw(SQLException, RuntimeException, std::exception)
55 : {
56 12 : verifyValidColumn(column);
57 :
58 12 : short aType = m_pSqlda->sqlvar[column-1].sqltype;
59 :
60 12 : return getColumnTypeFromFBType(aType);
61 : }
62 :
63 0 : sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive(sal_Int32 column)
64 : throw(SQLException, RuntimeException, std::exception)
65 : {
66 : // Firebird is generally case sensitive when using quoted identifiers.
67 : // IF THIS CHANGES make ResultSet::findColumn to be case-insenstive as needed.
68 : // Generally names that are entirely UPPERCASE are case insensitive, however
69 : // there remains some ambiguity if there is another mixed-case-named column
70 : // of the same name. For safety always assume case insensitive.
71 : (void) column;
72 0 : return sal_True;
73 : }
74 :
75 0 : OUString SAL_CALL OResultSetMetaData::getSchemaName(sal_Int32 column)
76 : throw(SQLException, RuntimeException, std::exception)
77 : {
78 : (void) column;
79 0 : return OUString(); // Schemas supported by firebird
80 : }
81 :
82 52 : OUString SAL_CALL OResultSetMetaData::getColumnName(sal_Int32 column)
83 : throw(SQLException, RuntimeException, std::exception)
84 : {
85 52 : verifyValidColumn(column);
86 52 : OUString sRet(m_pSqlda->sqlvar[column-1].sqlname,
87 52 : m_pSqlda->sqlvar[column-1].sqlname_length,
88 156 : RTL_TEXTENCODING_UTF8);
89 52 : sanitizeIdentifier(sRet);
90 52 : return sRet;
91 : }
92 :
93 0 : OUString SAL_CALL OResultSetMetaData::getTableName(sal_Int32 column)
94 : throw(SQLException, RuntimeException, std::exception)
95 : {
96 0 : verifyValidColumn(column);
97 0 : return OUString(m_pSqlda->sqlvar[column-1].relname,
98 0 : m_pSqlda->sqlvar[column-1].relname_length,
99 0 : RTL_TEXTENCODING_UTF8);
100 : }
101 :
102 0 : OUString SAL_CALL OResultSetMetaData::getCatalogName(sal_Int32 column)
103 : throw(SQLException, RuntimeException, std::exception)
104 : {
105 : (void) column;
106 0 : return OUString(); // Catalogs not supported by firebird
107 : }
108 :
109 0 : OUString SAL_CALL OResultSetMetaData::getColumnTypeName(sal_Int32 column)
110 : throw(SQLException, RuntimeException, std::exception)
111 : {
112 0 : verifyValidColumn(column);
113 :
114 0 : short aType = m_pSqlda->sqlvar[column-1].sqltype;
115 :
116 0 : return getColumnTypeNameFromFBType(aType);
117 : }
118 :
119 0 : OUString SAL_CALL OResultSetMetaData::getColumnLabel(sal_Int32 column)
120 : throw(SQLException, RuntimeException, std::exception)
121 : {
122 : // TODO: clarify what this is -- probably not the alias
123 0 : return getColumnName(column);
124 : }
125 :
126 0 : OUString SAL_CALL OResultSetMetaData::getColumnServiceName(sal_Int32 column)
127 : throw(SQLException, RuntimeException, std::exception)
128 : {
129 : // TODO: implement
130 : (void) column;
131 0 : return OUString();
132 : }
133 :
134 12 : sal_Bool SAL_CALL OResultSetMetaData::isCurrency(sal_Int32 column)
135 : throw(SQLException, RuntimeException, std::exception)
136 : {
137 : (void) column;
138 12 : return sal_False;
139 : }
140 :
141 12 : sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement(sal_Int32 column)
142 : throw(SQLException, RuntimeException, std::exception)
143 : {
144 : // Supported internally but no way of determining this here.
145 : (void) column;
146 12 : return sal_False;
147 : }
148 :
149 :
150 0 : sal_Bool SAL_CALL OResultSetMetaData::isSigned(sal_Int32 column)
151 : throw(SQLException, RuntimeException, std::exception)
152 : {
153 : // Unsigned values aren't supported in firebird.
154 : (void) column;
155 0 : return sal_True;
156 : }
157 :
158 0 : sal_Int32 SAL_CALL OResultSetMetaData::getPrecision(sal_Int32 column)
159 : throw(SQLException, RuntimeException, std::exception)
160 : {
161 : // TODO: implement
162 : (void) column;
163 0 : return 0;
164 : }
165 :
166 0 : sal_Int32 SAL_CALL OResultSetMetaData::getScale(sal_Int32 column)
167 : throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
168 : {
169 0 : return m_pSqlda->sqlvar[column-1].sqlscale;
170 : }
171 :
172 0 : sal_Int32 SAL_CALL OResultSetMetaData::isNullable(sal_Int32 column)
173 : throw(SQLException, RuntimeException, std::exception)
174 : {
175 0 : if (m_pSqlda->sqlvar[column-1].sqltype & 1)
176 0 : return ColumnValue::NULLABLE;
177 : else
178 0 : return ColumnValue::NO_NULLS;
179 : }
180 :
181 0 : sal_Bool SAL_CALL OResultSetMetaData::isSearchable(sal_Int32 column)
182 : throw(SQLException, RuntimeException, std::exception)
183 : {
184 : // TODO: Can the column be used as part of a where clause? Assume yes
185 : (void) column;
186 0 : return sal_True;
187 : }
188 :
189 0 : sal_Bool SAL_CALL OResultSetMetaData::isReadOnly(sal_Int32 column)
190 : throw(SQLException, RuntimeException, std::exception)
191 : {
192 : (void) column;
193 0 : return m_pConnection->isReadOnly(); // Readonly only available on db level
194 : }
195 :
196 0 : sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable(sal_Int32 column)
197 : throw(SQLException, RuntimeException, std::exception)
198 : {
199 : (void) column;
200 0 : return !m_pConnection->isReadOnly();
201 : }
202 :
203 0 : sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException, std::exception)
204 : {
205 : (void) column;
206 0 : return !m_pConnection->isReadOnly();
207 : }
208 :
209 :
210 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|