11#include <rtl/ustrbuf.hxx>
14#include <com/sun/star/sdbc/DataType.hpp>
15#include <com/sun/star/sdbc/SQLException.hpp>
24using namespace firebird;
28 std::u16string_view sRet =
o3tl::trim(rIdentifier);
29 assert(sRet.size() <= 31);
31 return OUString(sRet);
35 std::u16string_view rCause)
38 const ISC_STATUS* pStatus =
reinterpret_cast<const ISC_STATUS*
>(&rStatusVector);
40 buf.append(
"firebird_sdbc error:");
44 while(fb_interpret(msg,
sizeof(msg), &pStatus))
48 + OUString(msg, strlen(msg), RTL_TEXTENCODING_UTF8));
53 SAL_WARN(
"connectivity.firebird",
"ignore fb_interpret exception");
55 buf.append(OUString::Concat(
"\ncaused by\n'") + rCause +
"'\n");
57 OUString error = buf.makeStringAndClear();
58 SAL_WARN(
"connectivity.firebird", error);
63 std::u16string_view rCause,
64 const uno::Reference< XInterface >& _rxContext)
69 throw SQLException(error, _rxContext, OUString(), 1,
Any());
77 case NumberSubType::Numeric:
78 return DataType::NUMERIC;
79 case NumberSubType::Decimal:
80 return DataType::DECIMAL;
85 return DataType::SMALLINT;
87 return DataType::INTEGER;
89 return DataType::DOUBLE;
91 return DataType::BIGINT;
103 if( sCharset ==
u"OCTETS")
104 return DataType::BINARY;
106 return DataType::CHAR;
108 if( sCharset ==
u"OCTETS")
109 return DataType::VARBINARY;
111 return DataType::VARCHAR;
118sal_Int32 firebird::ColumnTypeInfo::getSdbcType()
const
122 short aSubType = m_aSubType;
126 if(aType == SQL_SHORT || aType == SQL_LONG || aType == SQL_DOUBLE
127 || aType == SQL_INT64)
130 if(
static_cast<NumberSubType>(aSubType) == NumberSubType::Other )
131 aSubType =
static_cast<short>(NumberSubType::Numeric);
146 return DataType::FLOAT;
148 return DataType::DOUBLE;
150 return DataType::TIMESTAMP;
154 case BlobSubtype::Blob:
155 return DataType::BLOB;
156 case BlobSubtype::Clob:
157 return DataType::CLOB;
158 case BlobSubtype::Image:
159 return DataType::LONGVARBINARY;
161 SAL_WARN(
"connectivity.firebird",
"Unknown subtype for Blob type: " << aSubType);
162 assert(!
"Unknown subtype for Blob type");
166 return DataType::ARRAY;
168 return DataType::TIME;
170 return DataType::DATE;
172 return DataType::SQLNULL;
176 return DataType::BOOLEAN;
183OUString firebird::ColumnTypeInfo::getColumnTypeName()
const
185 sal_Int32
nDataType = this->getSdbcType();
190 case DataType::TINYINT:
192 case DataType::SMALLINT:
194 case DataType::INTEGER:
196 case DataType::BIGINT:
198 case DataType::FLOAT:
202 case DataType::DOUBLE:
204 case DataType::NUMERIC:
206 case DataType::DECIMAL:
210 case DataType::VARCHAR:
212 case DataType::LONGVARCHAR:
213 return "LONGVARCHAR";
218 case DataType::TIMESTAMP:
220 case DataType::BINARY:
225 case DataType::VARBINARY:
227 return "CHARACTER VARYING";
228 case DataType::LONGVARBINARY:
229 return "BLOB SUB_TYPE " + OUString::number(
static_cast<short>(BlobSubtype::Image));
230 case DataType::ARRAY:
233 return "BLOB SUB_TYPE BINARY";
235 return "BLOB SUB_TYPE TEXT";
236 case DataType::BOOLEAN:
238 case DataType::SQLNULL:
271 return SQL_TIMESTAMP;
277 return SQL_TYPE_TIME;
279 return SQL_TYPE_DATE;
299 XSQLVAR* pVar = pSqlda->sqlvar;
300 for (
int i=0;
i < pSqlda->sqld;
i++, pVar++)
302 int dtype = (pVar->sqltype & ~1);
305 pVar->sqldata =
static_cast<char *
>(malloc(
sizeof(
char)*pVar->sqllen));
308 pVar->sqldata =
static_cast<char *
>(malloc(
sizeof(
char)*pVar->sqllen + 2));
311 pVar->sqldata =
static_cast<char*
>(malloc(
sizeof(sal_Int16)));
314 pVar->sqldata =
static_cast<char*
>(malloc(
sizeof(sal_Int32)));
317 pVar->sqldata =
static_cast<char *
>(malloc(
sizeof(
float)));
320 pVar->sqldata =
static_cast<char *
>(malloc(
sizeof(
double)));
323 pVar->sqldata =
static_cast<char *
>(malloc(
sizeof(
double)));
326 pVar->sqldata =
static_cast<char*
>(malloc(
sizeof(ISC_TIMESTAMP)));
332 pVar->sqldata =
static_cast<char*
>(malloc(
sizeof(ISC_QUAD)));
335 pVar->sqldata =
static_cast<char*
>(malloc(
sizeof(ISC_TIME)));
338 pVar->sqldata =
static_cast<char*
>(malloc(
sizeof(ISC_DATE)));
341 pVar->sqldata =
static_cast<char *
>(malloc(
sizeof(sal_Int64)));
344 pVar->sqldata =
static_cast<char *
>(malloc(
sizeof(
sal_Bool)));
348 pVar->sqldata =
nullptr;
354 SAL_WARN(
"connectivity.firebird",
"Unknown type: " << dtype);
359 pVar->sqlind =
static_cast<short *
>(malloc(
sizeof(
short)));
365 XSQLVAR* pVar = pSqlda->sqlvar;
366 for (
int i=0;
i < pSqlda->sqld;
i++, pVar++)
368 int dtype = (pVar->sqltype & ~1);
389 pVar->sqldata =
nullptr;
394 assert(pVar->sqldata ==
nullptr);
400 SAL_WARN(
"connectivity.firebird",
"Unknown type: " << dtype);
408 pVar->sqlind =
nullptr;
417 for(
int i=0;
i< nDecimalCount;
i++)
static sal_Int32 lcl_getNumberType(short aType, NumberSubType aSubType)
static sal_Int32 lcl_getCharColumnType(short aType, std::u16string_view sCharset)
#define SAL_WARN(area, stream)
NumberSubType
Numeric and decimal types can be identified by their subtype in Firebird API.
void freeSQLVAR(XSQLDA *pSqlda)
bool IndicatesError(const ISC_STATUS_ARRAY &rStatusVector)
short getFBTypeFromBlrType(short blrType)
Internally (i.e.
OUString sanitizeIdentifier(std::u16string_view rIdentifier)
Make sure an identifier is safe to use within the database.
OUString StatusVectorToString(const ISC_STATUS_ARRAY &rStatusVector, std::u16string_view rCause)
sal_Int64 pow10Integer(int nDecimalCount)
void evaluateStatusVector(const ISC_STATUS_ARRAY &rStatusVector, std::u16string_view aCause, const css::uno::Reference< css::uno::XInterface > &_rxContext)
Evaluate a firebird status vector and throw exceptions as necessary.
void mallocSQLVAR(XSQLDA *pSqlda)
std::basic_string_view< charT, traits > trim(std::basic_string_view< charT, traits > str)