1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
11 #include <rtl/ustrbuf.hxx>
13 using namespace ::connectivity
;
15 using namespace ::com::sun::star
;
16 using namespace ::com::sun::star::sdbc
;
17 using namespace ::com::sun::star::uno
;
19 OUString
firebird::sanitizeIdentifier(const OUString
& rIdentifier
)
21 OUString sRet
= rIdentifier
.trim();
22 assert(sRet
.getLength() <= 31); // Firebird identifiers cannot be longer than this.
27 OUString
firebird::StatusVectorToString(const ISC_STATUS_ARRAY
& rStatusVector
,
28 const OUString
& rCause
)
31 const ISC_STATUS
* pStatus
= reinterpret_cast<const ISC_STATUS
*>(&rStatusVector
);
33 buf
.appendAscii("firebird_sdbc error:");
36 char msg
[512]; // Size is based on suggestion in docs.
37 while(fb_interpret(msg
, sizeof(msg
), &pStatus
))
39 // TODO: verify encoding
40 buf
.appendAscii("\n*");
41 buf
.append(OUString(msg
, strlen(msg
), RTL_TEXTENCODING_UTF8
));
46 SAL_WARN("connectivity.firebird", "ignore fb_interpret exception");
48 buf
.appendAscii("\ncaused by\n'").append(rCause
).appendAscii("'\n");
50 OUString error
= buf
.makeStringAndClear();
51 SAL_WARN("connectivity.firebird", error
);
55 void firebird::evaluateStatusVector(const ISC_STATUS_ARRAY
& rStatusVector
,
56 const OUString
& rCause
,
57 const uno::Reference
< XInterface
>& _rxContext
)
60 if (IndicatesError(rStatusVector
))
62 OUString error
= StatusVectorToString(rStatusVector
, rCause
);
63 throw SQLException(error
, _rxContext
, OUString(), 1, Any());
67 sal_Int32
firebird::getColumnTypeFromFBType(short aType
)
69 aType
&= ~1; // Remove last bit -- it is used to denote whether column
70 // can store Null, not needed for type determination
74 return DataType::CHAR
;
76 return DataType::VARCHAR
;
78 return DataType::SMALLINT
;
80 return DataType::INTEGER
;
82 return DataType::FLOAT
;
84 return DataType::DOUBLE
;
86 return DataType::DOUBLE
;
88 return DataType::TIMESTAMP
;
90 return DataType::BLOB
;
92 return DataType::ARRAY
;
94 return DataType::TIME
;
96 return DataType::DATE
;
98 return DataType::BIGINT
;
100 return DataType::SQLNULL
;
101 case SQL_QUAD
: // Is a "Blob ID" according to the docs
102 return 0; // TODO: verify
104 assert(false); // Should never happen
109 OUString
firebird::getColumnTypeNameFromFBType(short aType
)
111 aType
&= ~1; // Remove last bit -- it is used to denote whether column
112 // can store Null, not needed for type determination
116 return OUString("SQL_TEXT");
118 return OUString("SQL_VARYING");
120 return OUString("SQL_SHORT");
122 return OUString("SQL_LONG");
124 return OUString("SQL_FLOAT");
126 return OUString("SQL_DOUBLE");
128 return OUString("SQL_D_FLOAT");
130 return OUString("SQL_TIMESTAMP");
132 return OUString("SQL_BLOB");
134 return OUString("SQL_ARRAY");
136 return OUString("SQL_TYPE_TIME");
138 return OUString("SQL_TYPE_DATE");
140 return OUString("SQL_INT64");
142 return OUString("SQL_NULL");
144 return OUString("SQL_QUAD");
146 assert(false); // Should never happen
151 short firebird::getFBTypeFromBlrType(short blrType
)
159 return 0; // No idea if this should be supported
164 return 0; // No idea if this should be supported
176 return SQL_TIMESTAMP
;
179 // case blr_SQL_ARRAY:
180 // return OUString("SQL_ARRAY");
182 return SQL_TYPE_TIME
;
184 return SQL_TYPE_DATE
;
188 // return OUString("SQL_NULL");
192 // If this happens we have hit one of the extra types in ibase.h
193 // look up blr_* for a list, e.g. blr_domain_name, blr_not_nullable etc.
199 void firebird::mallocSQLVAR(XSQLDA
* pSqlda
)
201 // TODO: confirm the sizings below.
202 XSQLVAR
* pVar
= pSqlda
->sqlvar
;
203 for (int i
=0; i
< pSqlda
->sqld
; i
++, pVar
++)
205 int dtype
= (pVar
->sqltype
& ~1); /* drop flag bit for now */
208 pVar
->sqldata
= static_cast<char *>(malloc(sizeof(char)*pVar
->sqllen
));
211 pVar
->sqldata
= static_cast<char *>(malloc(sizeof(char)*pVar
->sqllen
+ 2));
214 pVar
->sqldata
= static_cast<char*>(malloc(sizeof(sal_Int16
)));
217 pVar
->sqldata
= static_cast<char*>(malloc(sizeof(sal_Int32
)));
220 pVar
->sqldata
= static_cast<char *>(malloc(sizeof(float)));
223 pVar
->sqldata
= static_cast<char *>(malloc(sizeof(double)));
226 pVar
->sqldata
= static_cast<char *>(malloc(sizeof(double)));
229 pVar
->sqldata
= static_cast<char*>(malloc(sizeof(ISC_TIMESTAMP
)));
232 pVar
->sqldata
= static_cast<char*>(malloc(sizeof(ISC_QUAD
)));
235 assert(false); // TODO: implement
238 pVar
->sqldata
= static_cast<char*>(malloc(sizeof(ISC_TIME
)));
241 pVar
->sqldata
= static_cast<char*>(malloc(sizeof(ISC_DATE
)));
244 pVar
->sqldata
= static_cast<char *>(malloc(sizeof(sal_Int64
)));
247 assert(false); // TODO: implement
250 assert(false); // TODO: implement
253 SAL_WARN("connectivity.firebird", "Unknown type: " << dtype
);
257 if (pVar
->sqltype
& 1)
259 /* allocate variable to hold NULL status */
260 pVar
->sqlind
= static_cast<short *>(malloc(sizeof(short)));
265 void firebird::freeSQLVAR(XSQLDA
* pSqlda
)
267 XSQLVAR
* pVar
= pSqlda
->sqlvar
;
268 for (int i
=0; i
< pSqlda
->sqld
; i
++, pVar
++)
270 int dtype
= (pVar
->sqltype
& ~1); /* drop flag bit for now */
287 pVar
->sqldata
= NULL
;
291 assert(false); // TODO: implement
294 assert(false); // TODO: implement
297 assert(false); // TODO: implement
300 SAL_WARN("connectivity.firebird", "Unknown type: " << dtype
);
305 if (pVar
->sqltype
& 1)
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */