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/.
12 #include <rtl/ustrbuf.hxx>
14 using namespace ::connectivity
;
16 using namespace ::rtl
;
18 using namespace ::com::sun::star
;
19 using namespace ::com::sun::star::sdbc
;
20 using namespace ::com::sun::star::uno
;
22 OUString
firebird::sanitizeIdentifier(const OUString
& rIdentifier
)
24 OUString sRet
= rIdentifier
.trim();
25 assert(sRet
.getLength() <= 31); // Firebird identifiers cannot be longer than this.
30 void firebird::evaluateStatusVector(ISC_STATUS_ARRAY
& aStatusVector
,
31 const OUString
& aCause
,
32 const uno::Reference
< XInterface
>& _rxContext
)
35 if (aStatusVector
[0]==1 && aStatusVector
[1]) // indicates error
38 char msg
[512]; // Size is based on suggestion in docs.
39 const ISC_STATUS
* pStatus
= (const ISC_STATUS
*) &aStatusVector
;
41 buf
.appendAscii("firebird_sdbc error:");
42 while(fb_interpret(msg
, sizeof(msg
), &pStatus
))
44 // TODO: verify encoding
45 buf
.appendAscii("\n*");
46 buf
.append(OUString(msg
, strlen(msg
), RTL_TEXTENCODING_UTF8
));
48 buf
.appendAscii("\ncaused by\n'").append(aCause
).appendAscii("'\n");
50 OUString error
= buf
.makeStringAndClear();
51 SAL_WARN("connectivity.firebird", error
);
53 throw SQLException( error
, _rxContext
, OUString(), 1, Any() );
57 sal_Int32
firebird::getColumnTypeFromFBType(short aType
)
59 aType
&= ~1; // Remove last bit -- it is used to denote whether column
60 // can store Null, not needed for type determination
64 return DataType::CHAR
;
66 return DataType::VARCHAR
;
68 return DataType::SMALLINT
;
70 return DataType::INTEGER
;
72 return DataType::FLOAT
;
74 return DataType::DOUBLE
;
76 return DataType::DOUBLE
;
78 return DataType::TIMESTAMP
;
80 return DataType::BLOB
;
82 return DataType::ARRAY
;
84 return DataType::TIME
;
86 return DataType::DATE
;
88 return DataType::BIGINT
;
90 return DataType::SQLNULL
;
91 case SQL_QUAD
: // Is a "Blob ID" according to the docs
92 return 0; // TODO: verify
94 assert(false); // Should never happen
99 OUString
firebird::getColumnTypeNameFromFBType(short aType
)
101 aType
&= ~1; // Remove last bit -- it is used to denote whether column
102 // can store Null, not needed for type determination
106 return OUString("SQL_TEXT");
108 return OUString("SQL_VARYING");
110 return OUString("SQL_SHORT");
112 return OUString("SQL_LONG");
114 return OUString("SQL_FLOAT");
116 return OUString("SQL_DOUBLE");
118 return OUString("SQL_D_FLOAT");
120 return OUString("SQL_TIMESTAMP");
122 return OUString("SQL_BLOB");
124 return OUString("SQL_ARRAY");
126 return OUString("SQL_TYPE_TIME");
128 return OUString("SQL_TYPE_DATE");
130 return OUString("SQL_INT64");
132 return OUString("SQL_NULL");
134 return OUString("SQL_QUAD");
136 assert(false); // Should never happen
141 short firebird::getFBTypeFromBlrType(short blrType
)
149 return 0; // No idea if this should be supported
154 return 0; // No idea if this should be supported
166 return SQL_TIMESTAMP
;
169 // case blr_SQL_ARRAY:
170 // return OUString("SQL_ARRAY");
172 return SQL_TYPE_TIME
;
174 return SQL_TYPE_DATE
;
178 // return OUString("SQL_NULL");
182 // If this happens we have hit one of the extra types in ibase.h
183 // look up blr_* for a list, e.g. blr_domain_name, blr_not_nullable etc.
189 void firebird::mallocSQLVAR(XSQLDA
* pSqlda
)
191 // TODO: confirm the sizings below.
192 XSQLVAR
* pVar
= pSqlda
->sqlvar
;
193 for (int i
=0; i
< pSqlda
->sqld
; i
++, pVar
++)
195 int dtype
= (pVar
->sqltype
& ~1); /* drop flag bit for now */
198 pVar
->sqldata
= (char *)malloc(sizeof(char)*pVar
->sqllen
);
201 pVar
->sqldata
= (char *)malloc(sizeof(char)*pVar
->sqllen
+ 2);
204 pVar
->sqldata
= (char*) malloc(sizeof(sal_Int16
));
207 pVar
->sqldata
= (char*) malloc(sizeof(sal_Int32
));
210 pVar
->sqldata
= (char *)malloc(sizeof(float));
213 pVar
->sqldata
= (char *)malloc(sizeof(double));
216 pVar
->sqldata
= (char *)malloc(sizeof(double));
219 pVar
->sqldata
= (char*) malloc(sizeof(ISC_TIMESTAMP
));
222 pVar
->sqldata
= (char*) malloc(sizeof(ISC_QUAD
));
225 assert(false); // TODO: implement
228 pVar
->sqldata
= (char*) malloc(sizeof(ISC_TIME
));
231 pVar
->sqldata
= (char*) malloc(sizeof(ISC_DATE
));
234 pVar
->sqldata
= (char *)malloc(sizeof(sal_Int64
));
237 assert(false); // TODO: implement
240 assert(false); // TODO: implement
243 SAL_WARN("connectivity.firebird", "Unknown type: " << dtype
);
247 if (pVar
->sqltype
& 1)
249 /* allocate variable to hold NULL status */
250 pVar
->sqlind
= (short *)malloc(sizeof(short));
255 void firebird::freeSQLVAR(XSQLDA
* pSqlda
)
257 XSQLVAR
* pVar
= pSqlda
->sqlvar
;
258 for (int i
=0; i
< pSqlda
->sqld
; i
++, pVar
++)
260 int dtype
= (pVar
->sqltype
& ~1); /* drop flag bit for now */
277 assert(false); // TODO: implement
280 assert(false); // TODO: implement
283 assert(false); // TODO: implement
286 SAL_WARN("connectivity.firebird", "Unknown type: " << dtype
);
291 if (pVar
->sqltype
& 1)
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */